Javascript help: How do I validate a URL entered into a form?
I've been battling this one for too many hours...it's time to ask for help. I'm trying to combine a few free scripts because I can't find one that will do exactly what I want.
Here's the offending page WebsiteMobiliser.com | Mobile Website Portfolio | Australia
What I'm trying to do is display a website in a frame. The website comes from user input into a form field. It currently works OK unless the user forgets to enter http://.
I'll use this forum url as an example:
It works fine for http://www.warriorforum.com
and it will work fine for http://warriorforum.com
but will not work for warriorforum.com or www.warriorforum.com
or warriorforum.com
Here's what I have used in the head...
<script type="text/javascript">
var url;
function submitURL() {
url = document.getElementById("goTo").value;
check = url.substr(0,7);
check = check.toLowerCase();
if (check != "http://")
{
url = "http://"+url;
myURL.document.location.href = url;
}
else
{
myURL.document.location.href = url;
}
}
</script> <p>
<form target="frame" onsubmit="this.action=this.goTo.value">
<b><font face="arial">Test your site...</font></b><br />
<input type="text" name="goTo" onchange="submitURL()" size="50" id="goTo" placeholder="enter your web address here"></form>
<font face="arial" size="-1">(enter your website, including the http://, press enter)</font>
</p> <iframe name="frame" style="height: 489px; width: 327px;" src="Website Mobiliser | Mobile Website Designer" frameborder="0" marginwidth="0" scrolling="no" width="320" height="240"> </iframe>
I'd appreciate any suggestions even if you're not sure if it will work. I'm willing to try things until I figure this out. If I figure it out I'll post the solution so we can all learn.
Tips: I think the problem is in the naming of certain elements. The javascript code I got from a coding website and I'm pretty sure it needs adjusting to point to my frame but I'm not sure where. Is it in the "goTo" or the "myURL" parameters or elsewhere or am I way off? I know I'm close but I just don't have quite enough skill to pull this off.
-
Tradeout -
Thanks
{{ DiscussionBoard.errors[6360039].message }} -
-
Mr Bill -
Thanks
{{ DiscussionBoard.errors[6360048].message }} -