Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Value of varibable into a hidden field

Status
Not open for further replies.

jewel464g

Technical User
Jul 18, 2001
198
US
var count = 0

if (document.frmTest.q1.value == "T") {
count++;
}

if (document.frmTest.q2.value == "T") {
count++;
}

if (document.frmTest.q3.value == "T") {
count++;
}

if (document.frmTest.q4.value == "T") {
count++;
}

if (document.frmTest.q5.value == "T") {
count++;
}

if (document.frmTest.q6.value == "T") {
count++;
}

if (document.frmTest.q7.value == "T") {
count++;
}

if (document.frmTest.q8.value == "T") {
count++;
}

if (document.frmTest.q9.value == "T") {
count++;
}

if (document.frmTest.q10.value == "T") {
count++;
}

count = count * 10;


How do I get the value of count into a hidden field within my form.

When faced with a decision, always ask, 'Which would be the most fun?'
 
Assume that the name of your hidden field is named hiddenField. If that's the case, then the last line of the function would be:
Code:
document.frmTest.hiddenField.value = count;

-kaht

banghead.gif
 

Why not replace all those ugly if statements with one if statement within a loop? It also means that if you add or remove fields, it becomes easy to change the code to suit:

Code:
for (var loop=1; loop<11; loop++) {
   if (document.forms['frmTest'].elements['q' + loop].value == "T") count++;
}

Hope this helps,
Dan
 
Shoot, while you're at it, as long as you're going to multiply by 10 at the end, intead of count++, just make each one: count += 10;

--Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top