/    Sign up×
Community /Pin to ProfileBookmark

Passing Values via Arrays

Hello-
I have to develop a script that will randomly rotate selections on a form (radio buttons), I have been able to accomplish this but I have just realized that I am not passing the value for each selection. I have pasted the script below, any help greatly appreciated:

<html>
<head>
<script>

var arrayOfData1 = [“Buying”,”Refinancing”,”Other”];

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

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

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=”RADIO” NAME=”‘ + name + ‘” > ‘ +
array[randOption] + ‘<BR>’);
array[randOption] = array[array.length – 1]
–array.length;
}
}

</script>
</head>

<body>
<form method=”post” action=”http://XXX
onsubmit=”return checkRequired(this)”>
<INPUT type=”hidden” NAME=”form_version” VALUE=”1″/>
<INPUT type=”hidden” NAME=”source_site” VALUE=”AD Feedback Response”/>
<INPUT type=”hidden” NAME=”thankyou”
VALUE=”http://www.thankyou“/>
<INPUT type=”hidden” NAME=”thankyou_page” VALUE=””/>
<INPUT type=”hidden” NAME=”fieldorder”
VALUE=”Q01,Q02,Q03,Q04,Q05,Q06,Q07,Q08,Q09,Q10,Q11,Q12,Q13,Q14,Q15,Q16,Q17,Q18″/

>

<p><b>Please tell us your interest in visiting our website:</b><br>
<script>
writeRadioButton(“Q01”, 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(“Q02”, 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(“Q03”, arrayOfData3)
</script>
</form>
</body>
</html>

to post a comment
JavaScript

8 Comments(s)

Copy linkTweet thisAlerts:
@SotiauthorNov 22.2002 — anyone??
Copy linkTweet thisAlerts:
@SotiauthorNov 22.2002 — I apologize, didn't mean to "bump" my post - I have been going nuts trying to figure this out for two days now. I'm pretty new to JavaScript so I'm not sure where a person needs to look, that's pretty much what I'm trying to figure out - Where/how can I pass the values if the selection is listed on top?

Any help appreciated.
Copy linkTweet thisAlerts:
@SotiauthorNov 22.2002 — Since I want the selections to randomly appear each time that the page is loaded or refreshed, the selections are arrays:

var arrayOfData1 = ["Buying","Refinancing","Other"];

var arrayOfData2 = ["Rates are too high",

"I don't trust that my personal online",

"I didn't want to be charged an application fee ",

"I never enter my credit card information online",

"I had too many questions about the application process "];

called this way:

<p><b>Please tell us your interest in visiting our website:</b><br>

<script>

writeRadioButton("Q01", arrayOfData1)

</script>


How can I pass and define the value of each selection so that when the user submits I know what they selected, generally it is done this was in html:

<input type="radio" name="Q01" value="buying">

but I can't do this with this script. Does anyone know how I can do this whiles randomly presenting the selections?
Copy linkTweet thisAlerts:
@SotiauthorNov 22.2002 — They already are radio buttons, I've done that part:

function writeRadioButton(name, array) {

while (array.length > 0) {

var randOption = rand(array.length);

document.write('<INPUT TYPE="RADIO" NAME="' + name + '" > ' +

array[randOption] + '<BR>');

array[randOption] = array[array.length - 1]

--array.length;

then:

<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("Q02", arrayOfData2)

</script>

But they are not passing a value, just on or off, I need to know how I can pass the value.
Copy linkTweet thisAlerts:
@SotiauthorNov 23.2002 — Thanks for the tip, I'm still not sure where I will place the value. I understand that I can call it from there, but where do I define it?

I'm using this code:

rnd.today=new Date();

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

function rnd() {

rnd.seed = (rnd.seed*9301+49297) % 233280;

return rnd.seed/(233280.0);

};

Instead of the Math.random() method, no particular reason. Do you recommend this method instead?
Copy linkTweet thisAlerts:
@SotiauthorNov 23.2002 — Adding this code:

<INPUT TYPE="RADIO" NAME="' + name + '" value="' +

array[randOption] + '"> ' + array[randOption] + '<BR>');

Didn't work, actually it crashed my browser and I got a pretty bizarre error message.

I see where you are calling the value:

" value="' +

But I don't understand where you are defining it. For example, if Question 1 has three choices and the values are house1, house2, and house3, where am I to define these? They are not anywhere else in the script.
Copy linkTweet thisAlerts:
@SotiauthorNov 23.2002 — The value for each selection was *supposed* to be slightly different then the selection, especially because some are very long. Perhaps that is not possible, but that was my initial question. No, you are not teaching me how someone elses script works, I actually spent quite a bit of time on this one ?

Looks like it's working, I can't seem to access my DB now, though so I can't be sure.

Thanks for you help, I really appreciate your time!
Copy linkTweet thisAlerts:
@SotiauthorNov 23.2002 — Aha!! There it is! Perfect! That is exactly what I was looking for, I started to think that it wasn't possible.

You've made my day?

THANKS!
×

Success!

Help @Soti 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.3,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...