0

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?????

4 Answers 4

2
if (document.getElementById("customer.fcDate").value == "") {
   // BAD!
} else {
   // GOOD!
}
Sign up to request clarification or add additional context in comments.

Comments

1

You just call this function on Blur to event to check text box 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.

2 Comments

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?????
On the above "input type="Text" name="customer.fcDate", you need to integrate this function. ???
1

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

Comments

1

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...
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.