Hey Guys I have a applicate website that has a selection box to chose what store you would like to apply for. I can not figure out how to use the selection box to send the form to another PHP page. Right now when you click submit on the forum it sends it to a php page that emails the form to the correct store. I need to be able to send it to another store if they change the store that they are applying for. I know basic javascript. Please let me know where I can find this answer.
Give the selection-box the attribute data-send_to="some_page"
, and then use this JS code:
document.querySelector(".selection_box").onclick = function() {
document.getElementById('form').action = this.getAttribute('data-send_to') + '.php';
};
Also don't forget to give the form the same id as in the JS code (right now it's simply form
).
You can try this
var option = document.getElementById("clicked");
window.location="nextpagename";
In the Javascript below, you would change FORMNAME
to the name of your form and SELECTOR
to the name of the selector used inside the form.
document.forms.FORMNAME.onsubmit = function (event) {
var e = event || window.event,
form = e.currentTarget || e.sourceElement;
e.preventDefault();
if (form.action === "") return false; // Verify selection made
form.action = form.SELECTOR.value;
form.submit();
};
Your HTML should resemble this (to your page's specs of course):
<form name="FORMNAME" action="" method="post">
<select name="SELECTOR" id="SELECTOR">
<option value="" selected="selected">---Choose destination store---</option>
<option value="http://www.google.com">Google</option>
<option value="http://www.yahoo.com">Yahoo!</option>
</select>
</form>
PS - I believe you can use Daniel's answer just as well, mine is simply a way to avoid dealing with it until submission actually occurs, his is instantly. Cheers.