/    Sign up×
Community /Pin to ProfileBookmark

user input box for a url that will redirect to that url

Hi guys
Need your help!
I am learning Javascript with an online school and got stuck for a few hours on this : ( I know it must dead simple and not enough to stimulate your brain)
Write a JavaScript program that will accept a url from a user using an input box. The program should then transport the user to the url using the Location object with the “href” method.

<SCRIPT LANGUAGE=”JavaScript”>
<!–hide from older browsers
function location.href.url()
{
Var url = form_site.url.value;
}
//–>
</SCRIPT>
</HEAD>
<BODY>
<form method=”post” action=”” name=”form_site”>
Please enter below the web site address of your dream:<br>
<input type=”text” name=”url”><br>
<input type=”button” value=”submit” onClick=”javascript:location.href(‘url’)>
<input type=”reset” value=”reset”>
</form>
</BODY>

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@CharlesDec 27.2004 — [font=monospace]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"

"http://www.w3.org/TR/html4/strict.dtd">

<html lang="en">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta name="Content-Script-Type" content="text/javascript">

<meta name="Content-Style-Type" content="text/css">

<title>Example</title>

<style type="text/css">

<!--

fieldset {width:20em; padding:1em}

label {display:block; text-align:right}

button {display:block; margin:auto; margin-top:1em}

-->

</style>

</head>

<body>

<form action="redirect-for-the-javascript-free.pl" onsubmit="this.action = this.url.value">

<fieldset>

<legend>Please enter below the web site address of your dream:</legend>

<label>URL: <input name="url"type="text"></label>

<button type="submit">Submit</button>

</fieldset>

</form>

</body>

</html>[/font]
Copy linkTweet thisAlerts:
@berty380May 10.2012 — Hello,

Thanks for much for this code. I know I'm 8 years behind, but this code has recently answered a million questions for me. If possible, I'm hoping someone can help me expand on it....

  • 1. Is it possible to adjust this code so that the URL submitted remains the URL upon page reload. In other words. If I type in http://google.com, is there a way to make sure each time I visit the original page it is directed to google.com?


  • I am trying to use this as an Iframe application similar to Theme Forest, Woothemes, etc. When my customers visit the original site with the form (thx to your code), they will simply input their URL and press submit. This redirects them to the very URL they submitted. Ideally, I can find a way to lock this redirect in so that they never have to fill in the form again.

  • 2. Additionally, this code only allows for URLs or addresses that begin in http:// . Is there a way to make this code work so that a user can put in google.com or www.google.com as opposed to the http?


  • Thanks again for all your help!

    Robert
    ×

    Success!

    Help @fredlearninjava spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.21,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...