javascript - Mandatory fields and selecting drop down list values -


basically, have 2 fields, 1 selection (drop down) list , other input textbox, both different question's.

my question is, if choose only one value in selection list (first question), textbox (second question) must 6 characters or numbers in length. otherwise, other values chosen in selection list can 10 characters long in textbox.

how can write in javascript form without use of regex , within ?

i have written parts of script see how others can write it. sole problem rest of other values 10 characters long.

i'd add first question not need selection list. made way html more presentable , organised.

this script (so far):

function imposemaxlength(object, limit) {     var num = document.getelementbyid("number").value;     if (num == "3") {     document.getelementbyid("type").value  {     return (object.value.length <= limit);     }   } } 

html:

<label for="number">number:</label>    <select size="1" id="number">    <option disabled>...</option>    <option value="1">1</option>    <option value="2">2</option>    <option value="3">3</option>    <option value="4">4</option>    <option value="5">5</option>    <option value="6">6</option>    <option value="7">7</option>    <option value="8">8</option>  </select>  <br>type:<input type="text" id="type" onkeypress="return imposemaxlength(this,6);"><br>  <input type="button" value="submit"/> 

please help.

i think need this

<script>    $('#number').on('change', function () {       var value=this.value;       if(value==1)         {             $("#type").attr('maxlength','6');         }       else         {             $("#type").attr('maxlength','10');         }    }); </script> 

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -