Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Dec 2005
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Radio button validation and focus help needed

    Hi,

    I am coding up a questionnaire in Domino 6.5.4. I am trying to validate all fields and when not succesful return an errror message and a subsequent focus to the field in question. Within the form there is a button that calls a dosubmit function located in the jsheader field. All works well except for two areas :

    1 When trying to ensure that the a radio button has been selected (ie the question answered) the validation does not seem to be working. After many tinkerings with the syntax (value==null, checked==false) I still dont seem to be getting this to work (it either accepts the form in the browser or returns the error message advising that the field is still blank (in the case below the error is "please enter frequency"). My feeling is that my syntax is incorrect on this one so if someone could set this tired head straight it would be appreciated.

    2 When returning the focus to the radio button in question in the browser it leaves out the text appearing above - essentially the question located two lines above. I realise that the focus is due to my selecting [0] -- ( [0] being the first option in the radio button). Was wondering if there was any way to get the lines above to appear. the question is in text format and not a field so I can't ask for the focus to go to that field. I would just like a little more text appearing above. the code follows below and any help would be much appreciated as I think I am getting circular and not seeing the wood for the trees !!!

    JS Header :

    function doSubmitForm(){

    var f=document.forms[0];
    if (f.FirstName.value==""){
    alert("Please enter your first name");
    f.FirstName.focus();
    return false;
    }
    if (Surname.value==""){
    alert("Please enter your surname ");
    f.FirstName.focus();
    return false;
    }
    if (loginfrequency.checked==false){
    alert("Please enter frequency ");
    f.loginfrequency[0].focus();
    return false;
    }

    return f.submit();
    }

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,521
    Thanks
    3
    Thanked 507 Times in 494 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function CheckRadio(f){
     var eles=f.elements;
     var names='';
     var radiogrp,ck;
     for (zxc0=0;zxc0<eles.length;zxc0++){
      if (eles[zxc0].type=='radio'&&!names.match(eles[zxc0].name)){
       ck=false;
       names+=eles[zxc0].name+',';
       radiogrp=f[eles[zxc0].name];
       for (zxc1=0;zxc1<radiogrp.length;zxc1++){
        if (radiogrp[zxc1].checked){
         ck=true;
        }
       }
       if (!ck){
        alert('check one in radio group '+eles[zxc0].name);
       }
      }
    
     }
    
    }
    //-->
    </script></head>
    
    <body>
    radio buttons of the same name form an array so must be checked using something like this if the name cannot be used<br>
    <form>
    <input type="radio" name="fred">
    <input type="radio" name="fred">
    <input type="radio" name="fred"><br>
    <input type="radio" name="tom">
    <input type="radio" name="tom"><br>
    <input type="button" value="Check Radio" onclick="CheckRadio(this.form);" >
    </form>
    </body>
    
    </html>
    Last edited by vwphillips; 12-29-2005 at 10:30 PM. Reason: code tags


  •  

    Posting Permissions

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