How to do custom validation in JavaScript -


i have function works input prevent customers inputting p.o. box address field. input works has inline onkeypress event, input need run function on doesn't (and can't access it).

my question how incorporate correct event listener function runs on inaccessible input?

my js fiddle here: http://jsfiddle.net/zqqs9/4/

function killpobox(id) {    var idvalue = document.getelementbyid('v65-onepage-shipaddr1').value;	    if (id == 'v65-onepage-shipaddr1') {      function runval() {        if (idvalue.substr(0,4).touppercase() === "po b" || idvalue.substr(0,5) === "p.o. ") {          alert("usa light cannot ship p.o. boxes. please enter street address.");        }      }      setinterval(runval(),1);    }  }	
<!-- practice input works -->  1. <input type="text" class="quantity" name="v65-onepage-shipaddr1" id="v65-onepage-shipaddr1" onkeypress="killpobox(this.name)">	   <br>  <br>  <!-- actual input need hook into, cannot edit -->  2. <input type="text" size="25" maxlength="75" name="shipaddress1" id="v65-onepage-shipaddr1" value="" style="" onkeydown="">

you can use addeventlistener() method this:

document.getelementbyid('v65-onepage-shipaddr2').addeventlistener('keypress', killpobox('v65-onepage-shipaddr2')); 

i think first input incorrectly passing this.name argument killpobox() function. should passing this.id instead? may want replace 'v65-onepage-shipaddr1' in killpobox() function id use argument passed function.


Comments

Popular posts from this blog

java - Custom OutputStreamAppender not run: LOGBACK: No context given for <MYAPPENDER> -

java - UML - How would you draw a try catch in a sequence diagram? -

c++ - No viable overloaded operator for references a map -