Submit Alternates Target URL

[Total: 0    Average: 0/5]

This shows how to have a form submit button alternate the target of its submit.

Body Code:

<form name=exf1>
<input type=text name=t1 value="http://www.js-examples.com">
<input type=text name=t2 value="http://www.js-examples.com/">
<input type=hidden name=which value="1">
<input type=button value="Go!" onclick="goNow()">
</form>
<script>
function goNow() {
var x = document.exf1.which.value!="1"?"1":"2";
document.exf1.which.value=x;
var y = eval("document.exf1.t"+x+".value");
alert("going to "+y);
document.exf1.action=y;
document.exf1.target="_blank";
document.exf1.submit();
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *