Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Radio boxes with OnChange()?

Status
Not open for further replies.

bluedollar

Programmer
Jul 24, 2003
174
GB
I have a some code that is supposed to call a script when a radio box is selected, the code is shown below:

===========================================================

<?php

class checkout3_class {

function chk31() {

echo'<html>';
echo'<head>';
echo'<title></title>';
echo'</head>';
echo'<body>';
echo'<form name=&quot;payment&quot; method=POST action=&quot;checkout3script.php&quot;>';
echo'<table border=&quot;0&quot;>';
echo'<tr><th colspan=&quot;2&quot; align=&quot;left&quot; bgcolor=&quot;#999999&quot;>Delivery Address</th></tr>';
echo'<tr><td colspan=&quot;2&quot;><br>Please enter payment details:<P></td></tr>';

}

function creditonline() {
echo'<tr><td><input type=&quot;radio&quot; onChange=&quot;document.payment.submit();&quot; name=&quot;ocredit&quot;</td><td>Pay by Card Via Secure Online Transaction</tr>';
}

function creditphone() {
echo'<tr><td><input type=&quot;radio&quot; onChange=&quot;document.payment.submit();&quot; name=&quot;pcredit&quot;</td><td>Pay by Card Via Phone Transaction</td></tr>';
}

function cheque() {
echo'<tr><td><input type=&quot;radio&quot; onChange=&quot;document.payment.submit();&quot; name=&quot;ocheque&quot;</td><td>Pay by Cheque/Postal Order</td></tr>';
}

function chk32() {

echo'<tr><td colspan=&quot;2&quot; align=&quot;center&quot;><br><input type=&quot;submit&quot; name=&quot;details&quot; value=&quot;Next&quot;></td></tr>';
echo'</table>';
echo'</form>';
echo'</body>';
echo'</html>';

}

}

?>

==========================================================

PROBLEM

- The script only runs after you have selected two radio boxes.

Question

1) How do you get the script to run after just selecting ONE radio box?

Any help would be greatly appreciated.

Thanks

Dan
 
Thanks, works fine, but have come up with a new problem.

Q: When I click on one of the radio buttons how do keep it checked.

What I am doing at the moment, basically, in the script that is called when they are selected:

if (isset(button1)) {
$checkout3class->radio1button(true);
misc other code
}
else {
$checkout3class->radio1button(false);
misc other code
}

and I have modified the checkout3classes functions that contain radio boxes to take a boolean parameter to determined whether the box is CHECKED or not.

This works, but the boxes stay checked eg.

1) click on radio box one, script creates page and box one is checked.
2) THEN click on box two, script creates page and box one AND two are checked.

Does anyone have any ideas how I would solve this problem?

Thanks

Dan


 
radio buttons work by all having the same name. name them all radio1button and then you can only select one at a time... this will of course affect your boolean testing...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top