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
Post a Comment