Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
| Search | Today's Posts | Mark Forums Read
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 24th, 2005, 07:15 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default JavaScript form field validation error issue

This is my JavaScript Validation function:

Code:

function check(df)
{
    for (n=0;n<document.form.elements.length-1;n++)
    {
         if(form.elements[n].name.indexOf("invoiceNo")!=-1)//&&(form.elements[n].value==""))
       {
       var flag
       var flag="false"
        var valid="abcdefghijklmnopqrstuvwxyz ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            for(i=0;i<form.elements[n].value.length;i++)
            {
                if(valid.indexOf(form.elements[n].value.charAt(i))==-1)
                {
                    flag="true"
                    alert("Invalid character in Invoice No.")
                    form.elements[n].focus();
                    form.elements[n].select();
                    return false;
                    break;
                }
            }

        }
    }
}

this is my HTML form:


Code:

<form action="conf_invoice2.asp" method="post" name="form">
<input type="hidden" name="pnrno" value="<%=pnrno%>">
<table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <td width="16"><img src="images/top_lefbb.gif" width="16" height="16"></td>
    <td height="16" background="images/top_midbb.gif"><img src="images/top_midbb.gif" width="16" height="16"></td>
    <td width="24"><img src="images/top_rigbb.gif" width="24" height="16"></td>
  </tr>
  <tr>
    <td width="16" background="images/cen_lef.gif"><img src="images/cen_lef.gif" width="16" height="11"></td>
    <td align="center" valign="middle" bgcolor="#FFFFFF">

<table width="100%" border="1" bordercolor="#000000" bgcolor="#dcdcdc">
  <tr bordercolor="#FFFFFF" bgcolor="#006699">
    <td colspan="2"><div align="center">You have selected to Invoice Booking no <%=pnrno%></div></td>
    </tr>
  <tr bordercolor="#DCDCDC">
    <td width="42%"><div align="right">Invoice No </div></td>
    <td><div align="left"><input type="text" name="invoiceNo" STYLE="color: black; font: 8pt Verdana, Arial, Helvetica, sans-serif;" onKeyUp="return check();">
    </div></td>
    </tr>
  <tr bordercolor="#DCDCDC">
    <td colspan="2"><div align="center">Please confirm your selection </div></td>
    </tr>
  <tr bordercolor="#DCDCDC" bgcolor="#DCDCDC">
    <td colspan="2"><table width="100%" border="1" bordercolor="#DCDCDC">
      <tr bordercolor="#FFFFFF" bgcolor="#006699">
        <td width="50%" align="center" bgcolor="#006699" onclick="javascript:history.go(-1)" onMouseOver="this.bgColor = '#C0C0C0'; this.style.color='#000000'; style.cursor='hand'" onMouseOut ="this.bgColor = '#006699'; this.style.color='#FFFFFF'">
            Back</td>
        <td width="50%" align="center" valign="bottom" bgcolor="#006699" onMouseOver="this.bgColor = '#C0C0C0'; this.style.color='#000000'; style.cursor='hand'" onMouseOut ="this.bgColor = '#006699'; this.style.color='#FFFFFF'">
          <a href="javascript: document.forms[0].submit()"><img name="Submit" src="images/submit.gif" align="middle" border="0" onmouseover="Image_On();style.cursor='hand'" onMouseOut="Image_Off()" > </a> </td>
      </tr>
    </table></td>
    </tr>
</table>

    </td>
    <td width="24" background="images/cen_rigbb.gif"><img src="images/cen_rigbb.gif" width="24" height="11"></td>
  </tr>
  <tr>
    <td width="16" height="16"><img src="images/bot_lefbb.gif" width="16" height="16"></td>
    <td height="16" background="images/bot_midbb.gif"><img src="images/bot_midbb.gif" width="16" height="16"></td>
    <td width="24" height="16"><img src="images/bot_rigbb.gif" width="24" height="16"></td>
  </tr>
</table>
</form>

How do i allow only Numbers and - to be inserted into the textbox?


Code:

<input type="text" name="invoiceNo" STYLE="color: black; font: 8pt Verdana, Arial, Helvetica, sans-serif;" onKeyUp="return check();">

TIA>

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
__________________
_______________________
Ayrshire Minis - a Mini E-Community
http://www.ayrshireminis.com
http://www.crmpicco.co.uk
 
Old June 24th, 2005, 07:34 AM
Authorized User
 
Join Date: Feb 2005
Location: Havana, , Cuba.
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deniscuba
Default

try this:

function check(df)
{
    for (n=0;n<document.form.elements.length-1;n++)
    {
         if(form.elements[n].name.indexOf("invoiceNo")!=-1)//&& (form.elements[n].value==""))
       {
        if(!isNumericValue(form.elements[n].value)){
            alert("Invalid character in Invoice No.")
            return false;
           }
        return true;
         }
    }
}
function isNumericValue(value)
{
  return (value.match(/^\d+$/)!= null);
}

 
Old June 29th, 2005, 08:39 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

regards, denis!


www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
 
Old July 4th, 2005, 07:08 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Code:
alert ("AGE = " diff);
How do i put a marker inside this alert?
diff is a variable (integer)

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt
 
Old July 4th, 2005, 10:10 AM
Friend of Wrox
Points: 8,019, Level: 38
Points: 8,019, Level: 38 Points: 8,019, Level: 38 Points: 8,019, Level: 38
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2005
Location: Mauchline, East Ayrshire, Scotland
Posts: 1,525
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to crmpicco Send a message via AIM to crmpicco Send a message via MSN to crmpicco Send a message via Yahoo to crmpicco
Default

Code:
alert ("CHD Counter = " + chdcounter);
        alert ("INF Counter = " + infcounter);
        if((chdcounter!=0)&&(infcounter!=0))
        {
            chdpaxno = Math.floor(under12counter) + Math.floor(chdcounter);
            infpaxno = Math.floor(under2counter) + Math.floor(infcounter);
            alert("Please check the Date of Birth for Child number" + chdpaxno "\n Please check the Date of Birth for Infant number" + infpaxno);
        }

        if((chdcounter!=0)&&(infcounter==0))
        {
            chdpaxno = Math.floor(under12counter) + Math.floor(chdcounter);
            alert("Please check the Date of Birth for Child number" + chdpaxno);
        }

        if((infcounter!=0)&&(chdcounter==0))
        {
            infpaxno = Math.floor(under2counter) + Math.floor(infcounter);
            alert("Please Check the Date of births of pax");
        }
can anyone see what is wrong with this code?

www.crmpicco.co.uk
www.crmpicco.co.uk.tt
www.milklemonadechocolate.uk.tt
www.griswolds.uk.tt
www.piccosmini.co.uk.tt
www.morton.uk.tt




Similar Threads
Thread Thread Starter Forum Replies Last Post
Standalone validation + web form validation morbo Struts 0 August 19th, 2008 04:02 AM
Javascript error: form.elements[...]..... mars123 Javascript How-To 0 November 28th, 2007 02:37 AM
Field Array Validation in Javascript Asad Khan Apache Tomcat 1 September 4th, 2007 06:14 AM
Javascript validation error in asp.net shoakat ASP.NET 2.0 Professional 0 August 15th, 2007 11:53 AM
Error in form validation using "this" keyword danielh Javascript How-To 8 June 2nd, 2004 05:00 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.