Radio Buttons

Results 1 to 2 of 2

Thread: Radio Buttons

  1. #1
    Join Date
    Dec 1969

    Default Radio Buttons

    I want to check if the value of 2 radio buttons are the same when a user clicks on a button. if the values are identical i want to tell the user that their parking time is invalid.<BR><BR>i have this code but i keep getting the error "expected;"<BR>&#060;script&#062;<BR>function checkForm()<BR>{<BR>if (Booking.start.value == Booking.fin.value)<BR> {alert("You must enter a valid parking duration");}<BR>end if <BR>&#060;/script&#062;<BR>and this is my button code<BR>&#060;input type = "submit" value = "Book!" onClick= "checkForm();" name = "B1"&#062; &#060;/td&#062;<BR><BR>any help would be gratefully appreciated...<BR>thanks!<BR>

  2. #2
    Join Date
    Dec 1969

    Default Can't use .value for radio buttons

    You have to "calculate" it:<BR><BR>&#060;SCRIPT Language=JavaScript&#062;<BR><BR>function radioValue( group )<BR>{<BR> for ( var r = 0; r &#060; group.length; ++r )<BR> {<BR> if ( group[r].checked ) return group[r].value;<BR> }<BR> return null;<BR>}<BR>&#060;/SCRIPT&#062;<BR><BR>And *NOW* you can code:<BR><BR>function checkForm()<BR>{<BR> if ( radioValue(Booking.start) == radioValue(Booking.fin) )<BR> ...<BR><BR>You might want to check that you aren&#039;t getting null from both though. So maybe:<BR><BR><BR>function checkForm()<BR>{ <BR> var startVal = radioValue(Booking.start);<BR> var endVal = radioValue(Booking.fin);<BR> if ( startVal == null &#124&#124 endVal == null )<BR> {<BR> alert("You must push one of the start and one of the end buttons");<BR> return false;<BR> }<BR> if ( startVal == endVal )<BR> {<BR>...<BR><BR> ...<BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts