We help IT Professionals succeed at work.

PHP or Javascript

kkbenj
kkbenj asked
on
I have 2 buttons on a page.  Each calls the same resulting page, but I want to pass a hidden field filled with a different variable for each button.

My PHP code is very simple.  Shown is one of the 2 buttons.  But in checking the posted values on the subsequent page, it is blank.

What am I doing wrong?
<form id='account-form' action='abc.php' method='POST'>
<INPUT type='hidden' name='rcptdate'>

<?php
$DonateDt="20111107";
echo "<input class='pill-button' type='submit' value='Receipt' onClick='this.account-form.rcptdate.value=".$DonateDt."'; />";
?>

Open in new window

Comment
Watch Question

Top Expert 2013

Commented:
change:

this.account-form.rcptdate.value


to this.value

Cd&
Top Expert 2013

Commented:
Sorry I miss read it

change it to  forms.account-form.rcptdate.value

Cd&

Author

Commented:
Changing this.account-form.rcptdate.value to forms.account-form.rcptdate.value did not work.

Just to be clear, I need to be able to set the value of the hidden field on click.  The php code takes care of filling the variable $DonateDt, then upon click it needs to assign it.
Most Valuable Expert 2011
Top Expert 2016

Commented:
You can use var_dump($_POST) to see the contents of the post array.

If you have two submit buttons, why no just detect which button was submitted by testing the value of the named submit button?  Easy!
Top Expert 2013
Commented:
Oh I'm a dummy.  It's been a while since I saw anybody do it.  Hyphen is an illegal character in a Javascript variable.


so change the name of the form to accountForm and then:

document.forms.accountForm.rcptdate.value

should work.

Author

Commented:
Cobol - perfect and easy solution.  Thanks for the speedy responses.
Top Expert 2013

Commented:
It would have been better if I had been paying better attention and got it right the first time.  Need more coffee I think. :^)



Cd&