Question

I am pretty new to jQuery and I am having issue with setting an input text box to a default value. I have tried using the val method and also the .attr method. Neither seem to work. I will post my input html and both jQuery that I have tried below. I am going to guess I have a syntax issue. I did try a couple of the answers posted on other questions and I couldn't seem to get it to work. Thanks for any help.

<input id="DiscountCode" class="discountcodeInput" type="text" name="DiscountCode"
value="" onchange="ApplyDiscountCode(this.value,3460847,209327);return false;"></input>
<input class="update" type="button" value="Update" onclick="return false;"></input>

jQuery:

Current:

$(document).load(function(){
    $('input#DiscountCode.discountcodeInput').val('SANFORDSUITES');
});

Have tried this also:

$(document).load(function(){
    $('input#DiscountCode.discountcodeInput').attr('value', 'SANFORDSUITES');
});
Was it helpful?

Solution

I believe you want $(document).ready(function(){... }), rather than .load().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top