0

I am trying to use a query string to pull the first and last name into the url, however the code that I have used does not work, it is not giving any results. I am unsure who to processed.I have tried different ways put I am getting the same result, the query seems fine, however the form seems to be where it is breaking.

$(function () {//grab the entire query stringvar query = document.location.search.replace('?', '');//extract each field/value pairquery = query.split('&');//run through each pairfor (var i = 0; i < query.length; i++) {  //split up the field/value pair into an array  var field = query[i].split("=");  //target the field and assign its value  $("input[name='" + field[0] + "'], select[name='" + field[0] + "']").val(field[1]);}});</script></head><body><div><input type="hidden" name="MainContent$0$0$hfCallBack"> <input type="hidden" name="MainContent$0$0$hfViewState"><div><div>  <h2>Query string form filling demo</h2>  <p></p>  </div>  <div>  <p>Please enter the required information</p></div><div>  <div>    <div>      <span>Name</span>    </div>    <div>      <p>        <span>          <input name="field_92375_1015030" type="text" size="16" value="">          <em>First</em>        </span>        <span>          <input name="field_92375_1015031" type="text" size="16" value="">          <em>Last</em>        </span>      </p>    </div>    <div></div>  </div>  </div><!-- REST OF FORM OMITTED FOR BREVITY -->   </div> </div></body>
askedMay 22, 2015 at 10:40
user3182518's user avatar
1

1 Answer1

1
search=window.location.search;  search=search.slice(1);listOfPairs=search.split("&");keyVal=new Object();keyValue=new Array();  for(i=0;i<listOfPairs.length;i++){      temp=listOfPairs[i].split("=")    keyVal.key=temp[0];    keyVal.value=temp[1];    keyValue.push(keyVal); }
answeredMay 22, 2015 at 11:10
Joey Dias's user avatar
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Sign up orlog in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

By clicking “Post Your Answer”, you agree to ourterms of service and acknowledge you have read ourprivacy 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.