473,386 Members | 1,835 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

How to determine if a DHTML text box is empty?

Provide me an If/Then statement to determine if a DHTML text box is empty and stop running code.
I required this immediately....i will be highly thankful!!!!!!
Mar 29 '10 #1
4 1789
phvfl
173 Expert 100+
I assume that the textbox is either a textarea or standard text input box. Get a reference to the textbox using getElementById or similar and then check the value property.
Mar 29 '10 #2
I am new to this. so i requested u to give me step by step explanation..please!!!!
Mar 29 '10 #3
phvfl
173 Expert 100+
OK. Assuming that the text box is either an text input or textarea with an id of "myBox", this would mean html similar to:
Expand|Select|Wrap|Line Numbers
  1. <!-- A text input -->
  2. <input type="text" id="myBox" value="" />
  3. <!-- or for a textarea -->
  4. <textarea id="myBox" cols="10" rows="3"></textarea>
  5.  
You would be able to get a reference to the element by using getElementById and then check its values:
Expand|Select|Wrap|Line Numbers
  1.   // Get a reference to the html element
  2.   var textbox = document.getElementById("myBox");
  3.  
  4.   // Ensure that the element was found
  5.   if(textbox !== null){
  6.     // Check the value - i.e. the text in the box.
  7.    if(textbox.value === ''){
  8.       //Textbox is empty so do something
  9.     }else{
  10.       //Textbox is not empty so do something else.
  11.     }
  12.   }
  13.  
If you are just learning JavaScript then w3schools is a good reference point - it also contains information for other web technologies. The site is at www.w3schools.com
Mar 29 '10 #4
Thank you so much for the help.I will try it out!!!
Mar 29 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris Leonard | last post by:
Hi. I've copied some code from a book which will enable me to make a layer around a page, my aim is to do something a little more complex but this I thought would get me started. Anyway, I've...
18
by: Christopher W. Douglas | last post by:
I am writing a VB.NET application in Visual Studio 2003. I have written a method that handles several events, such as closing a form and changing the visible status of a form. I have some code...
7
by: Mike | last post by:
Hello, I am developing a simple web editor to enable my users to update their websites and add simple formatting to the text. The page content is recovered from a SQL Server database and...
0
by: Stuart Shay | last post by:
Hello All I have a ASP.NET 2.0 checkbox list, the problem is when 0 items are checked I am unable to determine if the list is empty //Determine Checked Roles CheckBoxList ckUserRoleList =...
20
by: cwdjrxyz | last post by:
There have been fancy dhtml text effects since the early days of javascript. The rainbow text effect was one of the early ones. While some such effects may be fun on private pages, they can easily...
4
by: Steve | last post by:
hi all, i'm using DHTML to generate a dynamic table with adding removing and sorting rows the thing is after a row has been added at a position that i specify, if i try to delete it i get this...
6
by: Mike | last post by:
I have a textbox were users can enter data, then they can delete it all and enter in new data again and click submit. Is there a way to determine if the user deleted the text they entered in? I'm...
9
by: ninhovid | last post by:
Hi... i'm new at dhtml, and i want to use it in help windows (instead of window.open() of javascript)... i'm done it... but it works only in internet explorer.. in firefox 2 and 3 it opens the...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.