Sanjoy Roy

[MCM, MCP, SCJP] – Senior PHP Programmer

Javascript Validate two input fields with the same name?


<div style=”” id=”shipping-new”>
<table class=”form”>
<tr>
<td><span class=”required”>*</span> Post Code:</td>
<td><input type=”text” class=”large-field” value=”” name=”postcode”><span class=”error”>Sorry, we cannot deliver to your area!</span></td>
</tr>
</table>
</div>

<div style=”” id=”payment-new”>
<table class=”form”>
<tr>
<td><span class=”required”>*</span> Post Code:</td>
<td><input type=”text” class=”large-field” value=”” name=”postcode”><span class=”error”>Sorry, we cannot deliver to your area!</span></td>
</tr>
</table>
</div>

<script>
$(document).ready(function() {
$(‘#shipping-new input[name=”postcode”]’).keyup(function() {
allowed_postcodes = [<?php echo $this->config->get(‘config_postcodes_allowed’); ?>];
if ($(‘#shipping-new input[name=”postcode”]’).val().length == 4) {
$(‘.error’).remove();
if ($.inArray(parseInt($(‘#shipping-new input[name=”postcode”]’).val()), allowed_postcodes) == -1) {
$(‘#shipping-new input[name=”postcode”]’).after(‘<span class=”error”>Sorry, we cannot deliver to your area!</span>’);
$(‘#register a.button’).hide();
} else {
$(‘#register a.button’).show();
}
}
});
$(‘#payment-new input[name=”postcode”]’).keyup(function() {
allowed_postcodes = [<?php echo $this->config->get(‘config_postcodes_allowed’); ?>];
if ($(‘#payment-new input[name=”postcode”]’).val().length == 4) {
$(‘.error’).remove();
if ($.inArray(parseInt($(‘#payment-new input[name=”postcode”]’).val()), allowed_postcodes) == -1) {
$(‘#payment-new input[name=”postcode”]’).after(‘<span class=”error”>Sorry, we cannot deliver to your area!</span>’);
$(‘#register a.button’).hide();
} else {
$(‘#register a.button’).show();
}
}
});
});
</script>

Comments are closed.