1

I have written the script below to pull in data from a url string and then place in preexisting (un-editable) form fields.

<script>
var Month = getQueryVariable("Month");

function getQueryVariable(variable) {
var query = window.location.search.replace("?", "");
for (var vars = query.split("&"), i = 0; i < vars.length; i++) {
    var pair = vars[i].split("=");
    if (decodeURIComponent(pair[0]).replace("+", " ") == variable) {
        return decodeURIComponent(pair.slice(1).join("=")).replace("+", " ");
    }
}
return "NONE"
}

</script><script type="text/javascript">
   document.getElementById('Month').readOnly = true;
</script>

I am able to pull in the data from the url just fine. However I get an error when submitting, and upon inspecting the element, it appears the value that was passed has tripled! Any idea what is causing this and how I can prevent it? My assumption is it is something with the autotab.

<input id="Month" name="Month" class="month autotab autotabdate" type="text" value="12,12,12" size="2" maxlength="2" readonly="">

URL used is: https://test.com/welcome.html?Month=12

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
odyssey82
  • 7
  • 3
  • possible duplicate of [How to get the value from the URL parameter?](http://stackoverflow.com/questions/979975/how-to-get-the-value-from-the-url-parameter) – SaidbakR Apr 30 '15 at 19:03
  • What does your URL look like? –  Apr 30 '15 at 19:07
  • URL used is: https://test.com/welcome.html?Month=12 – odyssey82 Apr 30 '15 at 19:17
  • @sємsєм OP says that getting the value from the URL is working, so this is not a duplicate of _that_ question. – Stephen P Apr 30 '15 at 21:13
  • Sorry, I want to cancel this vote to close but I could not. @StephenP – SaidbakR Apr 30 '15 at 22:46
  • The second script tag in your code should be placed at the end of the page before closing `

    ` then you have to supply the field with the value after making it readonly `document.getElementById('Month').value = Month;`

    – SaidbakR Apr 30 '15 at 23:01
  • Thanks @sємsєм, followed your suggestion. Still getting the same result where value="12,12,12" as opposed to just "12" – odyssey82 May 01 '15 at 00:21
  • Got it... appears as if it was posting to https://test.com/welcome.html?Month=12. Had to create another JavaScript tag to remove the section after html from the post action. Thank you for your help! – odyssey82 May 01 '15 at 12:51

1 Answers1

0

Got it... appears as if it was posting to test.com/welcome.html?Month=12. Had to create another JavaScript tag to remove the section after html from the post action.

odyssey82
  • 7
  • 3