?
Solved

Numeric validation

Posted on 2004-08-10
4
Medium Priority
?
9,207 Views
Last Modified: 2011-08-18
Hi,

The folloiwng code displays data in an asp form from database for updating purpose. I want to force user to enter a number (no decimals or negative or zeros) in the "QtyOut_<%=iLp%>" fields. Could anyone pls. help me?

Zero is allowed only if user selected the check boxes in the form "Del_<%=iLp%>".

          <%if not rst3.EOF then
               iLp = -1
               while not rst3.EOF
                    iLp = iLp + 1%>
                    <TR>
                         <TD width="40" height="1" align="center"><%=rst3.AbsolutePosition%></TD>
                         <TD width="150" height="1">
                              <INPUT name="PartNo_<%=iLp%>" ReadOnly value="<%=server.HTMLEncode(rst3("PartNo"))%>">
                         </TD>
                         <TD width="151" height="1">
                              <INPUT name="f_1_<%=iLp%>" value="<%=server.HTMLEncode(rst3("ProductName"))%>" readonly>
                         </TD>
                         <TD width="100" height="1">
                              <INPUT size=5 name="QtyOut_<%=iLp%>" value="<%=rst3("QtyOut")%>">
                              <input type="hidden" name="OldQtyOut_<%=iLp%>" value="<%=rst3("QtyOut")%>">
                              <input type="hidden" name="ROL_<%=iLp%>" value="<%=rst3("ROL")%>">
                         </TD>
                         <TD align="center">
                              <INPUT type="checkbox" name="Del_<%=iLp%>" value="True">
                              <INPUT type=hidden name="ID_<%=iLp%>" value="<%=rst3("ID")%>">
                         </TD>
                    </TR>
                    <%rst3.MoveNext
               Wend%>
               <tr>
                    <td colspan="5" align="right">
                         <input type="hidden" name="ItemCount" value="<%=iLp%>">
                         <input type="hidden" name="Action" value = "Update">
                    </td>
               </tr>
          <%end if%>

hafs.
0
Comment
Question by:ayha1999
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 13

Expert Comment

by:StormyWaters
ID: 11763667
Do you want the user to be able to type any character in the box and then it checks it on submit or do you want it to only allow 1-9 and maybe 0 in the box and all other characters don't work?
0
 
LVL 33

Accepted Solution

by:
knightEknight earned 120 total points
ID: 11763817
use this onblur event on your inputs:

<INPUT type="text" name="numeric" onblur='this.value=this.value.replace(/[^\d]*/gi,"");' />
0
 
LVL 16

Expert Comment

by:jaysolomon
ID: 11769597
<INPUT type="text" name="numeric" onblur="if(isNaN(this.value)){this.value = '';} />
0
 
LVL 7

Author Comment

by:ayha1999
ID: 11781401
Hi,

I want to force user to enter numeric values in the "QtyOut_<%=iLp%>" fields.

It should be something like this;

function mySubmit(obj)
{
     var theForm=obj.form;
     var p1=/^col1_/;
     var num=/^[1-9]\d*/;
     var oldCol1= new Array();
     for(var i=0;i<theForm.elements.length;i++)
     {
          if(p1.test(theForm.elements[i].name))
          {
               if(theForm.elements[i].value!="" && theForm.elements[i+1].value=="")
               {
                    alert("Please enter a valid quantity");
                    theForm.elements[i+1].focus();
                    return false;

But if user seletected <INPUT type="checkbox" name="Del_<%=iLp%>" value="True"> then 0 is allowed.

hafs
0

Featured Post

Want to be a Web Developer? Get Certified Today!

Enroll in the Certified Web Development Professional course package to learn HTML, Javascript, and PHP. Build a solid foundation to work toward your dream job!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question