473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

Has the user entered text in a numeric field

Hi Experts, my first post here! I hope you can help me.

I have a basic form which I want the user to enter either a number (postcode/zipcode) or text (suburb).

When they hit submit I want to check what has been entered and then send them to either a postcode/zip code page if it was a number entered or send them to a suburb page if it was text they entered.

Is this possible and if so how?

Thanks for your possible help.

Unkietee
Mar 8 '08 #1
8 6014
karthickkuchanur
156 100+
Hi Experts, my first post here! I hope you can help me.

I have a basic form which I want the user to enter either a number (postcode/zipcode) or text (suburb).

When they hit submit I want to check what has been entered and then send them to either a postcode/zip code page if it was a number entered or send them to a suburb page if it was text they entered.

Is this possible and if so how?

Thanks for your possible help.

Unkietee
call the function in while submit the button
check the condition in js whether it a number or an test ans link the page that u wnt to do
Note:NAN check
Mar 8 '08 #2
Thanks karthickkuchanur,

I understand the concept - I dont understand how to write it!

Do you have a sample I could look at?
Mar 8 '08 #3
acoder
16,027 Expert Mod 8TB
You could call the function onsubmit.

To change the page that the form is submitted to, use the action property to point to the correct URL.

Do you know how to test if it's an integer?
Mar 8 '08 #4
Thanks Acoder,

I am not 100% on how to check if its an integer. The code below is as close as I have got but it is not working - what am I doing wrong?


Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="Javascript">
  3.       function chk_val(obj) {
  4.  
  5.           var chk = /^\d+$/.test(obj.value);
  6.  
  7.  
  8.  
  9.           if (!chk) {
  10.  
  11.               location.href = 'SuburbSearch.php';
  12.  
  13.               obj.focus();
  14.  
  15.           }
  16.  
  17.       }
  18. </script>
  19. <body>
  20.  
  21. <h1>Start Here</h1>
  22.  
  23. <form action="PostcodeSearch.php" method="post">
  24.  
  25.  
  26. Enter Postcode:<br>
  27.  
  28. <input name="searchterm" type=text value="" onblur="chk_val(this);">
  29.  
  30. <br>
  31. </form>
  32.  
  33.  
Mar 9 '08 #5
acoder
16,027 Expert Mod 8TB
Instead of changing the location.href, change the form's action property and then call its submit() method.
Mar 9 '08 #6
Side Tip: You mentioned "post code" in addition to ZIP code in your original post, so if your application is targeting international, don't forget that British-derived postal codes contain text characters. (If not for international use, please ignore this post from the peanut gallery.)
Mar 9 '08 #7
Thanks FredSovenix,

I am only using postcodes of Australia but point taken.

Now to try acoders suggestion and see if I can get it to work.

Back soon!
Mar 9 '08 #8
Expand|Select|Wrap|Line Numbers
  1. function chk_val(i) {
  2.   var chk= parseInt(i);
  3.   if(chk==NaN) { return false; } else { return true; }
  4. };
  5.  
  6.  
  7. var n=  chk_val(userInput);
  8.  
  9. if(n) { 
  10. // allow user to do xyz
  11. } else {
  12. // not a number! do something else.
  13. }
Oct 27 '09 #9

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

Similar topics

1
by: Job Lot | last post by:
In a multi-user environment, how would I prevent users from adding Orders with identical OrderID. For instance I have following tables in my database Order ================== OrderID Identity...
2
by: sara | last post by:
I have a mess on my hands. I have a whole set of queries and reports (almost a whole app, really) that has "location" as a text field. Sometimes it's a number and a few times it's text (001, 002,...
2
by: brucedodds | last post by:
This post is for senior developers. I'm an Access contractor. This morning I see a listing for a position that seems to require development of a self-modifying database. The application may need...
5
by: V. Jenks | last post by:
Long story as short as possible: I have a page (aspx) that contains a user control (ascx). In the form the user can enter a username and password. If they do, the password box auto-posts-back...
4
by: steph | last post by:
Hello, I've got a text field in an access form (Microsoft Access 2002, SP3), that the user has to fill out. Now I don't want the user to leave this field (and this record) until he has filled...
1
by: steven scaife | last post by:
Hi I have created two user controls that are the basis of two forms. I havent included the form tag in the user controls. one of the controls accepts one input which is a numeric text field...
9
by: abprules | last post by:
Can somehow tell me the best way for multi user development to occur in MS Access? The situation is: We are creating a new database for a small company. There are 2 of us who want to...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
9
by: xian2 | last post by:
Hi All, I have been wroking on the databse for a while now and am on the stage of creating forms. I am trying to create a subform at the moment but am having some problems. I am using the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
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...
0
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...

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.