0

I have searched Google for the past hour and can't find the answer to this. I have a variable and I need to send it to a text box to be the default value:

if (totalcustomamount < 105)  {
          totalcustomamount = 105;
}

is my code and it works, but I don't know how to set the variable there to that value in the textbox below:

<input name="name_of_box" type="text" id="name_of_box" size="4" class="name_of_class">

I normally would just put value="something", but I need to use the variable that is in the JavaScript. Is this possible?

3 Answers 3

2
// id="name_of_box"
document.getElementById('name_of_box').value = totalcustomamount;
Sign up to request clarification or add additional context in comments.

Comments

1

jQuery way :

$(function() {
    if (totalcustomamount < 105)  {
        $("#name_of_box").val(105);
    }
}

Comments

0
if (totalcustomamount < 105)  {
          totalcustomamount = 105;
        document.getElementById('name_of_box').value = totalcustomamount;

}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.