Solved

java script to check is value is not empty

Posted on 2011-03-18
3
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
This video shows how to use Hyena, from SystemTools Software, to update 100 user accounts from an external text file. View in 1080p for best video quality.

752 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