Current location: Hot Scripts Forums » General Web Coding » JavaScript » Need Js for radiobutton validation


Need Js for radiobutton validation

Reply
  #1 (permalink)  
Old 11-15-09, 11:53 PM
rsmahaa rsmahaa is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Need Js for radiobutton validation

my code is blow,,,
1. If i select the first option i have validate first txt box (should hav 11 char).
2. If i select the secondoption i have validate second txt box (not empty).
Someone Plz Help
HTML Code:
<table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="24%" rowspan="2">Select Shipping Type </td>
              <td width="25%" valign="top"><div align="right">Blue Dart
                <input name="type" type="radio" value="B" />
              </div></td>
              <td width="2%" valign="top"><div align="center">:</div></td>
              <td width="49%" height="22"><input name="billno" type="text" id="billno" style="WIDTH: 130px" onfocus="this.value=''" 
onclick="javascript:clearbox();" value="Enter  Bill  No" size="10" maxlength="60" /></td>
            </tr>
            
            <tr>
              <td height="22"><div align="right">Hand Delivery
                <input name="type" type="radio" value="H" />
              </div></td>
              <td><div align="center">:</div></td>
              <td><input name="storeid" type="text" id="storeid" value="Enter Store Id" onfocus="this.value=''" onclick="javascript:clearbox();"/></td>
            </tr>
          </table>
            <p>&nbsp;</p></td>
        </tr>
        <tr>
          <td colspan="3" class="login_txt"><div align="center">
            <input name="rma" type="hidden" id="rma" value="<?php echo $rma; ?>" />
            <input type="submit" name="Submit" value="Submit" onclick="valbutton(myform);return false;" />
          </div></td>
          </tr>
      </table>
          <?php } ?>
      <p align="center">&nbsp;</p>
      </td>
  </tr></form>
</table>
</body>
</html>

Last edited by job0107; 11-20-09 at 06:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-16-09, 04:50 AM
rsmahaa rsmahaa is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry correct code is here

HTML Code:
<table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="24%" rowspan="2">Select Shipping Type </td>
<td width="25%" valign="top"><div align="right">Blue Dart
<input name="type" type="radio" value="B" />
</div></td>
<td width="2%" valign="top"><div align="center">:</div></td>
<td width="49%" height="22"><input name="billno" type="text" id="billno" style="WIDTH: 130px" onFocus="this.value=''" 
onclick="javascript:clearbox();" value="Enter Bill No" size="10" maxlength="60" /></td>
</tr>

<tr>
<td height="22"><div align="right">Hand Delivery
<input name="type" type="radio" value="H" />
</div></td>
<td><div align="center">:</div></td>
<td><input name="storeid" type="text" id="storeid" value="Enter Store Id" onFocus="this.value=''" onClick="javascript:clearbox();"/></td>
</tr>
</table>
<p>&nbsp;</p></td>
</tr>
<tr>
  <td colspan="3" class="login_txt">&nbsp;</td>
</tr>
</table>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 11-18-09, 10:26 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,516
Thanks: 20
Thanked 109 Times in 106 Posts
The radio buttons need to have the same name, then you can add an onclick event.

Go to W3Schools Online Web Tutorials for reference.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-19-09, 04:45 AM
rsmahaa rsmahaa is offline
Newbie Coder
 
Join Date: Nov 2009
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
k thanks for reply
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 11-20-09, 06:38 AM
job0107's Avatar
job0107 job0107 is offline
Community Liaison
 
Join Date: Dec 2006
Location: Tacoma, Washington USA
Posts: 3,454
Thanks: 0
Thanked 140 Times in 137 Posts
If you use the onfocus() event listener in your radio buttons, it won't let you select a radio button until you have entered a correct value in the associated text box.

Example:
HTML Code:
<html>
<head>
<script>
function validate(v)
{
 var textBox1 = document.getElementById("billno");
 var textBox2 = document.getElementById("storeid");
 if(v == "B")
 {
  if(textBox1.value == "Enter Bill No" || textBox1.value == "" || textBox1.value.length != 11){alert("Value entered is incorrect.");}
  }
 if(v == "H")
 {
  if(textBox2.value == "Enter Store Id" || textBox2.value == ""){alert("Value entered is incorrect.");}
  }
 }
</script>
</head>
<body>
<table width="100%" height="56" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="24%" rowspan="2">Select Shipping Type </td>
<td width="25%" valign="top"><div align="right">Blue Dart
<input name="type" type="radio" value="B" onfocus="validate(this.value)" />
</div></td>
<td width="2%" valign="top"><div align="center">:</div></td>
<td width="49%" height="22"><input name="billno" type="text" id="billno" style="WIDTH: 130px" onFocus="this.value=''"
onclick="javascript:clearbox();" value="Enter Bill No" size="10" maxlength="60" /></td>
</tr>

<tr>
<td height="22"><div align="right">Hand Delivery
<input name="type" type="radio" value="H" onfocus="validate(this.value)" />
</div></td>
<td><div align="center">:</div></td>
<td><input name="storeid" type="text" id="storeid" value="Enter Store Id" onFocus="this.value=''" onClick="javascript:clearbox();"/></td>
</tr>
</table>
<p>&nbsp;</p></td>
</tr>
<tr>
  <td colspan="3" class="login_txt">&nbsp;</td>
</tr>
</table>
</body>
</html>
__________________
Jerry Broughton
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 05-07-10, 10:59 AM
khill07 khill07 is offline
New Member
 
Join Date: May 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
The following script will do any type of validation you need, include radio buttons:
Validation Plugin
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
JS works in all but Firefox for Mac...done lots of homework... Jayson44 JavaScript 5 12-09-08 09:58 AM
ajax checking and onsubmit issue follower JavaScript 4 10-12-08 04:45 PM
SSO solution / JS for multiple logins needed... doedelkrake Script Requests 0 08-17-05 11:59 AM
validation not working buzzby PHP 13 05-29-05 03:09 PM
Validation oracle_mik JavaScript 4 04-04-05 08:50 PM


All times are GMT -5. The time now is 09:09 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.