Hi Folks,
I’m new at this and am I’m trying to combine PHP and javascript to write some simple form submission code. (learning process and all that). It’s a little mix of everything, but I’m guessing javascript(which I know least about) is causing me the trouble so I thought I’d post here:
On a PHP page I have a form
[code=php]
echo”<form method=”POST” name=”ReActivate”>”;
…….and later…..
if($_SESSION[‘A_Number’] >= 100){
echo “<input type=”submit” value=”Do Something” name=pay onclick=”return checkme3();”>”;
}
….later…</form>
In the head of that page I have the checkme3 function:
[code]
function checkme3() {
var formObj = document.ReActivate;
var count = 0;
for (i=0;i<formObj.length; i++){
if(formObj.elements[i].type == ‘checkbox’)
if(formObj.elements[i].checked)
count++;
}
if (count < 1){
alert(“Some Error”);
return false;
}
{
document.ReActivate.action = “validation.php”
document.ReActivate.target = “_self”; // Open in a new window
document.ReActivate.submit(); // Submit the page
return true;
}
}
The idea is that unless at least one checkbox option is selected don’t continue, otherwise submit the page.
Now everything works great – unless I test the code on Safari(on windows) If I use any other browser, on the validate.php page I can access the POSTed variables, but in Safari, the pay variable isn’t passed through – and I have no idea why. 8-/
There is a second button within the same form, once clicked that should be sent off the validate as well, just with a different name value on the submit button:
[code=php]
echo “<table><tr><td><input type=”submit” value=”Re-Activate” name=ReActivate onclick=”return checkme1();”></td></tr></td></table>”;
[code]
which is pretty much exactly the same
function checkme1() {
var formObj = document.ReActivate;
var count = 0;
for (i=0;i<formObj.length; i++)
{
if(formObj.elements[i].type == ‘checkbox’)
if(formObj.elements[i].checked)
count++;
}
if (count < 1)
{
alert(“Another Error”);
return false;
}
{
document.ReActivate.action = “pay.php”
document.ReActivate.target = “_self”; // Open in a new window
document.ReActivate.submit(); // Submit the page
return true;
}
}
So there seems to be some difference between the way Safari deals with the above. In every other browser I’ve checked I have access to the pay variable submitted when I click on that submit button.
Sorry if I’m not clear enough – I’d appreciate any pointers you could provide!!
thanks,
Robin.