Solved

Numeric validation

Posted on 2004-08-10
4
9,206 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 30 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

What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

Question has a verified solution.

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

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
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…

718 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