View Full Version : do radio buttons have to be clicked twice when using js

andrew midgley
10-30-2008, 11:11 AM

i have a set of radio buttons with some javascript attached to each one. for some reason the javascript only runs on the second click (i.e you have to click once to activate the radio button and click again to run the javascript)

is this a known issue or is there something strange in my code.

this happens with all javascript events like onmousedown \ onmouseover \ onclick etc.

here my code.

any help appreciated


<td class="form_field" valign='top' align='right'>How Would You Like Paying?</td><td width='10' aligh='right' valign='top'> <font
size='2' color='#ff0000'>*</font> </td>

<td class="form_text">
<input onMouseUp="return paypals()" type="radio" id="charityradio" name="Please_select" value="Donate Funds To Charity" <?php
formChecked($HTTP_POST_VARS[ "Please_select" ], "Donate Funds To Charity" ); ?> > Donate Funds To Charity (children in need)

<input onMouseUp="return paypals()" type="radio" id="paypalradio" name="Please_select" value="PayPal Payment" <?php
formChecked( $HTTP_POST_VARS[ "Please_select" ], "PayPal Payment" ); ?>
> PayPal Payment<br>

<input onMouseUp="return paypals()" type="radio" id="chequeradio" name="Please_select" value="Cheque" <?php formChecked(
$HTTP_POST_VARS[ "Please_select" ], "Cheque" ); ?> > Cheque<br>
<script type="text/javascript">

function paypals() {

chosen = ""
len = document.frmFormMail.Please_select.length

for (i = 0; i <len; i++)
if (document.frmFormMail.Please_select[i].checked)
chosen = document.frmFormMail.Please_select[i].value

if (chosen == "")
//alert("No Location Chosen")
if (chosen == "Donate Funds To Charity")
document.getElementById("paypal").style.visibility = "hidden"
document.getElementById("cheque").style.visibility = "hidden"
else if (chosen == "PayPal Payment")
document.getElementById("paypal").style.visibility = "visible"
document.getElementById("cheque").style.visibility = "hidden"
else if (chosen == "Cheque")
document.getElementById("paypal").style.visibility = "hidden"
document.getElementById("cheque").style.visibility = "visible"
return false

10-30-2008, 04:42 PM
You should use the onclick event, not the onmouseup. There could be other problems.

Please post a link to the page on your site that contains the problematic code so we can check it out.