/    Sign up×
Community /Pin to ProfileBookmark

Missing submit variable value.

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>
[/code]

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;
}

}
[/code]

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]

[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;
}

}
[/code]

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.

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Aug 18.2008 — You are not looping through the elements lenght here:
<i>
</i>for (i=0;i&lt;formObj.length; i++){


You are looking at the lenght of the form object. You should be looking at the length of the object's elements. So try doing
<i>
</i>for (var i=0;i&lt;formObj.elements.length; i++){



Eric
Copy linkTweet thisAlerts:
@robulusauthorAug 18.2008 — Hi Eric,

thanks for the quick reply! I've made the change you suggested - but when I try :

<i>
</i> alert(formObj.elements.length);
alert(formObj.length);


alerts prints the same result for each reference. Also:

http://docs.sun.com/source/816-6408-10/form.htm seems to say that they're the same?

The Safari issue is still plaguing me - any takers?

thanks for taking a look,

Robin.
×

Success!

Help @robulus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...