...

View Full Version : Why does one URL direct work and the other not?



Grangripau
08-20-2010, 12:00 PM
I read a beginners book on js and now I'm working through a cookbook style book to get a hang of things, I came across an example for redirecting URLs in the book that didn't work:



<form>
<input type="text" name="url">
<input type="button" value="Go" onClick="location.href=this.form.url.value">
</form>


After searching on the net I found another that works perfectly but
I don't understand why the one in the book doesn't work.

works:


<form name="openlocation">
<input type="text" name="href">
<input type="button" value="Go" onClick="location.href=document.openlocation.href.value;; ">
</form>


I tried replacing the url with href and other tweaks, is it that you cant use ".this" here, making it necesary to name the form?

Any explanation help would be apreciated.

Thanks in advance!

Philip M
08-20-2010, 12:07 PM
Why do you think that it does not work?



<form>
<input type="text" name="url" value = "http://www.google.com">
<input type="button" value="Go" onClick="location.href=this.form.url.value">
</form>


All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

Grangripau
08-20-2010, 12:21 PM
Hi Philip,

I tried substituting url for href in the name and the onclick, and I also tried adding "document." in the onclick.

I think it's because the form needs a name, then needs to be referenced, but I don't understand why you cant just use ".this"

Philip M
08-20-2010, 01:35 PM
See Post#2.

Why do you think that it does not work?


<form>
<input type="text" name="url" value = "http://www.google.com">
<input type="button" value="Go" onClick="location.href=this.form.url.value">
</form>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum