Solved

java script to check is value is not empty

Posted on 2011-03-18
3
198 Views
Last Modified: 2012-06-22
I know nothing about java script other than its client side.  I want to modify a form so that if a user enters null values it highlights the form that wasnt entered and states something like what yahoo do see below

https://edit.europe.yahoo.com/registration?.intl=ie&.pd=ym_ver%253D0%2526c%253D%2526ivt%253D%2526sg%253D&new=1&.done=http%3A//mail.yahoo.com&.src=ym&.v=0&.u=amrr5ep6o6e9k&partner=&.partner=&pkg=&stepid=&.p=&promo=&.last=
0
Comment
Question by:enigma1234567890
3 Comments
 
LVL 40

Expert Comment

by:gurvinder372
ID: 35164388
try this
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
	<script>
		function checkIfEmpty()
		{
			if( document.getElementById("text1").value.length == 0)
			{
				alert("enter something here");
			}
		}
	</script>
</HEAD>

<BODY>
	<input type="text" id="text1"/>

	<input type="button" value="submit" onclick="checkIfEmpty()"/>
</BODY>
</HTML>

Open in new window

0
 

Accepted Solution

by:
pnpatne earned 250 total points
ID: 35164537
This is what you are looking for:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
      <script>
            function checkIfEmpty()
            {
                  if( document.getElementById("text1").value.length == 0)
                  {
                        document.getElementById('error').style.display="block";
                  }
            }
      </script>
      <style type="text/css">
            .text1
            {
                  color:red;
            }
      </style>
</HEAD>

<BODY>
      <p>
      Text1 :  <input type="text" id="text1"/>
      <label id="error" class="text1" style="display:none;">Text1 is required.</label>
      </p>
<br>
      <input type="button" value="submit" onclick="checkIfEmpty()"/>
</BODY>
</HTML>
0
 
LVL 7

Assisted Solution

by:foobarr
foobarr earned 250 total points
ID: 35183277
to slightly modify the above code

if (document.getElementById("text") == null)
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Suggested Solutions

A safe way to clean winsxs folder from your windows server 2008 R2 editions
Owning a franchise can be the dream of a lifetime. It provides a chance for economic growth. You can be as successful as you want.  To make your franchise successful, you need to market it successfully. Here are six of the best marketing strategies …
This video discusses moving either the default database or any database to a new volume.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now