Forum Moderators: open

Message Too Old, No Replies

Enter to submit a URL to the iFrame

         

farizluqman

8:00 pm on Aug 19, 2011 (gmt 0)

10+ Year Member



Hello, recently, I made a proxy server... everything is going fine except, when I press enter on the text box, it will do nothing... this is my script

The story is:
1. User enter the url into the text box (for example www.google.com), and the URL will be rewritten as: "http://labnol-proxy-server.appspot.com/www.google.com" and then it will send it to the iFrame
2. the problem is, I want the text box to load just by pressing the Enter key. It is quite annoying to press the "GO" button each time to visit any website... so, what I want is I can press enter at the text box and it will load just like when I pressed the go button

<script> 
function go(){
var L1 = document.theform.lastframe.value;

if (L1!= "#")
{
var url = "http://labnol-proxy-server.appspot.com/" + L1;
document.getElementById("lastframe").src = url;
}
}
</script>
<form name="theform">
<INPUT TYPE="text" name="lastframe" size="30" MAXLENGTH="30" onUnfocus="go()">
<input type="button" value="GO" onclick="go()"/>
</form>
<iframe name="lastframe" id="lastframe" SRC="http://labnol-proxy-server.appspot.com/www.google.com" width="100%" height="500" frameborder="0" marginwidth="0" marginheight="0" ></iframe>


Fotiman

8:24 pm on Aug 19, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Replace your <input type="button"> with an actual submit button. Then move the code from the onclick handler of your button to the onsubmit of the form. Make sure you return false in the onsubmit handler if you don't want the default form action. For example:

<form name="theform" action="#" onsubmit="go(); return false;">
...
<input type="submit" value="GO">

farizluqman

8:48 pm on Aug 19, 2011 (gmt 0)

10+ Year Member



Wow! That's a fast reply! Thanks, now it works.

Fotiman

3:19 am on Aug 20, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Glad to help, and welcome to WebmasterWorld! :)