Solved

Numeric validation

Posted on 2004-08-10
4
9,200 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
4 Comments
 
LVL 13

Expert Comment

by:StormyWaters
Comment Utility
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 30 total points
Comment Utility
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
Comment Utility
<INPUT type="text" name="numeric" onblur="if(isNaN(this.value)){this.value = '';} />
0
 
LVL 7

Author Comment

by:ayha1999
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now