bcode Posted October 8, 2009 Share Posted October 8, 2009 I am completely new to javascript but I am trying it works semi-good I added onKeyUp to my forms input and it works. I now need it when you press backspace to go delete and go to the previous input but I have onkeyup I started trying to get it to work with the second script in the code but I don't really know what I am doing. If you need more info let me know I really don't know how to ask this thank you for any help <script type="text/javascript"> var active_color = '#993300'; var inactive_color = '#993300'; window.onload = formDefaultValues; function formDefaultValues() { var fields = getElementsByClassName(document, "input", "default-value"); if (!fields) { return; } var default_values = new Array(); for (var i = 0; i < fields.length; i++) { fields[i].style.color = inactive_color; if (!default_values[fields[i].id]) { default_values[fields[i].id] = fields[i].value; } fields[i].onfocus = function() { if (this.value == default_values[this.id]) { this.value = ''; this.style.color = active_color; } this.onblur = function() { if (this.value == '') { this.style.color = inactive_color; this.value = default_values[this.id]; } } } } } function getElementsByClassName(oElm, strTagName, strClassName){ var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName); var arrReturnElements = new Array(); strClassName = strClassName.replace(/\-/g, "\\-"); var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)"); var oElement; for (var i = 0; i < arrElements.length; i++) { oElement = arrElements[i]; if (oRegExp.test(oElement.className)) { arrReturnElements.push(oElement); } } return (arrReturnElements); } </script> <script type='text/javascript'> var n=0 function x(){ if(event.keyCode==35){ n+=1 if (n==2)alert('2 x #') } } </script> <form action="" method="get"> <input id="1" name="zipcode1" onKeyUp="document.getElementById('2').focus()" onkeypress='x(event)' type="text" value="?" size="1" maxlength="1" class="default-value" /> <input id="2" name="zipcode2" onKeyUp="document.getElementById('3').focus()" onkeypress='x(event)' type="text" value="0" size="1" maxlength="1" class="default-value" /> <input id="3" name="zipcode3" onKeyUp="document.getElementById('4').focus()" type="text" value="0" size="1" maxlength="1" class="default-value" /> <input id="4" name="zipcode4" onKeyUp="document.getElementById('5').focus()" type="text" value="0" size="1" maxlength="1" class="default-value" /> <input id="5" name="zipcode5" type="text" value="0" size="1" maxlength="1" class="default-value" /> </form> Quote Link to comment Share on other sites More sharing options...
bcode Posted October 8, 2009 Author Share Posted October 8, 2009 here is a working sample http://code2pixels.com/testzip.html i need to be able to go backspaces Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.