Richard Korts
asked on
Javascript or php problem?
I have what seems impossible.
Note these code sections. First, a form field called "agency", done like this:
Next, the javascript function set_form(), like this:
Note the alerts in the function set_form(). When I pick a value other than Houston from the dropdown, the alerts display, but but NEVER goes to subscribet.php.
Obviously I have tried to break this down to it's simplest elements. The "real" subscribe.php program does much more.
The result is that it jumps to another version of the first program called form.php.
If it drops through to the end of set_form(), it will go to save_form.php which will have the effect of what is happening. The way I see the logic, that is impossible.
I am probably just missing the obvious. I have tried running this in Firefox with Firebug turned on & Chrome with F11. They show nothing.
Can someone see what is wrong?
Thanks
Note these code sections. First, a form field called "agency", done like this:
<div class="row">
<div class="col-sm-6 col-xs-6 text-right" style="padding-top:3px;">Agency: </div>
<div class="col-sm-6 col-xs-6 text-left" style="padding-top:3px;"><select name="agency" onChange="set_form();">
<option value="">-- Select Agency -- </option>
<? for ($i = 0; $i < $nf; $i++) {
$f = mysqli_fetch_array($resf,MYSQLI_ASSOC);
$sel = "";
if ($_SESSION['form'] == $f['agency']) {
$sel = "selected";
} ?>
<option value="<? print $f['agency']; ?>" <? print $sel; ?>><? print $f['agency']; ?></option>
<? } ?>
</select></div>
</div>
Next, the javascript function set_form(), like this:
function set_form() {
t = document.st.asstyp.value;
if (document.st.agency.value != "Houston") {
if (free == "FR") {
jj = confirm("This form requires subscription fee. Continue?");
if (! jj) {
document.st.agency.value = "Houston";
return false;
} else {
alert("going to subscriben.");
document.st.action = "subscribet.php?fr=f&ag=" + document.st.agency.value;
document.st.submit();
}
}
}
document.st.action="save_form.php?t=" + t;
document.st.submit();
}
Finally, the code in subscribet.php:?php
echo "entered subscribe test<br>";
exit;
?>
Note the alerts in the function set_form(). When I pick a value other than Houston from the dropdown, the alerts display, but but NEVER goes to subscribet.php.
Obviously I have tried to break this down to it's simplest elements. The "real" subscribe.php program does much more.
The result is that it jumps to another version of the first program called form.php.
If it drops through to the end of set_form(), it will go to save_form.php which will have the effect of what is happening. The way I see the logic, that is impossible.
I am probably just missing the obvious. I have tried running this in Firefox with Firebug turned on & Chrome with F11. They show nothing.
Can someone see what is wrong?
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As @gr8gonzo has already pointed out you need the return;
Basically, your script is dropping through to the action and submit at the end of your script, so you need to prevent that.
Basically, your script is dropping through to the action and submit at the end of your script, so you need to prevent that.
ASKER
I thought I did this 1,000 times before like this, but that sure does the job!!
Thanks,
Richard
Thanks,
Richard
The save_form part should be enclosed with an 'else' statement.