What you need to do is assign an event handler to the submit event of the form and do your checks there.
<form onsubmit="return checkForm();" action="next.php" method="get">
<input id="home_page_input" type="text" name="page" value="http://" >
<input id="url_input_button" type="submit" value="enter it !" />
</form>
And in Javscript somewhere:
// onSubmit - if it returns false, it won't submit, and vice versa
function checkForm () {
var url_input_button = document.getElementById('url_input_button');
var ok = /^[a-z]+:\/\//i.test(url_input_button.value);
if (!ok) {
alert('url is not correctly formed');
return false;
}
// url is fine, continue
return true;
}
If you're unsure where to place the javascript code, you can also place it alongside the HTML, like this:
<script type="text/javascript">
// onSubmit - if it returns false, it won't submit, and vice versa
function checkForm () {
var url_input_button = document.getElementById('url_input_button');
var ok = /^[a-z]+:\/\//i.test(url_input_button.value);
if (!ok) {
alert('url is not correctly formed');
return false;
}
// url is fine, continue
return true;
}
</script>
<form onsubmit="return checkForm();" action="next.php" method="get">
<input id="home_page_input" type="text" name="page" value="http://" >
<input id="url_input_button" type="submit" value="enter it !" />
</form>
edit: I've been doing jquery for so long, that my vanilla javascript skills have degraded. Don't know how to assign the event without resorting to inline javascript.. I've edited the example
Somewhat related question on Stack Overflow: how can i validate a url in javascript using regular expression