1

I have a HTML form like:

<form name="input" action="" method="post">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>

I need to build a URL when the submit link is clicked and send the user to it, using the username from the form in the correct position in the URL.

URL:

http://example.com/htmlchat/init.html?init_room=1&init_user=USERNAME_FROM_FORM_HERE

Can someone help (an example would be great)?

1
  • Why do you need the user value twice? You are already sending it as POST data. Commented Aug 8, 2014 at 10:26

2 Answers 2

3
  1. Don't use POST when you want the data to appear in the URL
  2. Do put all the data you want in your URL in the form
  3. Get the names of your fields right
  4. Put the base URI in the action

such:

<form action="init.html">
    <input type="hidden" name="init_room" value="1">
    <label>
        Username: 
        <input name="init_user">
    </label>
    <input type="submit" value="Submit">
</form>
Sign up to request clarification or add additional context in comments.

Comments

0

This is possible with either Javascript or a server side language such as PHP. With Javascript you want to update the action attribute.

You could use jQuery to do this.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.