View the Most Wanted LQ Wiki articles.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 01-05-2005, 04:23 AM   #1
Registered: Jan 2004
Distribution: OS X 10.4
Posts: 172
Blog Entries: 1

Rep: Reputation: 30
javascript variable in a form


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:
<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:
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
<span id="hiddenbit"></span>
inside the form.

Old 01-05-2005, 05:07 AM   #2
Senior Member
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
document.test_score.value = score1;
If the <input> is in a form, then it needs to be in this fashion
document.FORM_NAME.test_score.value = score1;
Where form_name needs replaced with the actual name of the form.

Last edited by scuzzman; 01-05-2005 at 05:11 AM.
Old 01-05-2005, 05:09 AM   #3
Registered: Sep 2004
Location: Canberra, Australia
Distribution: Fedora Core 3, Ubuntu Hoary, Slack 10.1
Posts: 120

Rep: Reputation: 15
[EDIT: scuzzman beat me to the punch]

I'm no javascript expert, but:

document.test.test_score.value = score1
should do it, assuming the form name is test.
Old 01-05-2005, 05:34 AM   #4
Registered: Jan 2004
Distribution: OS X 10.4
Posts: 172
Blog Entries: 1

Original Poster
Rep: Reputation: 30

awesome thanks guys!!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
strange value of variable after a php form jeanpba Linux - Software 0 11-15-2005 03:38 AM
csh: variable input of the form x.y.z not accepted kpachopoulos Programming 1 07-24-2005 05:39 PM
Can I "submit" an HTML <Form> with Javascript? nickiv Programming 3 06-13-2005 07:41 AM
submit a form with javascript djgerbavore Programming 6 06-01-2005 03:46 PM
willing to pay $$$ PHP / Javascript multiple paged form; carrying over variables micro_sucks General 1 12-26-2003 10:37 AM

All times are GMT -5. The time now is 01:45 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration