Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Javascript General Javascript discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 28th, 2003, 02:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default onClick event problem

There is error in onClick event.
How can check multiple record a to z value if datatype is numeric, if user inter character value
It should gives message that “ enter Numeric value “

<head>
<script language=JavaScript>
function docheck()
{
for (i=0;i<=10;++i)
 {
 x=document.forms[0].elements[i].value
 n=document.forms[0].elements[i].name

   if (i==0)
  {
  fn=document.forms[0].elements[i].value
    if (fn=="a,b,c,d,e,f.,,,,,,,,,,,………..") // a to z
   {
   alert ("Please enter Numeric Value ")
   document.forms[0].elements[i].focus()
   return false;
   }
  }
}
}
document.myform.submit()
}
</script>
</head>

<input type=submit value="show drawings" onClick=”docheck()”>

Mateen
Reply With Quote
  #2 (permalink)  
Old July 28th, 2003, 03:52 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

regular expressions are the way to go with this sort of thing, try
Code:
if ( /[^0-9]/.test(fn) ) { alert ("Please enter Numeric Value "); ... }
that will check whether the field contains any non-numeric characters, but it won't check for empty field, but this will:
Code:
if (!(/^\d+$/.test(fn)) ) { alert ("Please enter Numeric Value ");  }
Do you want to allow decimals, example 12.75?

rgds
Phil
Reply With Quote
  #3 (permalink)  
Old July 28th, 2003, 06:54 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks.

yes, it will more better to check decimals
boths example, allow and not allow, how ?

Mateen


Quote:
quote:Originally posted by pgtips
 regular expressions are the way to go with this sort of thing, try
Code:
if ( /[^0-9]/.test(fn) ) { alert ("Please enter Numeric Value "); ... }
that will check whether the field contains any non-numeric characters, but it won't check for empty field, but this will:
Code:
if (!(/^\d+$/.test(fn)) ) { alert ("Please enter Numeric Value ");  }
Do you want to allow decimals, example 12.75?

rgds
Phil
Reply With Quote
  #4 (permalink)  
Old July 29th, 2003, 02:34 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

if non numeric value inter it is give alert message that enter numeric value but it is not focus on it. But it move to next page why ?

document.forms[0].elements[i].focus() not working .

how can stop to move it to next page ?
I am using <input type=submit value=show >

Mateen


Quote:
quote:Originally posted by pgtips
 regular expressions are the way to go with this sort of thing, try
Code:
if ( /[^0-9]/.test(fn) ) { alert ("Please enter Numeric Value "); ... }
that will check whether the field contains any non-numeric characters, but it won't check for empty field, but this will:
Code:
if (!(/^\d+$/.test(fn)) ) { alert ("Please enter Numeric Value ");  }
Do you want to allow decimals, example 12.75?

rgds
Phil
Reply With Quote
  #5 (permalink)  
Old July 29th, 2003, 03:59 AM
Authorized User
 
Join Date: Jun 2003
Location: Quezon City, MM, Philippines.
Posts: 97
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to planeswalk
Default

Hi,

This is because you have document.myform.submit() after the regular expressions code block. The first thing that you need to do is remove that line from the javascript. Then type onSubmit="return doCheck()" as an attribute in your <form> tag (you have to have this) and remove the onClick attribute from the button. This will force your HTML form to do the expression check when you submit the form and will not submit the page if the check fails.

Cheers!
Marlon
Reply With Quote
  #6 (permalink)  
Old July 29th, 2003, 04:07 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

Try this regexp for validating decimals:
Code:
if (!(/^\d+\.?\d*$/.test(fn)) ) { alert ("Please enter Numeric Value ");  }
Reply With Quote
  #7 (permalink)  
Old July 30th, 2003, 12:25 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for response.
I amend the coding,but it is move to next page.
it is not stop that field.
I remove onClick attribute from the button.
Please check coding
<head>
<script language=JavaScript>
function doCheck()
{
for (i=0;i<=1;++i)
 {
 fx=document.forms[0].elements[i].value
 fn=document.forms[0].elements[i].name
   if (i==0)
  {
  fn=document.forms[0].elements[i].value
    if ( /[^0-9]/.test(fn) )
   {
   alert ("Please enter Numeric Value ")
   onSubmit="return doCheck()"
   return false;
   }
  }
}
document.myform.submit()
}
</script>
</head>




