Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7869895
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T01:27:28+00:00 2026-06-03T01:27:28+00:00

I want to make a form with a text field where the user enters

  • 0

I want to make a form with a text field where the user enters something, then that needs to be incorporated into the link to an external site the user will be redirected to.

So let’s say the user enters ‘foobar’. After he clicks submit he should be taken to http://example.com/foobar .

This should preferably be in JS, although PHP works as well.

So far I have this:

<html>
<head>
<script type="text/javascript">

function genURL() {
var user = document.getElementById('user');
window.location.href = "http://example.com/" + user;
}

</script>
</head>
<body>

<form>
username: <input type="text" name="user">
<input type="submit" value="Submit" name="user" onClick="genURL()">
</form>

</body>
</html>

The only thing this does is append ?user=foobar to the URL.

What do I need to do to make this work?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T01:27:29+00:00Added an answer on June 3, 2026 at 1:27 am

    You should prevent the form from being submitted. You can do this by making your function the onsubmit handler of the form and returning false to prevent the form from being submitted.

    Furthermore you should get the field’s content by using .value in document.getElementById('').value.

    JavaScript:

    function genURL() {
        var user = document.getElementById("user").value;
        window.location = "http://google.com/" + user;
    }​
    

    HTML:

    <form onsubmit="genURL(); return false;">
        <input type="text" id="user" />
        <input type="submit" value="Submit" />
    </form>​
    

    Demo: http://jsfiddle.net/jhogervorst/CFHtG/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to make the descriptive text around a form link also open the
I want to get data that user enter in the text field with name
I have a php script that gets user input (some text and a link),
I want to make the clock application where user enters the number in the
I want to validate a form to make sure a user writes in a
I have a form in asp with two text boxes. If user enters a
I try to make user registation form. I have two user types and want
I have a form which takes a couple of text field inputs and then
I want to make this form: echo '<form method=post action=ratinghandler.php style=width: 250px> <input type=hidden
I want to make a form like this, and i want to post the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.