Forum Moderators: open
<!-- load color picker, class="color" will trigger color picker -->
<script type="text/javascript" src="http://www.mysite.com/jscolor/jscolor.js"></script>
....
<form method="GET" action="http://www.mysite.com/product/HEX_COLOR_HERE/5">
<input class="color" name="hex_color" size="5" value="">
<input type="submit" value="Go">
</form>
<script type="text/javascript">
function submitColorForm(form) {
// Get the colour from the form, set it to upper case and remove any hashes
var color = form.hex_color.value.toUpperCase().replace(/\#+/g, '');
// Validate it with a regular expression
if(!color.match(/^[A-Z\d]{6}$/)) {
alert('Invalid colour selected');
return false;
}
// Redirect browser with javascript rather than form
window.location.href = 'http://www.mysite.com/product/' + color + '/5';
// Returning false will prevent the natural form submission from occurring
return false;
}
</script>
<!-- load color picker, class="color" will trigger color picker -->
<script type="text/javascript" src="http://www.mysite.com/jscolor/jscolor.js"></script>
....
<!--
form submission has been changed to your old redirect method
to support the annoying few who like to disable JavaScript.
-->
<form onsubmit="return submitColorForm(this);" method="post" action="http://www.mysite.com/redirect_page.php">
<input class="color" name="hex_color" size="5" value="">
<input type="submit" value="Go">
</form>