LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


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

Rep: Reputation: 30
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
 
Old 01-05-2005, 04:07 AM   #2
scuzzman
Senior Member
 
Registered: May 2004
Location: Hilliard, Ohio, USA
Distribution: Slackware, Kubuntu
Posts: 1,851

Rep: Reputation: 47
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.

Last edited by scuzzman; 01-05-2005 at 04:11 AM.
 
Old 01-05-2005, 04:09 AM   #3
bornhj
Member
 
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:

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

Original Poster
Blog Entries: 1

Rep: Reputation: 30
works

awesome thanks guys!!
 
  


Reply



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 02:38 AM
csh: variable input of the form x.y.z not accepted kpachopoulos Programming 1 07-24-2005 04:39 PM
Can I "submit" an HTML <Form> with Javascript? nickiv Programming 3 06-13-2005 06:41 AM
submit a form with javascript djgerbavore Programming 6 06-01-2005 02:46 PM
willing to pay $$$ PHP / Javascript multiple paged form; carrying over variables micro_sucks General 1 12-26-2003 09:37 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:42 PM.

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