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

  • SEARCH
  • Home
  • 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 8357473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T10:29:15+00:00 2026-06-09T10:29:15+00:00

I have a very simple form on my site http://www.example.com <form> <input type=text value=

  • 0

I have a very simple form on my site http://www.example.com

<form>
    <input type="text" value="" name="name">
</form>

How do I get my form to look like this

<form>
    <input type="text" value="tom" name="name">
</form>

If I type in (or a user is taken to this page from a search page) http://www.example.com?name=tom

bearing in mind at some point my form may look like this.

<form>
    <input type="text" value="" name="name[]">
    <input type="text" value="" name="name[]">
    <input type="text" value="" name="name[]">
    <input type="text" value="" name="name[]">
</form>

so I would like to handle an array of names as well. I have had a look at jQuery.param() but can’t get my head around how I would do this. Is it possible without submitting to a server side language sucha as php?

  • 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-09T10:29:16+00:00Added an answer on June 9, 2026 at 10:29 am

    There’s no baked-in jQuery way to get name/value pairs from the querysting to javascript variables (though, shouldn’t there be??)

    But folks have written pure javascript functions to do that for you: How can I get query string values in JavaScript?.

    If you use the 2nd answer to the above question, by Andy E, you can capture all the querystring vars to name-value pairs of a javascript object. Here’s what he wrote:

    var urlParams = {};
    (function () {
        var match,
            pl     = /\+/g,  // Regex for replacing addition symbol with a space
            search = /([^&=]+)=?([^&]*)/g,
            decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
            query  = window.location.search.substring(1);
    
        while (match = search.exec(query))
           urlParams[decode(match[1])] = decode(match[2]);
    })();
    

    Then use these to set the form values of inputs with the same name as the querystring names with jQuery like this:

    $.each(urlParams, function(key, value){
        $('form [name=' + key + ']').val(value);
    });
    

    Update: since this is hard to test in jsFiddle, here is an entire web page as a working example. It will replace the values ‘a’, ‘b’, and ‘c’ with those passed in by the url (‘1’, ‘2’, and ‘3’) — just set this up as test.html on localhost and go to: http://localhost/test.html?a=1&b=2&c=3

    <!DOCTYPE html>
    <html><head><title>Test URL params</title>
    
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
    <script type="text/javascript" >
        $(function(){
                var urlParams = {};
                (function () {
                    var match,
                    pl     = /\+/g,  // Regex for replacing addition symbol with a space
                    search = /([^&=]+)=?([^&]*)/g,
                    decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); },
                    query  = window.location.search.substring(1);
    
                    while (match = search.exec(query))
                       urlParams[decode(match[1])] = decode(match[2]);
                })();
    
                $.each(urlParams, function(key, value){
                    $('form [name=' + key + ']').val(value);
                });
        });
    </script>
    
    </head>
    <body>
    
    <form>
        <input name="a" value ="a" /><input name="b" value ="a" /><input name="c" value ="a" />
    </form>
    
    </body></html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have very simple OpenGL ES example similar to Hehe's example : http://nehe.gamedev.net/tutorial/ios_lesson_02__first_triangle/50001/ As
I have a very simple fxml file, with a checkbox: ... <AnchorPane id=AnchorPane xmlns:fx=http://javafx.com/fxml
I have a very simple form for data input. Just labels with inputs. But
I have a very simple contact form on my site, Im looking for users
I have a very simple entry form. After a button is pressed, I need
I have a very simple XAML form, that has one namespace definition. For some
So I have 4 pages. They are very simple. index.php (WORKS) <html> <form action=upload.php
I have very simple piece of code. The goal is when i input four-digit
I have a VERY simple windows form that the user uses to manage Stores.
I have a very simple form where users can enter their email and click

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.