Ok, I know this has to be simple. My Javascript skills are very weak (will become obvious in the code.) What I'm trying to do is use two Submit buttons in a form. The called function I want to send one named variable if one Submit is clicked and another named variable if the other button is clicked. The examples I've seen make it simple -- just use two destination PHP files. But isn't it possible to send just post ONE (the name connected to the button clicked) to the PHP file to use?
I know the PHP has to be set up, ready to Post whatever comes it's way (using variable would be really neat but can't transfer a JS variable to PHP file I guess).
What happens below is that no matter WHICH button is pushed, both seem to be sent.
<form method="post" name="frm1" onSubmit="javascript: decide_action();" action="">
<input type="text" name="firstname"><br>
<input type="text" name="lastname"><br>
<INPUT TYPE="SUBMIT" name="submit" onClick="document.pressed=this.value" VALUE="First">
<INPUT TYPE="SUBMIT" name="submit" onClick="document.pressed=this.value" VALUE="Last">
</form>
<SCRIPT language="JavaScript">
function decide_action() {
x = document.pressed
if (x == "First")
{
myname =document.forms['frm1'].elements['firstname'].value;
document.frm1.action ="two.php";
}
else if (x == "Last")
{
myname=document.forms['frm1'].elements['lastname'].value;
document.frm1.action ="two.php";
}
}
</SCRIPT>
CAN this work?
Thanks for any advice (aside from "take up piano") will be appreciated.
-- Mike