473,406 Members | 2,273 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,406 software developers and data experts.

javascript validation

vikas1111
122 100+
Hi All..
From 2 days i am learning javascript.. I have written a very basic code to accept a name and a submit boutton.. But my program is not running.. I am working in dreameweaver mx.. My problem is that when enter name and press submit boutton the name in the text box vanishes away.. and if i press submit button without entering any data no error message occurs .. can anyone help me to solve my problem pls ???
Mar 13 '08 #1
9 925
gits
5,390 Expert Mod 4TB
please show your code ...

kind regards
Mar 13 '08 #2
vikas1111
122 100+
since i am not sure about my code so i am pasting all the lines without editing...

Expand|Select|Wrap|Line Numbers
  1.  
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html>
  4. <head>
  5. <title>test Document</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  7. <script language="JavaScript" type="text/javascript">
  8. <!--
  9.   function validt()
  10.    { 
  11.     valid=true;
  12.       if(document.form1.txtname.value=="")
  13.          { alert("srtreter");
  14.             valid=false;
  15.            document.form1.txtname.focus();
  16.          }
  17.               else{valid=true;}
  18.               return valid:
  19.           }
  20.        //-->
  21. </script> 
  22. </head>
  23.  
  24. <body>
  25. <form name="form1" method="post" action="" onSubmit="return validt();">
  26. <p>Name 
  27.     <input type="text" name="txtname">
  28. </p>
  29. <p>
  30.   <input type="submit" name="Submit" value="Submit">
  31. </p>
  32. </form>
  33. </body>
  34. </html>
  35.  
  36.  
Mar 13 '08 #3
gits
5,390 Expert Mod 4TB
try the following:

Expand|Select|Wrap|Line Numbers
  1. function validt() {
  2.     var node  = document.form1.txtname;
  3.     var valid = node.value != '';
  4.  
  5.     if (!valid) {
  6.         alert('srtreter');
  7.         node.focus();
  8.     }
  9.  
  10.     return valid:
  11. }
  12.  
Mar 13 '08 #4
vikas1111
122 100+
No its not working..No message appears when i press submit button without entering data into text box...
Mar 13 '08 #5
gits
5,390 Expert Mod 4TB
sorry i copied your typo:

Expand|Select|Wrap|Line Numbers
  1. return valid:
MUST be:

Expand|Select|Wrap|Line Numbers
  1. return valid;
of course.

kind regards
Mar 13 '08 #6
RamananKalirajan
608 512MB
sorry i copied your typo:

Expand|Select|Wrap|Line Numbers
  1. return valid:
MUST be:

Expand|Select|Wrap|Line Numbers
  1. return valid;
of course.

kind regards

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <script language="javascript">
  4. function validThis()
  5. {
  6.   var x = document.getElementById('textval');
  7.   if(x.value=="")
  8.    {
  9.    alert("Missing");
  10.    return false;
  11.   }
  12.  return true;
  13. }
  14. </script>
  15. </head>
  16. <body>
  17. <input type="text" name="textval" id="textval"><br/>
  18. <input type="submit" value="submit" onclick="return validThis()">
  19. </body>
  20. </html>
Hello Friend use this code it will be useful. In most cases please use the ID instead of names that will be very useful for you

Regards
Ramanan Kalirajan
Mar 13 '08 #7
Hai This is Javascript Code


1 <html>

2. <head>

3. <script language="javascript">

4. function check()

5. {

6. var reddy = document.getElementById('textval').value;


7. if(reddy.value=="")

8. {

9. alert("Please provide some things");

10. return false;

11. }


12. return true;


13. }

14. </script>


15. </head>

16. <body>

17. <input type="text" name="textval" id="textval"><br/>

18. <input type="submit" value="submit" onClick="return check()">

19. </body>

20. </html>
Mar 13 '08 #8
vikas1111
122 100+
Hai This is Javascript Code


1 <html>

2. <head>

3. <script language="javascript">

4. function check()

5. {

6. var reddy = document.getElementById('textval').value;


7. if(reddy.value=="")

8. {

9. alert("Please provide some things");

10. return false;

11. }


12. return true;


13. }

14. </script>


15. </head>

16. <body>

17. <input type="text" name="textval" id="textval"><br/>

18. <input type="submit" value="submit" onClick="return check()">

19. </body>

20. </html>


Hi still it isnt working
Mar 14 '08 #9
gits
5,390 Expert Mod 4TB
hi ...

just use the code i provided above and fix the return as i stated in post #6 ... it will work :)

kind regards
Mar 14 '08 #10

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

Similar topics

5
by: Sue | last post by:
After finishing up my first quarter JavaScript on 12/12/03, I decided to improve character checking on my project. In my project I only had to do very basic validation. Therefore, I only had one...
9
by: tzigone | last post by:
hello, i use asp.net validation controls in my site. i wonder whether usin javascript validation will fasten page load speed? there are currently lots of requiredfieldvalidator now is it better t...
111
by: Retlak | last post by:
The recommended (on dozens of websites) and effective (works in Netscape, MSIE, Mozilla, probably others) way to detect if a browser has Javascript turned off is to put this in the <head>: ...
2
by: GIMME | last post by:
Background ... I've created a web application that allows a user to create an HTML application from IE. The application itself creates an XML representation of a XHTML form. The XHTML...
5
by: Allan M. | last post by:
I have a series of select boxes that must be populated client side, because they interact with each other. The design specification calls for these boxes to be updated without having to make a...
5
by: | last post by:
Hi all, Has anyone been able to write some custom javascript on the onclick event of submit button to do certain things like disable submit button, only submit form once etc. This was a breeze...
8
by: chrisdude911 | last post by:
how do i add video into a javascript web page with my own custom buttons?
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
6
by: Peter Afonin | last post by:
Hello, I'm creating an application in ASP.NET 1.1. I need to check whether at least one checkbox in my datagrid has been checked. To do this, I'm using Javascript - I'm adding this code to...
5
by: Peter Afonin | last post by:
Hello, I'm not an expert in Javascript, so I'm seeking an advice. As I mentioned in my previous post, I use Javascript to check whether at least one checkbox in the datagrid has been checked....
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.