i want to post to a different php depending on a drop down select. for example; option value "2" English to French, should post to "send_english.php", where as option value "3" French to English Should post to send_french.php. The closest i have got to this incorporates javascript, but any method you can think of would be good. Below is the javascript but it does not work.
</script>
<script type="text/javascript">
function check() {
var f = document.getElementById('form1');
var s = document.getElementById('select1');
if (s.selectedIndex == "2") {
f.setAttribute("method", "POST");
f.setAttribute("action", "send_english.php");
f.submit("Translate");
}
if (s.selectedIndex == "3") {
f.setAttribute("method", "POST");
f.setAttribute("action", "send_french.php");
f.submit("Translate");
}
}
</script>
</head>
<body>
<div style="height: 22px">Translate English to French</div>
Don't forget to close your opening SELECT tag, and give your event something to do:
Code:
<select id="Select1" name="language" onclick="check();">
<option value="1"></option>
<option value="2">English to French</option>
<option value="3">French to English</option>
</select>
Also, since you're using selectedIndex and not the VALUE of the selectedIndex, don't use quotes around 2 or 3. And it would be a bit simpler to use a switch/case statement:
Code:
function check() {
var f = document.getElementById('form1');
var s = document.getElementById('select1');
switch(parseInt(s.selectedIndex)) {
case 2:
f.setAttribute("method","POST");
f.setAttribute("action","send_english.php");
f.submit(); // You don't need any parameters to submit a form
break;
case 3:
f.setAttribute("method","POST");
f.setAttribute("action","send_french.php");
f.submit(); // You don't need any parameters to submit a form
break;
}
}
And your FORM element needs a default action for those of us who do not use JavaScript. A submit button inside a NOSCRIPT element wold be nice too.
“The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
—Tim Berners-Lee, W3C Director and inventor of the World Wide Web
thanks. WolfShade's code didn't work, but MarPlo is getting there. But instead of it posting when selected, could it be posted when clicked on the submit (translate) button instead?
Bookmarks