PDA

View Full Version : textbox in form only allows URLs


Ricky158
11-11-2002, 09:49 PM
i'm making a "Suggest a Link" feature for my site. so i'm trying to make a form with a textbox that MUST contain "http://" and "." within the text the user submits. here's what is is now...

--------

<FORM ACTION="/cgi-bin/script_library/form_handler_mail" METHOD=POST>What is the name of the site?<input type="text" name="site_name"><br>What is the URL of the site?<input type="text" name="site_URL"><INPUT TYPE="hidden" NAME="required" VALUE="email">
<INPUT TYPE="hidden" NAME="order" VALUE="site_name, site_URL">
<INPUT TYPE="hidden" NAME="savefile" VALUE="visitors.txt">
<INPUT TYPE="hidden" NAME="email_to" VALUE="(my email address here)">
<INPUT TYPE="submit" VALUE="Send Feedback"><input type="reset" value="Clear Form"></form>

---------

could someone just copy that code and insert the code to make it only allow URLs in the appropriate place? also, not to try to ask too much, but if the person doesnt enter a URL, could there be an alert box saying "You must enter a valid URL in order to complete the form"

Thanks to anyone who dares to take on this monsterous task :p

beetle
11-11-2002, 10:40 PM
Sure!function doForm(f) {
var e = f.elements['site_URL'];
if(!/^https?:\/\/.+\..+$/i.test(e.value)) {
alert('You must enter a valid URL to continue');
e.select();
e.focus();
return false;
}
return true;
}

<form action="/cgi-bin/script_library/form_handler_mail" method="post" onsubmit="return doForm(this);">
What is the name of the site?<input type="text" name="site_name"><br>
What is the URL of the site?<input type="text" name="site_URL">
<input type="hidden" name="required" value="email">
<input type="hidden" name="order" value="site_name, site_URL">
<input type="hidden" name="savefile" value="visitors.txt">
<input type="hidden" name="email_to" value="(my email address here)">
<input type="submit" value="Send Feedback"><input type="reset" value="Clear Form"></form>