Want to prevent a textbox from becoming empty with javascript -


so have textbox in can enter numbers , have within range.the textbox defaults 1,and want stop user being able make blank.any ideas guys?cheers

                    <script language=javascript>         window.addeventlistener("load", function () {         document.getelementbyid("quantity").addeventlistener("keyup", function (evt) {             var target = evt.target;               target.value = target.value.replace(/[^\d]/, "");               if (parseint(target.value, 10) > <%=dvd5.getquantityinstock()%>) {                 target.value = target.value.slice(0, target.value.length - 1);            }         }, false);               });                  <form action="regservlet"  method="post"><p>enter quantity  purchase : <input name="quantity" id="quantity" size=15 type="text" value="1" /> 

you use onkeyup listener check if input's value empty. along lines of:

if(target.value == null || target.value === "")     target.value = 1; } 

Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -