Results 1 to 3 of 3

Thread: radio button verification

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    a javascript question.

    i have three radio buttons and I want to, on form submit, verify what one has been choose.

    I am trying this:
    var strURL=document.frmEvent.txtURL.value;
    var optionButtonSelected=document.frmEvent.inpURL.checked;
    alert(optionButtonSelected);


    this is inside the function called by the submit button.

    i have the names correct.
    the form is called frmEvent and there is a text field called txtURL and the radio buttons are all called inpURL.

    as you can see i have an alert to get the value from the checked radio but it comes back 'undifined'

    so what am i doing wrong?
    any suggestions are welcome,
    if you need more information , just ask.

    thanks
    pnj

  2. #2
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    try this:

    Code:
    <HTML>
    <HEAD>
    <script language=javascript>
    
    function x(){
    var strURL=document.frmEvent.txtURL.value;
    var optionButtonSelected=-1;
    
    for(var i=0;i<document.frmEvent.inpURL.length;i++)
    {
    	if(document.frmEvent.inpURL(i).checked==true)
    	{
    		optionButtonSelected = i;
    	}
    	
    }
    
    if(optionButtonSelected==-1)
    {
    	alert("Please select and option")
    }else{
    	alert(optionButtonSelected);
    }
    }
    </script>
    </HEAD>
    <BODY>
    <form name=frmEvent>
    <input name=txtURL>
    <INPUT name=inpURL type=radio> option 1<BR>
    <INPUT name=inpURL type=radio> option 2<BR>
    <INPUT name=inpURL type=radio> option 3<BR>
    <input type=button onClick="x();">
    </form>
    </BODY>
    </HTML>
    Mark
    -------------------

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jun 2000
    Posts
    537
    thanks,
    turns out i'm not doing it this way but i'll be putting that code into my 'javascript' library.


    thanks again Mark
    pnj

Posting Permissions

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



Click Here to Expand Forum to Full Width