Could someone take a look??

Results 1 to 2 of 2

Thread: Could someone take a look??

  1. #1
    Join Date
    Dec 1969

    Default Could someone take a look??

    Could someone take a look at this code and tell me why it&#039;s not recognizing what the user selects. I get the alert message from the function portion even if I select one way or return???<BR> <BR>I have 2 radio buttons on my form. I want to validate them with JScript where if one is equal to "R" then proceed with a return flight and if the value is "O" then proceed with a one way trip.<BR><BR>Here&#039;s the code on the asp page: <BR><BR>&#060;tr&#062;&#060;td&#062;&#060;input type="radio" value="R" checked name="flttype" STYLE="background: #EEEEEE"&#062;&#060;b&#062;Round Trip&#060;/b&#062; <BR>&#060;input type="radio" value="O" name="flttype" checked STYLE="background: #EEEEEE"&#062; <BR>&#060;b&#062;One Way&#060;/b&#062;&#060;/font&#062;&#060;/td&#062;&#060;/tr&#062; <BR><BR>Here&#039;s where I want to validate if the user goes to select a return date without selecting the round trip radio button but the problem is no matter which one I select it still displays the error message but if I don&#039;t click on the return date and just go to the next page it will pick up which radio button I selected and displays either the one way or return info??: <BR>function lstRMon_onclick() <BR>{ <BR> if (thisForm.flttype.value!="R") <BR>{ <BR>alert("Please select round trip!"); <BR>var dt = new Date(); <BR>thisForm.lstRMon.selectedIndex=dt.getUTCMonth( ); <BR>thisForm.lstRDay.selectedIndex=dt.getUTCDate ()-1; <BR>//thisForm.lstRYear.selectedIndex=-1; <BR><BR>} <BR>} <BR>

  2. #2
    Join Date
    Dec 1969

    Default Two bugs I see...

    (1) You have specified CHECKED for *BOTH* radio buttons! No idea what this does to the poor HTML processor&#039;s mind. Remove one of them.<BR><BR>(2) You can&#039;t use ".value" with radio buttons, check boxes, or &#060;SELECT&#062;s in any browsers but MSIE 4+ and NS 6+.<BR>You *really* need to use functions to get the values of radio button groups, etc.<BR><BR>Example:<BR><BR>function rbValue( rb )<BR>{<BR>&nbsp; &nbsp; for ( var ix = 0; ix &#060; rb.length; ++ix )<BR>&nbsp; &nbsp; {<BR>&nbsp; &nbsp; &nbsp; &nbsp; if ( rb[ix].checked ) return rb[ix].value;<BR>&nbsp; &nbsp; }<BR>&nbsp; &nbsp; return null;<BR>}<BR><BR>And then in place of:<BR>&nbsp; &nbsp; if (thisForm.flttype.value!="R") <BR>you woudl code:<BR>&nbsp; &nbsp; if ( rbValue(thisForm.flttype) != "R" )<BR><BR>You have to use similar code for checkboxes (if there&#039;s more than one with the same name, that is) and &#060;SELECT&#062;s. And it gets more comples if multiple values can be returned.<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