/    Sign up×
Community /Pin to ProfileBookmark

JavaScript variables not getting sent to PHP file?

Hi, I’m new here, but not new to web development. I’m glad to have found this forum, because I have a strange problem. Maybe I’m just overlooking a really simple error, but I’ve gone over my files so many times I’m going crazy because I can’t figure it out.

I made this survey form in HTML:

[code=html]<form action=”http://shoesurfing.com/Library/scripts/feedback.php” method=”post” enctype=”application/x-www-form-urlencoded” name=”feedback_form” id=”feedback_form”>

<ol>

<!–Question #1–>
<li><p class=”qtxt”><span class=”red”>*</span> <b>Overall, how would you rate the ease of navigation of our website?</b></p>

<label for=”q1_opt1″><input type=”radio” value=”Very Good” name=”question1″ id=”q1_opt1″ />Very Good</label><br>
<label for=”q1_opt2″><input type=”radio” value=”Good” name=”question1″ id=”q1_opt2″ />Good</label><br>
<label for=”q1_opt3″><input type=”radio” value=”Average” name=”question1″ id=”q1_opt3″ />Average</label><br>
<label for=”q1_opt4″><input type=”radio” value=”Poor” name=”question1″ id=”q1_opt4″ />Poor</label><br>
<label for=”q1_opt5″><input type=”radio” value=”Very Poor” name=”question1″ id=”q1_opt5″ />Very Poor</label>

<input type=”hidden” name=”q1hid” id=”q1hid” value=”javascript:q1Var.toString()” />
</li><br><!–[if IE]> <br> <![endif]–>

…snip…

<!–Question #7–>
<li><p class=”qtxt”><span class=”red”>*</span> <b>In your opinion, how do our prices compare with other online retailers you have visited?</b></p>
<label for=”q7_less”><input type=”radio” value=”Less Expensive” name=”question7″ id=”q7_less” />Less Expensive</label><br>
<label for=”q7_same”><input type=”radio” value=”Similar” name=”question7″ id=”q7_same” />Similar</label><br>
<label for=”q7_more”><input type=”radio” value=”More Expensive” name=”question7″ id=”q7_more” />More Expensive</label>

<input type=”hidden” name=”q7hid” id=”q7hid” value=”javascript:q7Var.toString()” />
</li><br><!–[if IE]> <br> <![endif]–>

<!–Question #8–>
<li><p class=”qtxt”><span class=”red”>*</span> <b>Have you ordered from us before?</b></p>
<label for=”q8_yes”><input type=”radio” value=”Yes” name=”question8″ id=”q8_yes” onClick=”showDiv8(‘div910’);”/>Yes</label><br>
<label for=”q8_no”><input type=”radio” value=”No” name=”question8″ id=”q8_no” onClick=”hideDiv8(‘div910’);”/>No</label>

<input type=”hidden” name=”q8hid” id=”q8hid” value=”javascript:q8Var.toString()” />
</li>

<div id=”div910″>

<blockquote>
<!–Question #8 A–>
<p class=”qtxt”>a. <b>When you have ordered from us, did you receive the status update and confirmation emails?</b></p>
<label for=”q8a_yes”><input type=”radio” value=”Yes” name=”question8a” id=”q8a_yes” />Yes</label><br>
<label for=”q8a_no”><input type=”radio” value=”No” name=”question8a” id=”q8a_no” />No</label>

<input type=”hidden” name=”q8ahid” id=”q8ahid” value=”javascript:q8aVar.toString()” />

<br><br><!–[if IE]> <br> <![endif]–>
<!–Question #8 B–>
<p class=”qtxt”>b. <b>How satisfied are you with our email communication system?</b></p>
<label for=”q8b_one”><input type=”radio” value=”Very Satisfied” name=”question8b” id=”q8b_one” />Very Satisfied</label><br>
<label for=”q8b_two”><input type=”radio” value=”Satisfied” name=”question8b” id=”q8b_two” />Satisfied</label><br>
<label for=”q8b_three”><input type=”radio” value=”Neutral” name=”question8b” id=”q8b_three” />Neutral</label><br>
<label for=”q8b_four”><input type=”radio” value=”Unsatisfied” name=”question8b” id=”q8b_four” />Unsatisfied</label><br>
<label for=”q8b_five”><input type=”radio” value=”Very Unsatisfied” name=”question8b” id=”q8b_five” />Very Unsatisfied</label>

<input type=”hidden” name=”q8bhid” id=”q8bhid” value=”javascript:q8bVar.toString()” />

</blockquote>

</div><br><!–[if IE]> <br> <![endif]–>

<!–Question #9–>
<li><p class=”qtxt”><span class=”red”>*</span> <b>In your opinion, how would you rate your overall experience with this website and/or our entire footwear network?</b></p>
<label for=”q9_one”><input type=”radio” value=”Very Satisfied” name=”question9″ id=”q9_one” />Very Satisfied</label><br>
<label for=”q9_two”><input type=”radio” value=”Satisfied” name=”question9″ id=”q9_two” />Satisfied</label><br>
<label for=”q9_three”><input type=”radio” value=”Neutral” name=”question9″ id=”q9_three” />Neutral</label><br>
<label for=”q9_four”><input type=”radio” value=”Unsatisfied” name=”question9″ id=”q9_four” />Unsatisfied</label><br>
<label for=”q9_five”><input type=”radio” value=”Very Unsatisfied” name=”question9″ id=”q9_five” />Very Unsatisfied</label>

<input type=”hidden” name=”q9hid” id=”q9hid” value=”javascript:q9Var.toString()” />
</li><br><!–[if IE]> <br> <![endif]–>

<!–Question #10–>
<li><p class=”qtxt”>Please tell us any other additional comments you may have:</p>
<textarea name=”question10″ rows=”4″ cols=”50″ maxlength=”1000″></textarea>

<input type=”hidden” name=”q10hid” id=”q10hid” value=”javascript:q10Var.toString()” />
</li><br><!–[if IE]> <br> <![endif]–>

</ol>

<p class=”qtxt”><b>Thank you</b> for completing this survey. We greatly appreciate your feedback!<br><br>
To show our gratitude, we will send you a 10% OFF Promotional Coupon Code to be used toward your next purchase. To receive your coupon code, please enter your name
and email address in the form below and click submit.</p>

<p class=”qtxt”>Name: </p>
<p class=”qtxt”>Email: </p>
<p class=”privc”>ShoeSurfing.com does not rent, sell or share any of your personal information.</p>

<input type=”submit” value=”Submit” onclick=”valbutton(feedback_form);return false;SetJsValue();” name=”submit”/>
</form>
[/code]

It validates and stores variables with this JavaScript file:

[code=html]function valbutton(thisform) {
// Question 1
q1Opt = -1;
for (i=thisform.question1.length-1; i > -1; i–) {
if (thisform.question1[i].checked) {
q1Opt = i; i = -1;
}
}
if (q1Opt == -1) {
alert(“Please respond to Question 1.”);
return false;
}

…snip…

// Question 7
q7Opt = -1;
for (i=thisform.question7.length-1; i > -1; i–) {
if (thisform.question7[i].checked) {
q7Opt = i; i = -1;
}
}
if (q7Opt == -1) {
alert(“Please respond to Question 7.”);
return false;
}

// Question 8
q8Opt = -1;
for (i=thisform.question8.length-1; i > -1; i–) {
if (thisform.question8[i].checked) {
q8Opt = i; i = -1;
}
}
if (q8Opt == -1) {
alert(“Please respond to Question 8.”);
return false;
}

// Question 8 A
q8aOpt = -1;
for (i=thisform.question8a.length-1; i > -1; i–) {
if (thisform.question8a[i].checked) {
q8aOpt = i; i = -1;
}
}

// Question 8 B
q8bOpt = -1;
for (i=thisform.question8b.length-1; i > -1; i–) {
if (thisform.question8b[i].checked) {
q8bOpt = i; i = -1;
}
}

// Question 9
q9Opt = -1;
for (i=thisform.question9.length-1; i > -1; i–) {
if (thisform.question9[i].checked) {
q9Opt = i; i = -1;
}
}
if (q9Opt == -1) {
alert(“Please respond to Question 9.”);
return false;
}

//Store Variables:

//Question 1
var q1Var = “”;
var q1Var = (thisform.question1[q1Opt].value);
document.feedback_form.q1hid.value = q1Var;

…snip

//Question 7
var q7Var = “”;
var q7Var = (thisform.question7[q7Opt].value);
document.feedback_form.q7hid.value = q7Var;

//Question 8
var q8Var = “”;
var q8Var = (thisform.question8[q8Opt].value);
document.feedback_form.q8hid.value = q8Var;

//Question 8 A
var q8aVar = “”;
var q8aVar = (thisform.question8a[q8aOpt].value);
document.feedback_form.q8ahid.value = q8aVar;

//Question 8 B
var q8bVar = “”;
var q8bVar = (thisform.question8b[q8bOpt].value);
document.feedback_form.q8bhid.value = q8bVar;

//Question 9
var q9Var = “”;
var q9Var = (thisform.question9[q9Opt].value);
document.feedback_form.q9hid.value = q9Var;

//Question 10 (textarea)
var q10Var = “”;
var q10Var = (thisform.question10.value);
document.feedback_form.q10hid.value = q10Var;

// submit form after validating
thisform.submit();

}[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @hoodev 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.28,
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,
)...