Jump to content

javascript not working for radio buttons....


sunil.23143

Recommended Posts

hello,

i m using the folloing javascript for all the forms of my web. This script works well for all the fields...but not for radio buttons due to the reason that i have two radio buttons of the same name.

but if the radio button names are different the script works well.but due to some programming i cant give different names to two radio buttons....

 

 

# function MM_findObj(n, d) {
# //alert(n)
# //alert(d)
#   var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
#     d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
#   if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
#   for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
#   if(!x && d.getElementById) x=d.getElementById(n);  return x;
# }
#  
# function MM_validateForm() {
#   var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
# //alert(args.length-2)
#   for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
#     //alert(val)
#  
#     if (val) { nm=args[i+1]; if ((val=val.value)!="") {
#  
#                // alert(val)
#       if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
#         if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
#       } else if (test!='R') { num = parseFloat(val);
#         if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
#         if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
#           min=test.substring(8,p); max=test.substring(p+1);
#           if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
#     } } }  else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
#   }
#  
# //alert(document.getElementById('agreement1').value)
# //alert(document.getElementById('agreement').value)
#  
# //alert("work")
# //if(document.referrer.getElementById('agreement1').value=='1') errors+='Must accept terms of conditions ref';
#  
#  
# //if(document.getElementById('agreement').value=='1') errors+='Must pt terms of conditions';
#  
#  
#  
#  
# if (errors) alert('The following error(s) occurred:\n'+errors);
#  
#   document.MM_returnValue = (errors == '');
#  
# }

 

he form where i m applying this script is given below.if a field is blank, on submit a alert box appears conveying the information about field set black...this works well for the field "state" but not for the field "gender"....your sugestions are most welcomed.........

   1. <table width="100%" border="0" cellspacing="0" cellpadding="0">
   2.  <form name="register" action="index.php?mode=register" method="post" >
   3.                     <tr>
   4.                         <td colspan="4" class="form-main-bold">Create your account <span class="box-main-bold">Please give your login and brief personal details</td>
   5.                    </tr>
   6.  
   7.                    <tr>
   8.                         <td align="left" valign="middle" class="box-main-bold">Gender : </td>
   9.                         <td colspan="2" valign="top" class="form-text"><input name="gender" type="radio" id="gender" value=""  />
  10.                           Male  
  11.                           <input type="radio" name="gender" id="gender" value="" />
  12.                           Female</td>
  13.                   </tr>
  14.                    <tr>
  15.                         <td align="left" valign="top" class="box-main-bold">Current Location :
  16.              </td>   <input type='text' class="textbox" name="state" id="state" value="" maxlength="20" />< /td>
  17.                   </tr>
  18.  
  19.                    <tr>                      
  20.                         <td width="222" align="right" valign="middle" class="TextTD_Right"><input name="Submitregis" type="submit" class="button" id="Submitregis" value="Submit and Create Account "  onClick="MM_validateForm('gender','Gender :','R','state','State :','R');return document.MM_returnValue" /></td>
  21.                      </tr>
  22.  
  23. </table>
  24.  

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.