0

I currently calculate a random value with jQuery and save it to a variable.

I want this variable to be the value of:

<input type="text" class="mastery_num" name="mastery_num" id="mastery_num" value="VALUE_FROM_JQUERY"></input>

How can I do this?

2 Answers 2

3

You're looking for val:

var your_variable = doMyCalculation();
$("#mastery_num").val(your_variable);
Sign up to request clarification or add additional context in comments.

Comments

1
$("#mastery_num").val(your_saved_variable);

.val() is jQuery's equivalent of the plain JavaScript .value property. .val() either returns or sets the value depending on whether you supply a value to it.

Plain JavaScript version, for future viewers:

document.getElementById("mastery_num").value = your_saved_variable;

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.