Quote:
quote:Originally posted by planeswalk
 Hi,

This is because you have document.myform.submit() after the regular expressions code block. The first thing that you need to do is remove that line from the javascript. Then type onSubmit="return doCheck()" as an attribute in your <form> tag (you have to have this) and remove the onClick attribute from the button. This will force your HTML form to do the expression check when you submit the form and will not submit the page if the check fails.

Cheers!
Marlon

Reply With Quote
  #8 (permalink)  
Old July 31st, 2003, 02:29 AM
Registered User
 
Join Date: Jul 2003
Location: Athens, , Greece.
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

my friend the line onsubmit=....... MUST be placed in the <input type='submit'.....> of your HTML Code.

regards
Chris...

Quote:
quote:Originally posted by mateenmohd
 thanks for response.
I amend the coding,but it is move to next page.
it is not stop that field.
I remove onClick attribute from the button.
Please check coding
<head>
<script language=JavaScript>
function doCheck()
{
for (i=0;i<=1;++i)
{
fx=document.forms[0].elements[i].value
fn=document.forms[0].elements[i].name
if (i==0)
{
fn=document.forms[0].elements[i].value
    if ( /[^0-9]/.test(fn) )
{
alert ("Please enter Numeric Value ")
onSubmit="return doCheck()"
return false;
}
}
}
document.myform.submit()
}
</script>
</head>




Quote:
quote:Originally posted by planeswalk
 Hi,

This is because you have document.myform.submit() after the regular expressions code block. The first thing that you need to do is remove that line from the javascript. Then type onSubmit="return doCheck()" as an attribute in your <form> tag (you have to have this) and remove the onClick attribute from the button. This will force your HTML form to do the expression check when you submit the form and will not submit the page if the check fails.

Cheers!
Marlon

Reply With Quote
  #9 (permalink)  
Old August 2nd, 2003, 05:16 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: abu dbabi, , United Arab Emirates.
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks you for your help.

regards.

Quote:
quote:Originally posted by cpap
 my friend the line onsubmit=....... MUST be placed in the <input type='submit'.....> of your HTML Code.

regards
Chris...

Quote:
quote:Originally posted by mateenmohd
 thanks for response.
I amend the coding,but it is move to next page.
it is not stop that field.
I remove onClick attribute from the button.
Please check coding
<head>
<script language=JavaScript>
function doCheck()
{
for (i=0;i<=1;++i)
{
fx=document.forms[0].elements[i].value
fn=document.forms[0].elements[i].name
if (i==0)
{
fn=document.forms[0].elements[i].value
    if ( /[^0-9]/.test(fn) )
{
alert ("Please enter Numeric Value ")
onSubmit="return doCheck()"
return false;
}
}
}
document.myform.submit()
}
</script>
</head>




Quote:
quote:Originally posted by planeswalk
 Hi,

This is because you have document.myform.submit() after the regular expressions code block. The first thing that you need to do is remove that line from the javascript. Then type onSubmit="return doCheck()" as an attribute in your <form> tag (you have to have this) and remove the onClick attribute from the button. This will force your HTML form to do the expression check when you submit the form and will not submit the page if the check fails.

Cheers!
Marlon

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Weird problem with dropdown onclick event in IE 7. tovipul21 Classic ASP Basics 1 September 7th, 2007 01:15 PM
CheckBox onClick event sams ASP.NET 1.0 and 1.1 Professional 3 August 29th, 2007 03:02 AM
onclick event bjackman Access 6 July 15th, 2004 06:54 AM
onclick event pigtail Javascript 1 April 11th, 2004 03:10 PM
onClick Event mateenmohd Javascript 4 December 16th, 2003 01:08 AM



All times are GMT -4. The time now is 09:16 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.