Note that there are some explanatory texts on larger screens.

plurals
  1. POJavaScript value not set during form submit
    primarykey
    data
    text
    <p>I've searched for a solution to this issue all over the web. After no success, here I am. I have a form that where I have 3 fields that should contain data. Field 1 is the Zip Code, Field 2 and 3 are City and State respectively. </p> <p>The JS function getCityByZipHome and getStateByZipHome dynamically return the city and state and insert the values into the the city2 and state2 input fields.</p> <p>For whatever reason, when I submit the form via mouse-click.. I see the data via $_POST. If the users presses ENTER, the data is never captured and I never see that data from the hidden fields. </p> <p>Any idea what's wrong here? Note, I've tried almost all the event handlers onblur, onclick, onchange..etc. </p> <pre><code>&lt;form method="post" name="something" action="xxSome.php"&gt; &lt;div class="s_row"&gt; &lt;label for="zippy"&gt;Enter Zip Code&lt;/label&gt; &lt;input id="zipcode_home" tabindex="2" type="text" onkeypress="javascript:getCityByZipHome(document.getElementById('zipcode_home').value, this.form.elements['city3']);javascript:getStateByZipHome(document.getElementById('zipcode_home').value, this.form.elements['state3']);" name="zipcode_home"/&gt; &lt;input id="state3" name="state3"type="hidden"/&gt; &lt;input id="city3" name="city3" type="hidden"/&gt; &lt;input type="submit" value="Start Now!"/&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>I've tried adding onsubmit @ the form level as such:</p> <pre><code>&lt;form method="post" name="something" action="xxSome.php" onsubmit="javascript:getCityByZipHome(document.getElementById('zipcode_home').value, this.form.elements['city3']);javascript:getStateByZipHome(document.getElementById('zipcode_home').value, this.form.elements['state3']);"&gt; &lt;div class="s_row"&gt; &lt;label for="zippy"&gt;Enter Zip Code&lt;/label&gt; &lt;input id="zipcode_home" tabindex="2" type="text" name="zipcode_home"/&gt; &lt;input id="state3" name="state3"type="hidden"/&gt; &lt;input id="city3" name="city3" type="hidden"/&gt; &lt;input type="submit" value="Start Now!"/&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p>And I've tried onblur without any luck @ the input level as such:</p> <pre><code>&lt;form method="post" name="something" action="xxSome.php"&gt; &lt;div class="s_row"&gt; &lt;label for="zippy"&gt;Enter Zip Code&lt;/label&gt; &lt;input id="zipcode_home" tabindex="2" type="text" onblur="javascript:getCityByZipHome(document.getElementById('zipcode_home').value, this.form.elements['city3']);javascript:getStateByZipHome(document.getElementById('zipcode_home').value, this.form.elements['state3']);" name="zipcode_home"/&gt; &lt;input id="state3" name="state3"type="hidden"/&gt; &lt;input id="city3" name="city3" type="hidden"/&gt; &lt;input type="submit" value="Start Now!"/&gt; &lt;/div&gt; &lt;/form&gt; </code></pre> <p><strong>After all the messing around, I actually never solved the issue; rather, I disabled the ENTER key as a submit method.</strong> </p> <p>I have some pretty serious time constraints, but I'm sure this will come up later and I will definitely come back to this issue. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload