Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

java script to check is value is not empty

Posted on 2011-03-18
3
Medium Priority
?
204 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:Gurvinder Pal Singh
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 1000 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 1000 total points
ID: 35183277
to slightly modify the above code

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

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

The online market is growing at an unprecedented rate and retail eCommerce sales are expected to reach $4 trillion by 2020. Yet, the profit is not just there for the taking because you have to set yourself apart from the competition.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

670 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