tags:

views:

32

answers:

4

i have a textbox in a jsp page

<td><label for="customer.fcDate" class="desc"><bean:message key="label.customer.fcDate" /></label></td>
            <td>
                <table><tbody><tr>
                        <td><input type="Text" name="customer.fcDate" id="customer.fcDate" style="customer.fcDate" class="SingleLineTextField" maxlength="10" size="15" tabindex="1" ></td>
                <td><a href="javascript:NewCal('customer.fcDate','mmddyyyy')"><img align="middle" src="Images/cal.jpg" width="20" height="20" border="0" alt="Pick a date"></a></td>

                </tr></tbody></table>
            </td>

now i want to check that the box must not be null using javascript. how to do it?

can you explain it little more?

     <td> <table>
 <tbody><tr> 
<td>
<input type="Text" name="customer.fcDate" id="customer.fcDate" style="customer.fcDate" class="SingleLineTextField" maxlength="10" size="15" tabindex="1" onblur="nullcheck()">
</td> 
<td><a href="javascript:NewCal('customer.fcDate','mmddyyyy')">
<img align="middle" src="Images/cal.jpg" width="20" height="20" border="0" alt="Pick a date"></a></td> </tr></tbody></table> </td>

in this way?????

+1  A: 
if (document.getElementById("customer.fcDate").value == "") {
   // BAD!
} else {
   // GOOD!
}
box9
A: 

if you want an easy way, try using jquery validations.

here is a good one: http://demos.usejquery.com/ketchup-plugin/validation.html

if you just need plain js, just check if the input box value has a length of > 1

corroded
A: 

In your validation function you will use something like:

var fcDateInput = document.getElementById('customer.fcDate');
if (fcDateInput == null || fcDateInput.value.length < 1) {
  alert("You should select a valid date");
} else {
  // everything goes right...
}
Garis Suero
A: 

Dear,

You just call this function on Blur to event to check tex-tbox is empty or having value.

  function nullcheck()
  {
    if(document.getElementById(fcDate).value=="")
    {
      alert("Please enter value.");
      return false;
    }
  }

onblur="nullcheck()" -- add this to text box property.

All The Best !!!

Rahul Patil
can you explain it little more?<td> <table><tbody><tr> <td><input type="Text" name="customer.fcDate" id="customer.fcDate" style="customer.fcDate" class="SingleLineTextField" maxlength="10" size="15" tabindex="1" onblur="nullcheck()"></td> <td><a href="javascript:NewCal('customer.fcDate','mmddyyyy')"><img align="middle" src="Images/cal.jpg" width="20" height="20" border="0" alt="Pick a date"></a></td> </tr></tbody></table> </td>in this way?????
riyana