/    Sign up×
Community /Pin to ProfileBookmark

Populate Hidden field with the value

I’ve got a javascript that allows me to toggle between what cgi file I want to write data to with the selection of a radio button. The problem is that there is only one field name for the five choices that I have for the radio button, the field name is “operation”. In the form I need to be able to write the actual name of what they are choosing along with 1 through 5 to my database. Is it possible to have the radio button also populate a hidden field with the value of the name that is selected which would be for example General, Position Inquiry… My javascript code is below.

<html>
<head>
<title></title>

<SCRIPT language=”JavaScript”>
function OnSubmitForm()
{
if(document.myform.operation[0].checked == true)
{
document.myform.action =”write1.pl”;
}
else
if(document.myform.operation[1].checked == true)
{
document.myform.action =”write2.pl”;
}

else
if(document.myform.operation[2].checked == true)
{
document.myform.action =”write3.pl”;
}

else
if(document.myform.operation[3].checked == true)
{
document.myform.action =”write4.pl”;
}

else
if(document.myform.operation[4].checked == true)
{
document.myform.action =”write5.pl”;
}
return true;

}
</SCRIPT>

</head>
<body>

<FORM name=”myform” onSubmit=”return OnSubmitForm();” method=post>
Name: <INPUT TYPE=”TEXT” Name=”name”><br>
Email: <INPUT TYPE=”TEXT” Name=”email”><br>
<input type=”radio” name=”operation” value=”1″ checked>General
<input type=”radio” name=”operation” value=”2″>Position Inquiry
<input type=”radio” name=”operation” value=”3″>Acquisition Inquiry
<input type=”radio” name=”operation” value=”4″>Consulting Inquiry
<input type=”radio” name=”operation” value=”5″>Partnership Inquiry
<br><br>
<INPUT TYPE=”SUBMIT” name=”Submit” VALUE=” Submit “>
</FORM>

</body>
</html>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@ScreameRJan 30.2006 — Try this:

<html>

<head>

<title></title>

<SCRIPT language="JavaScript">

function OnSubmitForm()

{

if(document.myform.operation[0].checked == true)

{

document.myform.action ="write1.pl";

}

else

if(document.myform.operation[1].checked == true)

{

document.myform.action ="write2.pl";

}

else

if(document.myform.operation[2].checked == true)

{

document.myform.action ="write3.pl";

}

else

if(document.myform.operation[3].checked == true)

{

document.myform.action ="write4.pl";

}

else

if(document.myform.operation[4].checked == true)

{

document.myform.action ="write5.pl";

}

return true;

}

function populateValue(opt){

if(opt.checked) document.forms["myform"].elements["optValue"].value = opt.nextSibling.data;

return true;

}

</SCRIPT>

</head>

<body>

<FORM name="myform" onSubmit="return OnSubmitForm();" method=post>

Name: <INPUT TYPE="TEXT" Name="name"><br>

Email: <INPUT TYPE="TEXT" Name="email"><br>

<input type="radio" name="operation" value="1" onclick="populateValue(this)" checked>General

<input type="radio" name="operation" value="2" onclick="populateValue(this)">Position Inquiry

<input type="radio" name="operation" value="3" onclick="populateValue(this)">Acquisition Inquiry

<input type="radio" name="operation" value="4" onclick="populateValue(this)">Consulting Inquiry

<input type="radio" name="operation" value="5" onclick="populateValue(this)">Partnership Inquiry

<br><br>

<input type=hidden name="optValue" />

<INPUT TYPE="SUBMIT" name="Submit" VALUE=" Submit ">

</FORM>

</body>

</html>[/QUOTE]
Copy linkTweet thisAlerts:
@HDCauthorJan 30.2006 — haha, yes thats exactly it! Even on the first try. Thanks for helping me out!

HDC
Copy linkTweet thisAlerts:
@HDCauthorFeb 04.2006 — Is this possible... Instead of radio buttons that populate the hidden field just switch them over to a drop down box that populates the hidden field: Tried this but didn't work:


<select name="operation">

<option value="1" onclick="populateValue(this)">General</option>

<option value="2" onclick="populateValue(this)">Position Inquiry</option>

<option value="3" onclick="populateValue(this)">Acquisition Inquiry</option>

<option value="4" onclick="populateValue(this)">Consulting Inquiry</option>

<option value="5" onclick="populateValue(this)">Partnership Inquiry</option>

</select>
Copy linkTweet thisAlerts:
@HDCauthorFeb 05.2006 — anybody got any ideas on this?
Copy linkTweet thisAlerts:
@HDCauthorMar 08.2006 — Is it possible instead of radio buttons that populate the hidden field just switch them over to a drop down box that populates the hidden field: Tried this but didn't work:


<select name="operation">

<option value="1" onclick="populateValue(this)">General</option>

<option value="2" onclick="populateValue(this)">Position Inquiry</option>

<option value="3" onclick="populateValue(this)">Acquisition Inquiry</option>

<option value="4" onclick="populateValue(this)">Consulting Inquiry</option>

<option value="5" onclick="populateValue(this)">Partnership Inquiry</option>

</select>
×

Success!

Help @HDC spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...