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 string
var query = document.location.search.replace('?', '');

//extract each field/value pair
query = query.split('&');

//run through each pair
for (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 class="element" id="element3528871_1345643">
<input type="hidden" name="MainContent$0$0$hfCallBack" id="MainContent_0_0_hfCallBack"> <input type="hidden" name="MainContent$0$0$hfViewState" id="MainContent_0_0_hfViewState">
<div id="MainContent_0_0_pnlViewForm" class="form_container">
<div class="formHeader">
  <h2 class="formTitle">Query string form filling demo</h2>
  <p class="formDescription"></p>
  </div>
  <div style="display:none;" class="errorSummary">
  <p>Please enter the required information</p>
</div>
<div class="fieldItem type-name medField" id="">
  <div class="fieldItemInner">
    <div class="fieldTitle">
      <span class="title">Name</span>
    </div>
    <div class="fieldContent">
      <p class="fieldRow">
        <span class="fieldBlock">
          <input name="field_92375_1015030" type="text" size="16" class="textField firstname" value="">
          <em class="fieldNote">First</em>
        </span>
        <span class="fieldBlock">
          <input name="field_92375_1015031" type="text" size="16" class="textField lastname" value="">
          <em class="fieldNote">Last</em>
        </span>
      </p>
    </div>
    <div class="fieldInstructions"></div>
  </div>
  </div>

<!-- REST OF FORM OMITTED FOR BREVITY -->

   </div>
 </div>
</body>
1

1 Answer 1

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); 
}
Sign up to request clarification or add additional context in comments.

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.