I have forms generated by loop, so the name of elements would be the same. That’s the reason i want to use $(this) inorder to access them and compare. But unsuccesful as of yet, any ideas how can I.
FYI I am a newbie to Jquery, any help appreciated 🙂
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
$("form").submit(function() {
if ($(this).children("#textbx").val() < $(this).children("#comparetobox").val() ) {
$("span").text("Validated...").show();
return true;
}
$("span").text("Not valid!").show().fadeOut(1000);
return false;
});
</script>
<form id='userbid' name='userbid' method=post>
<input type="text" name="textbx" id="textbx">
<input type="text" name="comparetobox" id="comparetobox">
<span></span>
<input type="submit" value="save" name="submit">
</form>
<!-- Form is in loop so can be generated N no of times -->
<form id='userbid' name='userbid' method=post>
<input type="text" name="textbx" id="textbx">
<input type="text" name="comparetobox" id="comparetobox">
<span></span>
<input type="submit" value="save" name="submit">
</form>
I don’t know how you compare values of
inputboxes, but this is valid JavaScript code:Pay attention that ID of elements should be unique. Use classes instead (e.g.
.textbx).