最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript textbox validation - Stack Overflow

programmeradmin3浏览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?????

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

Share Improve this question edited Aug 18, 2010 at 11:23 riyana asked Aug 17, 2010 at 4:48 riyanariyana 21.7k10 gold badges37 silver badges35 bronze badges
Add a ment  | 

4 Answers 4

Reset to default 2
if (document.getElementById("customer.fcDate").value == "") {
   // BAD!
} else {
   // GOOD!
}

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.

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

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

if you just need plain js, just check if the input box value has a length of > 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...
}
发布评论

评论列表(0)

  1. 暂无评论