hello,
this is the problem I have been facing. I have 2 different buttons in a single form that when they are hit I want them to do 2 different things.
They are not submit buttons, because I don't want to submit the form always, but only when the checkbox of the form is checked. Otherwise, if the checkbox is unchecked, the form will not be submitted, but instead an alert message will be displayed to the user.
The problem is that I haven't found a way so far to see which button has been hit and execute different things in each case. The isset function doesn't work with plain buttons that are not submit buttons. I would like to note that these things that I want to be executed are in the same page as the form.
Here is a short description of the code (testpage1.php):
for the form:
print "<form name=\"main_form\" method=\"POST\">";
print "<input type=\"checkbox\" name=\"fieldname\" value=\"anyvalue\">";
print "<input type=\"button\" name=\"submit1\" value=\"button1\" onClick='javascript:checkbutton1();'>";
print "<input type=\"button\" name=\"submit2\" value=\"button2\" onClick='javascript:checkbutton2();'>";
print "</form>";
for the Javascript function:
echo '<script language="JavaScript">
function checkbutton1()
{
if ((document.forms["main_form"].fieldname[0].checked==1))
{
document.forms["main_form"].action="testpage1.php";
document.forms["main_form"].submit();
}
else
{
alert ("Please check the value for which you want to find the exhibits");
}
}
function checkbutton2()
{
if ((document.forms["main_form"].fieldname[0].checked==1))
{
document.forms["main_form"].action="testpage1.php";
document.forms["main_form"].submit();
}
else
{
alert ("Please check the value for which you want to find the categories");
}
}
</script>';
Now if in testpage1.php in the beggining I write:
if (isset($submit1))
{
// do something
}
if (isset($submit2))
{
// do something else
}
it doesn't work! Does anyone have an idea that could help me?
Thanks,
Georgianna