473,811 Members | 2,979 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

javascript working in mozilla validating only one field

28 New Member
Hi,

this is my javascript validating the fields in mozilla FF but its working and validating only one field.

how to write the and how to works the script ............... ...

Expand|Select|Wrap|Line Numbers
  1. function Test(){
  2.  
  3.  
  4.  alphaNumericInput(document.forms[0].dealerid);
  5.  
  6.  digitsAlphabetsInput(document.forms[0].dealerid); //for digits only
  7.  alphabetsInput( document.forms[0].dealerid);//only alpha bets
  8.  
  9.   }
  10.  
  11.  function digitsInput(textField){
  12.  var regExp=/^[0-9]*$/;
  13.  if(textField.value=="" || regExp.test(textField.value)) 
  14.   return false;
  15.  
  16.  alert("Only digits are allowed!");
  17.  textField.value = textField.value.replace(/[^0-9]/g,"");
  18.  }
  19.  function alphabetsInput(textField){
  20.  var regExp=/^[a-z A-Z]*$/;
  21.  if(textField.value=="" || regExp.test(textField.value)) 
  22.   return;
  23.  
  24.  alert("Only alphabets symbols are allowed!");
  25.  textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
  26. }
  27.  var regExp=/^[0-9\a-z A-Z]*$/;
  28.  textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
  29.  
  30. function digitsAlphabetsInput(textField){
  31.  var regExp=/^[0-9\a-z A-Z]*$/;
  32.  if(textField.value=="" || regExp.test(textField.value)) 
  33.   return;
  34.  
  35.  alert("Only digits and alphabets are allowed!");
  36.  textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
  37. }
  38.  
  39.  
  40.  
Thanks

ss.
Jul 20 '07 #1
16 1967
pbmods
5,821 Recognized Expert Expert
Heya, SS.

In test(), you're passing the same form element each time. Is this intentional?
Jul 20 '07 #2
shyamg
28 New Member
Expand|Select|Wrap|Line Numbers
  1.  function Test(){
  2.  
  3.  
  4.  alphaNumericInput(document.forms[0].dealerid);
  5.  
  6.  alphabetsInput(document.forms[0].name);
  7.  alphabetsInput( document.forms[0].lname);
  8.  
  9.   }
  10.  
  11.  function digitsInput(textField){
  12.  var regExp=/^[0-9]*$/;
  13.  if(textField.value=="" || regExp.test(textField.value)) 
  14.   return false;
  15.  
  16.  alert("Only digits are allowed!");
  17.  textField.value = textField.value.replace(/[^0-9]/g,"");
  18.  }
  19.  function alphabetsInput(textField){
  20.  var regExp=/^[a-z A-Z]*$/;
  21.  if(textField.value=="" || regExp.test(textField.value)) 
  22.   return;
  23.  
  24.  alert("Only alphabets symbols are allowed!");
  25.  textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
  26. }
  27.  var regExp=/^[0-9\a-z A-Z]*$/;
  28.  textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
  29.  
  30. function digitsAlphabetsInput(textField){
  31.  var regExp=/^[0-9\a-z A-Z]*$/;
  32.  if(textField.value=="" || regExp.test(textField.value)) 
  33.   return;
  34.  
  35.  alert("Only digits and alphabets are allowed!");
  36.  textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
  37. }
  38.  
  39.  
i am passing differet values through the Body Onload. but it is checking only one first one. The above given is some of my sample code.
Jul 20 '07 #3
pbmods
5,821 Recognized Expert Expert
Heya, SS.

You did not declare a function named alphaNumericInp ut(). Did you mean digitsAlphabets Input()?
Jul 20 '07 #4
gits
5,390 Recognized Expert Moderator Expert
hi ...

please have a close look at your script and the comments that i made within:

Expand|Select|Wrap|Line Numbers
  1. function Test(){
  2.     // like pbmods said ... the following function is not declared
  3.     // and in your initial post all fields where 'dealerid' ... 
  4.     alphaNumericInput(document.forms[0].dealerid);
  5.  
  6.     alphabetsInput(document.forms[0].name);
  7.     alphabetsInput(document.forms[0].lname);
  8. }
  9.  
  10. function digitsInput(textField){
  11.     var regExp=/^[0-9]*$/;
  12.  
  13.     if(textField.value=="" || regExp.test(textField.value)) return false;
  14.  
  15.     alert("Only digits are allowed!");
  16.  
  17.     textField.value = textField.value.replace(/[^0-9]/g,"");
  18. }
  19.  
  20. function alphabetsInput(textField){
  21.     var regExp=/^[a-z A-Z]*$/;
  22.  
  23.     if(textField.value=="" || regExp.test(textField.value)) return;
  24.  
  25.     alert("Only alphabets symbols are allowed!");
  26.  
  27.     textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
  28. }
  29.  
  30. // the following two lines are useless i think ... they are executed 
  31. // during load and assign an regEx that is never used and
  32. // should give an error since textField is undefined here
  33. var regExp=/^[0-9\a-z A-Z]*$/;
  34.  
  35. textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
  36.  
  37. function digitsAlphabetsInput(textField){
  38.     var regExp=/^[0-9\a-z A-Z]*$/;
  39.  
  40.     if(textField.value=="" || regExp.test(textField.value)) return;
  41.  
  42.     alert("Only digits and alphabets are allowed!");
  43.  
  44.     textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
  45. }
  46.  
fixing the function-name in the test-function should do the job. and a strict way to write down the code with strict indentation will help you a lot when searching matching brackets or useless lines of code ... delete them since they produce an error in our actual case ...

kind regards
Jul 20 '07 #5
shyamg
28 New Member
hi ...

please have a close look at your script and the comments that i made within:

Expand|Select|Wrap|Line Numbers
  1. function Test(){
  2.        alphaNumericInput(document.forms[0].dealerid);
  3.  
  4.     alphabetsInput(document.forms[0].name);
  5.     alphabetsInput(document.forms[0].lname);
  6. }
  7.  
  8. function digitsInput(textField){
  9.     var regExp=/^[0-9]*$/;
  10.  
  11.     if(textField.value=="" || regExp.test(textField.value)) return false;
  12.  
  13.     alert("Only digits are allowed!");
  14.  
  15.     textField.value = textField.value.replace(/[^0-9]/g,"");
  16. }
  17.  
  18. function alphabetsInput(textField){
  19.     var regExp=/^[a-z A-Z]*$/;
  20.  
  21.     if(textField.value=="" || regExp.test(textField.value)) return;
  22.  
  23.     alert("Only alphabets symbols are allowed!");
  24.  
  25.     textField.value = textField.value.replace(/[^a-z A-Z]/g,"");
  26. }
  27.  
  28. function digitsAlphabetsInput(textField){
  29.     var regExp=/^[0-9\a-z A-Z]*$/;
  30.  
  31.     if(textField.value=="" || regExp.test(textField.value)) return;
  32.  
  33.     alert("Only digits and alphabets are allowed!");
  34.  
  35.     textField.value = textField.value.replace(/[^0-9\a-z A-Z]/g,"");
  36. }
  37.  
i removied that two lins also iam still geting same proble .now its not validating any field.


ss
Jul 20 '07 #6
gits
5,390 Recognized Expert Moderator Expert
;) you missed the first comment, and pbmods mentioned it too:

Expand|Select|Wrap|Line Numbers
  1. function Test(){
  2.     // there is no function called alphaNumericInput declared in your script
  3.     // you will get an error that alphaNumericInput is not a function
  4.     alphaNumericInput(document.forms[0].dealerid);
  5.     alphabetsInput(document.forms[0].name);
  6.     alphabetsInput(document.forms[0].lname);
  7. }
declare that function or use the correct name of the function you want to use ...

kind regards
Jul 20 '07 #7
shyamg
28 New Member
Expand|Select|Wrap|Line Numbers
  1. function Test(){
  2.         digitsInput(document.forms[0].dealerid);
  3.     alphabetsInput(document.forms[0].name);
  4.     alphabetsInput(document.forms[0].lname);
  5. }
iam using like this also not working do u know any validation script urls plz send that urls . ok
TQ

kind regards
Jul 20 '07 #8
gits
5,390 Recognized Expert Moderator Expert
... that's really confusing now, the following example works and uses all the code you provided ...

[HTML]<html>
<head>
<script>
function Test(){
digitsInput(doc ument.forms[0].dealerid);
alphabetsInput( document.forms[0].name);
alphabetsInput( document.forms[0].lname);
}

function digitsInput(tex tField){
var regExp=/^[0-9]*$/;

if(textField.va lue=="" || regExp.test(tex tField.value))r eturn false;

alert("Only digits are allowed!");
textField.value = textField.value .replace(/[^0-9]/g,"");
}

function alphabetsInput( textField){
var regExp=/^[a-z A-Z]*$/;

if(textField.va lue=="" || regExp.test(tex tField.value)) return;

alert("Only alphabets symbols are allowed!");

textField.value = textField.value .replace(/[^a-z A-Z]/g,"");
}

function digitsAlphabets Input(textField ){
var regExp=/^[0-9\a-z A-Z]*$/;

if(textField.va lue=="" || regExp.test(tex tField.value)) return;

alert("Only digits and alphabets are allowed!");

textField.value = textField.value .replace(/[^0-9\a-z A-Z]/g,"");
}
</script>
</head>
<body>
<form name="my_form">
<input type="text" name="dealerid"/>
<input type="text" name="name"/>
<input type="text" name="lname"/>
<input type="button" value="Validate " onclick="Test() ;"/>
</form>
</body>
</html>
[/HTML]

have a look at the firefox-javascript-console ... there has to be another error besides the one we found already ... how do you call Test();?

kind regards
Jul 20 '07 #9
gits
5,390 Recognized Expert Moderator Expert
... or another guess ... how should it work? may be it works for us but you want it to work another way? ...
Jul 20 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

12
6564
by: Kevin Lyons | last post by:
Hello, I am trying to get my select options (courses) passed correctly from the following URL: http://www.dslextreme.com/users/kevinlyons/selectBoxes.html I am having difficulty getting the courses to pass the correct option value and then be displayed at the following URL: http://www.dslextreme.com/users/kevinlyons/selectResults.html I am passing countries, products, and courses. The first two display
1
2712
by: lawrence | last post by:
This PHP function prints out a bunch of Javascript (as you can see). This is all part of the open source weblog software of PDS (www.publicdomainsoftware.org). We had this javascript stuff working, but it only worked for IE. You can see a working version here: http://www.publicpen.com/designer/mcControlPanel.php username: designer password: designer123 However, I've tried to rewrite this so it would work in all browsers,
10
4608
by: VictorG | last post by:
Hello, I am new to JS and am trying to add some HTML into a JS function. So that when called the script as well as the HTML will be invoked. Is there some type of embed mechanism, sort of the reverse of embedding JS in an html page with the script tag. (which is what I am doing in this case) Is this even possible?
8
3681
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
0
10644
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10127
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9201
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6882
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4336
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3863
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3015
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.