javascript - Generate option select on input change -
<select id="gameid"> //<option number 1-999> </select> <select id="netid"> //<option number 1-999> </select> <select id="camp_id"> <script> var = $("#gameid").val(); var b = $("#netid").val(); var c = a+b; (var = 1; i<=999; i++) { document.write("<option value='"+c+i+"'>"+c+i+"</option>"); } </script> </select>
the code above generate options selection.
what want there is, if val in #gameid changed, option list change too, , #netid.
however, option doesn't change. stay in default value of #gameid , #netid.
i don't know missing here. need help, please.
[update]
this code work. however, when second change on #cameid after have been select, doesn't change #campid selection anymore. change again if change on #netid.
$("#gameid" && "#netid").on('change', function(){ = $("#gameid").val(), b = $("#netid").val(), c = a+b; $("#camp_id").empty(); (var = 1; i<=999; i++){ $("#camp_id").append("<option value='"+(c+i)+"'>"+(c+i)+"</option>"); } });
don't forget add jquery library,
<select id="gameid" onchange="generateoptions();"> <!-- options --> </select> <select id="netid" onchange="generateoptions();"> <!-- options --> </select> <select id="camp_id"> </select> <script type="text/javascript"> var a,b,c,str=""; function generateoptions() { = $("#gameid").val(); b = $("#netid").val(); c = a+b; (var = 1; i<=999; i++) { str= str + "<option value='"+c+i+"'>"+c+i+"</option>"; } $('#camp_id').html(str); } </script>