Solved

java script to check is value is not empty

Posted on 2011-03-18
3
200 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Datepicker 3 229
Expand and Collapse Tree Grid 11 536
Need some javascript help with form event attachment 6 140
Certifications for javascript,html and css 2 151
One of the biggest threats in the cyber realm pertains to advanced persistent threats (APTs). This paper is a compare and contrast of Russian and Chinese APT's.
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

816 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

8 Experts available now in Live!

Get 1:1 Help Now