Sunday, July 8, 2012

Custom javascript client side validation in magento on individual page

<script type="text/javascript" language="javascript">
var dataForm = new VarienForm('contactForm');
Validation.addAllThese(
[
['validate-number-tel', '<?php echo $this->__('Please Enter Valid telephone number and pincode') ?>', function(v) {
if(document.getElementById("telephone1").value == "" || document.getElementById("telephone2").value == "")
{
return false;
}
else
{
return true;
}
}],
['validate-captcha', 'Your Captcha Entry Mismatch', function(v) {
if(document.getElementById("hdnRandomString1").value != document.getElementById("recaptcha_response_field1").value)
{
return false;
}
else
{
return true;
}
}]
]
);
</script>
<script type="text/javascript">
//<![CDATA[
var contactForm = new VarienForm('contactForm', true);
//]]>
</script>
<script type="text/javascript" language="javascript">
function validateNumberKey(event) {
var key = window.event ? event.keyCode : event.which;
if (event.keyCode == 8 || event.keyCode == 46
|| event.keyCode == 37 || event.keyCode == 39 || event.keyCode == 9) {
return true;
}
else if ( key < 48 || key > 57 ) {
return false;
}
else return true;
}
</script>

No comments:

Post a Comment

Please mention your comments.......