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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing Values in Arrays

Status
Not open for further replies.

Berns

IS-IT--Management
Apr 25, 2002
41
US
Hi-
Someone was helping mewith this last night, and I thought that I had it all figured out until I realized that I don't have the an area to identify the value for each answer.

This is the problem, I need to develop a script that will rotate the order of the selections on a form. For example, if the question is How old are you and the selections (radio buttons) are 12, 13, and 14. This part Kev helped me out with. Now I have to be able to pass the value of each selection, right now I'm just getting "on", but I need an actual value, here is the current code:

<html>
<head>
<script>

var arrayOfData1 = [&quot;Buying&quot;,&quot;Refinancing&quot;,&quot;Other&quot;];

var arrayOfData2 = [&quot;Rates are too high&quot;,
&quot;I don't trust that my personal online&quot;,
&quot;I didn't want to be charged an application fee &quot;,
&quot;I never enter my credit card information online&quot;,
&quot;I had too many questions about the application process &quot;];

var arrayOfData3 = [&quot;Accessed the Glossary sectionof the web site&quot;,
&quot;Called the 800# &quot;,
&quot;Left the web site &quot;];

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
rnd.seed = (rnd.seed*9301+49297) % 233280;
return rnd.seed/(233280.0);
};

function rand(number) {
return Math.floor(rnd()*number);
};

function writeRadioButton(name, array) {
while (array.length > 0) {
var randOption = rand(array.length);
document.write('<INPUT TYPE=&quot;RADIO&quot; NAME=&quot;' + name + '&quot; > ' +
array[randOption] + '<BR>');
array[randOption] = array[array.length - 1]
--array.length;
}
}

</script>
</head>

<body>
<form method=&quot;post&quot; action=&quot;onsubmit=&quot;return checkRequired(this)&quot;>
<INPUT type=&quot;hidden&quot; NAME=&quot;form_version&quot; VALUE=&quot;1&quot;/>
<INPUT type=&quot;hidden&quot; NAME=&quot;source_site&quot; VALUE=&quot;VAL1&quot;/>
<INPUT type=&quot;hidden&quot; NAME=&quot;thankyou&quot;
VALUE=&quot;<INPUT type=&quot;hidden&quot; NAME=&quot;thankyou_page&quot; VALUE=&quot;&quot;/>
<INPUT type=&quot;hidden&quot; NAME=&quot;fieldorder&quot;
VALUE=&quot;Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13,Q14,Q15,Q16,Q17,Q18&quot;/
>

<p><b>Please tell us your interest in visiting our website:</b><br>
<script>
writeRadioButton(&quot;Q01&quot;, arrayOfData1)
</script>

<p><b>If you did not complete & submit our online application, what was the top
reason that prevented you from doing so?</b><br>
<script>
writeRadioButton(&quot;Q02&quot;, arrayOfData2)
</script>

<p><b>If you had a question while on our web site, what action did you take to
help get an answer to your question?</b><br>
<script>
writeRadioButton(&quot;Q03&quot;, arrayOfData3)
</script>
</form>
</body>
</html>
 
currently you're not giving the radio buttons a value. you could modify writeRadioButton() to add the value=&quot;&quot;:

function writeRadioButton(name, array) {
while (array.length > 0) {
var randOption = rand(array.length);
document.write('<INPUT TYPE=&quot;RADIO&quot; NAME=&quot;' + name +
'&quot; value=&quot;' + array[randOption] + '&quot; > ' +
array[randOption] + '<BR>');
array[randOption] = array[array.length - 1];
--array.length;
}
}


=========================================================
if (!succeed) try();
-jeff
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top