|
|
I have a PHP script which generates an (unknown) number of forms on a single page. Upon clicking I want a simple javascript check function along the lines of:
function submitform()
{
var con=confirm("Do you really want to do this?");
if(con==true)
{
document.form1.submit();
}
else
{
window.location="payment.php";
}
(The actual check is always the same) Obviously, in PHP I can generate the form so that they have different names:
<form name="form<?=$formnumber?>" method="POST" action="payment_action.php"> and/or <a href="javascript: submitform(form<?=$formnumber?>)">Payment</a>, but I am unsure of how to chage the javascript to cope with this.
Thanks in advance,
LETMO
|
|
|
|
letmo - You could pass in the form name into the function, as in
function submitform(formname)
{
var con=confirm("Do you really want to do this?");
if(con==true)
{
document(formname).submit();
}
else
{
window.location="payment.php";
}
|
|
|
|
|
|
The problem with this (I think) is that I don't know how many forms there are. I tried generating the form names in php i.e. form1, form2, form3 etc. and then having more than enough Javascript functions i.e.
function submitform(form1)
function submitform(form2)
function submitform(form3)
etc.
But if the form doesn't exist (form5 for example), I get an error & none ofthe submitforms work.
|
|
|
|
|
|
|
|
|
|
|
// |