tags:

views:

70

answers:

2

Hello, how i need fill out a input of my form with jquery.

I have my url: http://example.com/page.html?name=YourName=Mark

+1  A: 

You could use a function that returns the value of a querystring parameter and then set the form field accordingly:

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
    var regexS = "[\\?&]" + name + "=([^&#]*)";
    var regex = new RegExp(regexS);
    var results = regex.exec(window.location.href);
    if (results == null)
        return "";
    else
        return results[1];
 }

var sName = getParameterByName(name);

Then set the form field value using jquery:

$("#formFieldID").val(sName);
TGuimond
your querystring would look something like thishttp://example.com/page.html?name=Mark
TGuimond
+1  A: 

Another alternative would be to use the jQuery plugin:

http://plugins.jquery.com/node/7491

TGuimond