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>

One response to “Javascript Validate two input fields with the same name?

  1. SutoCom 11/07/2013 at 8:05 PM

    Reblogged this on Sutoprise Avenue, A SutoCom Source.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: