faqts : Computers : Programming : Languages : JavaScript

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

4 of 5 people (80%) answered Yes
Recently 4 of 5 people (80%) answered Yes

Entry

I need js to read numeric user input then onblur js checks a radio box ie. 1 to 20 21 to 40 etc.

Apr 8th, 2008 19:11
ha mo, Dave Clark, steven scott,


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Steven,
     Rather than onblur, I'd recommend using onchange:
<form action="">
  <p><input type="text" name="tx1" size="5" onchange="
   if (/^\s*$/.test(this.value)) {
     alert('Value is required.');
     return false;
   }
   var nbr = Number(this.value);
   if (isNaN(nbr)) {
     alert('Value must be numeric.');
     return false;
   }
   if (nbr < 1 || 99 < nbr) {
     alert('Value must be from 1 to 99.');
     return false;
   }
   var grp = this.form.elements['rd1'];
   var x, len = grp.length;
   for (x=0; x<len; ++x) {
     if (nbr <= Number(grp[x].value)) break;
   }
   if (x < len) {
     grp[x].checked = true;
     return true;
   }
   alert('Radio button not found');
   return false;"><br>
  <label for="lb1">  1-20: </label><input type="radio" name="rd1" 
id="lb1" value="20"><br>
  <label for="lb2">21-40: </label><input type="radio" name="rd1" 
id="lb2" value="40"><br>
  <label for="lb3">41-60: </label><input type="radio" name="rd1" 
id="lb3" value="60"><br>
  <label for="lb4">61-80: </label><input type="radio" name="rd1" 
id="lb4" value="80"><br>
  <label for="lb5">81-99: </label><input type="radio" name="rd1" 
id="lb5" value="99"></p>
</form>
Take care,
Dave Clark
www.DaveClarkConsulting.com
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
http://www.businessian.com
http://www.computerstan.com
http://www.financestan.com
http://www.healthstan.com
http://www.internetstan.com
http://www.moneyenews.com
http://www.technologystan.com
http://www.zobab.com
http://www.healthinhealth.com