Solved

java script to check is value is not empty

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reorder multi file names 17 69
Sorting tables using javascript 9 84
jquery toggle display styling 5 96
Javascript Urgent help (Need help to disable event handler) 8 45
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Riverbed Technology's webinar discusses networking for the cloud era with simplified SD-WAN cloud connectivity.
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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