Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript onchange not working anymore after upload on public_html
    text
    copied!<p><strong>What I want to do</strong></p> <p>Auto populate a form text field based on what is selected in a form select field.</p> <p><strong>What I have done so far</strong></p> <p>The code below is working perfectly fine during development:</p> <p>STEP 1: I populate array of data</p> <pre><code>&lt;script type="text/javascript"&gt; var carcolorData = new Array(); carcolorData['Ford'] = 'Blue'; carcolorData['BMW'] = 'Green'; carcolorData['Fiat'] = 'Red'; carcolorData[''] = 'Hello'; &lt;/script&gt; </code></pre> <p>STEP 2: I create a typical html form with a text and select field:</p> <pre><code>&lt;form&gt; &lt;select name="cartype" id="cartype" &gt; &lt;option selected="selected"&gt;&lt;/option&gt; &lt;option&gt;Ford&lt;/option&gt; &lt;option&gt;BMW&lt;/option&gt; &lt;option&gt;Fiat&lt;/option&gt; &lt;/select&gt; &lt;input name="carcolor" type="text" id="carcolor" /&gt; &lt;/form&gt; </code></pre> <p>STEP 3: I create a little javascript function to autopopulate onchange:</p> <pre><code>&lt;script type="text/javascript"&gt; document.form.cartype.onchange = showColor; function showColor() { var obj_sel = document.form.cartype; document.form.carcolor.value = carcolorData[obj_sel.value]; } &lt;/script&gt; </code></pre> <p><strong>The problem</strong></p> <p>Doesn't work anymore after upload on public_html. Whatever I select it displays 'Hello' which is the color corresponding to blank in my example. I am totally lost... The code is correct since it works fine during development phase. Why is it not working anymore after upload on public_html?</p> <p><strong>Possible reasons</strong></p> <p>I am thinking of this but I may be far from the truth...</p> <ol> <li>Different versions of IE (?)</li> <li>Different development parameters (?)</li> <li>Conflict with other javascript on the same page (?)</li> <li>The javascript is not positioned correctly in the script (?)</li> </ol>
 

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