1

Hi am generating input boxes dynamically base on database keys.

 <input type="text" id="101" name="101"> 
 <input type="text" id="302" name="302">
 <input type="text" id="501" name="501">
 <input type="text" id="601" name="601">

i want to make it mandatory fields + max length validation check using jquery

1
  • 1
    What's your question? What have you tried? Commented Dec 27, 2010 at 10:34

2 Answers 2

3

Check out http://docs.jquery.com/Plugins/validation

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript" src="http://dev.jquery.com/view/trunk/plugins/validate/jquery.validate.js"></script>
<style type="text/css">
* { font-family: Verdana; font-size: 96%; }
label { width: 10em; float: left; }
label.error { float: none; color: red; padding-left: .5em; vertical-align: top; }
p { clear: both; }
.submit { margin-left: 12em; }
</style>

<script>
$(document).ready(function(){
    $("form[name=validation]").validate()
});
</script>

<form name="validation" action="" method="post">
    <p>
        <label for="101">101</label>
        <input type="text" id="101" name="101" class="required" maxlength="4">
    </p>
    <p>
        <label for="302">302</label>
        <input type="text" id="302" name="302" class="required" maxlength="4">
    </p>
    <p>
        <label for="501">501</label>
        <input type="text" id="501" name="501" class="required" maxlength="4">
    </p>
    <p>
        <label for="601">601</label>
        <input type="text" id="601" name="601" class="required" maxlength="4">
    </p>
    <p>
        <input class="submit" type="submit" value="Submit"/>
    </p>
</form>
Sign up to request clarification or add additional context in comments.

Comments

0
 $('input[type=text]').each(function() { 
    if($(this).val() == '')
       alert('is Null');
    if($(this).val().length > 5)
       alert('max length execced');

 })

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.