javascript - Removing Current value from dropdown -


I have 2 dropdown boxes that allow users to choose their age and gender. These dropdown boxes attract my value from my database (PHP 5.5+ MYSQL), and use the retrieved value as the default value shown to the user.

Other dropbox options are generated through pageload operations.

The functions are:

  function age dropdown () {var list = document.getElementById ("age"); (Var i = 1; i & lt; 100; i ++) for {var opt = document.createElement ("options"); Opt.value = i; Opt.textContent = I; List.appendChild (optional); }   

}

  function genderlists () {var list = document.getElementById ("gender"); Var option = ["M", "F"]; (I = 0; i   

Although my code works perfectly, and all of the options are displayed, whenever I click on the dropbox to change the value, the current value is additionally for options that are generated.

Example

Age

  18 1 2 3 & lt; ---- The value shown in the select dropdown 4 5 6   

gender

  mmf   

when I showed Will go to the dropdown box that is about to delete the default value from the given options?

Example (What I want to do instead of what is shown above.)

Age

  1 2 3 4 5 6 7   

gender

  mf    

All you have to do is empty the div. You can set the internal HTML in the empty string to clear the div.

Note:

Add whatever you want to your div. So you have to clean the divis (remove your children).

The code should be list.innerHTML = "";

The complete code should be as follows:

  function age dropdown () {var list = document.getElementById ("age"); List.innerHTML = ""; (Var i = 1; i & lt; 100; i ++) for {var opt = document.createElement ("options"); Opt.value = i; Opt.textContent = I; List.appendChild (optional); }} Function Linglist () {var list = document.getElementById ("Gender"); List.innerHTML = ""; Var option = ["M", "F"]; (I = 0; i    

Comments

Popular posts from this blog

c - Mpirun hangs when mpi send and recieve is put in a loop -

python - Apply coupon to a customer's subscription based on non-stripe related actions on the site -

java - Unable to get JDBC connection in Spring application to MySQL -