LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   javascript variable in a form (https://www.linuxquestions.org/questions/programming-9/javascript-variable-in-a-form-274042/)

rksprst 01-05-2005 03:23 AM

javascript variable in a form
 
Hi,

I have <input name="test_score" value="" type="hidden">
in my form

I have a javascript global variable called score1.
the variable is an int but i converted to string by doing: score1 = score + "";
i think javascript does it automatically but i still did it

so i would like to set the value of the hidden form "test_score" as the javascript variable score1

is this possible? and how do i do it?

i tried the following:
Code:

<input name="test_score" value="score1" type="hidden">
<input name="test_score" value=score1 type="hidden">
<input name="test_score" value=javascript:score1 type="hidden">
and after finding something on google i did
<input name="test_score" value="+score1+" type="hidden">

i even tried:
Code:

score1 = score + " is your test score";

var sstr = "<input type='hidden' name='" + score1 + "' value='" + dowhat + "' name='test_scores'>";
document.getElementById("hiddenbit").innerHTML = sstr;

while i had
Code:

<span id="hiddenbit"></span>
inside the form.

thanks

scuzzman 01-05-2005 04:07 AM

Code:

document.test_score.value = score1;
If the <input> is in a form, then it needs to be in this fashion
Code:

document.FORM_NAME.test_score.value = score1;
Where form_name needs replaced with the actual name of the form.

bornhj 01-05-2005 04:09 AM

[EDIT: scuzzman beat me to the punch]

I'm no javascript expert, but:

Code:

document.test.test_score.value = score1
should do it, assuming the form name is test.

rksprst 01-05-2005 04:34 AM

works

awesome thanks guys!!


All times are GMT -5. The time now is 10:40 PM.