R
Raffi
Hi,
I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.
<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="javascript:some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1" value="Submit 1"
onclick="javascript:var flag=1;">
<input type="submit" name="submit2" value="Submit 2"
onclick="javascript:var flag=2;">
</form>
</BODY>
</HTML>
<?php
if ($_POST[submit1]) {
echo "submit1";
}
if ($_POST[submit2]) {
echo "submit2";
}
?>
I have a form that has 2 submit buttons. The form action is a php
script. What I'm trying to do is to execute a different javascript
function depending on which submit button is pressed. So far I've tried
the following with no success. In the code below, a different function
would execute based on the value of the "flag" variable.
<HTML>
<HEAD>
<SCRIPT TYPE="text/javascript">
function some_function() {
alert(flag);
}
</SCRIPT>
</HEAD>
<BODY>
<form name="form1" action="./submit.php" method="POST"
onsubmit="javascript:some_function()">
<input type="text" name="name" size=50>
<input type="submit" name="submit1" value="Submit 1"
onclick="javascript:var flag=1;">
<input type="submit" name="submit2" value="Submit 2"
onclick="javascript:var flag=2;">
</form>
</BODY>
</HTML>
<?php
if ($_POST[submit1]) {
echo "submit1";
}
if ($_POST[submit2]) {
echo "submit2";
}
?>