Note that there are some explanatory texts on larger screens.

plurals
  1. POWhat can i use instead of Array in javascript?
    text
    copied!<p>I have a script that auto populate form (3 fields) and it does work as i wanted (previously), but now, when i have like 2000 inputs, i can not handle it anymore. What i want to do is, make auto populate script where i can add more information later, for new inputs, now, i would need to start changing numbers for each input, i believe you'll understand batter through my code:</p> <p>Javascript:</p> <pre><code>var ids = new Array(); var use = new Array(); var ful = new Array(); ids[0] = ""; use[0] = ""; ful[0] = ""; ids[1] = "test1"; use[1] = "test2"; ful[1] = "test3"; ids[2] = "test1"; use[2] = "test"; ful[2] = "test3"; ids[3] = "test1"; use[3] = "test2"; ful[3] = "test3"; ids[4] = "test1"; use[4] = "test2"; ful[4] = "test3"; function Choice() { //x = document.getElementById("users"); y = document.getElementById("selectUsers"); //x.value = y.options[y.selectedIndex].text; document.getElementById("ids").value = ids[y.selectedIndex]; document.getElementById("use").value = use[y.selectedIndex]; document.getElementById("ful").value = ful[y.selectedIndex]; } </code></pre> <p>Form:</p> <pre><code>&lt;select id="selectUsers" class=" outtaHere" name="users" onChange='Choice();'&gt;&lt;option value="0" selected="selected"&gt;Choose...&lt;/option&gt; &lt;option value="1"&gt;Test1&lt;/option&gt; &lt;option value="2"&gt;Test2&lt;/option&gt; &lt;option value="3"&gt;Test3&lt;/option&gt; &lt;option value="4"&gt;Test4&lt;/option&gt; </code></pre> <p>The problem is in, if i try to add new option value on 2nd position, with value 5, i would need to change the javascript order again, 1,2,3,4,5, i'm wondering, if i'm able to make the javascript like this and make it work:</p> <pre><code>&lt;option value="1"&gt;Test1&lt;/option&gt; &lt;option value="2"&gt;Test2&lt;/option&gt; &lt;option value="4"&gt;Test4&lt;/option&gt; &lt;option value="3"&gt;Test3&lt;/option&gt; ids[2] = "test1"; use[2] = "test"; ful[2] = "test3"; ids[4] = "test1"; use[4] = "test2"; ful[4] = "test3"; ids[3] = "test1"; use[3] = "test2"; ful[3] = "test3"; </code></pre> <p>Please note the difference in 3 and 4 ids.</p> <p>What's the best option i can use?</p>
 

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