javascript - How to save select value of dropdown to MySQl table -
i have 2 drop down. in 2nd drop down items added dynamically based on 1st drop down selection.
now want selected value of 5th subject store in mysql table. not able value of option selected in 2nd drop down.
how can selected value items dynamically added in option tag
here code
<script> function setsubject(objlanguage) { var objmedia = document.getelementbyid("5thsub"); objmedia.options.length = 0; objmedia.disabled = false; switch (objlanguage.value) { case "humanity": objmedia.options.add(new option("hindi")); objmedia.options.add(new option("ip")); break; case "commerce": objmedia.options.add(new option("ip")); objmedia.options.add(new option("other")); break; case "sci[pcm]": objmedia.options.add(new option("cs")); objmedia.options.add(new option("ip")); break; case "sci[pcb]": objmedia.options.add(new option("ip")); objmedia.options.add(new option("math")); break; default: objmedia.options.add(new option("select")); objmedia.disabled = true; break; } } </script> <tr> <td>stream : <select name="stream" id="stream" onchange="setsubject(this)"> <option> select</option> <option value="humanity">humanity</option> <option value="commerce">commerce</option> <option value="sci[pcm]">sci[pcm]</option> <option value="sci[pcb]">sci[pcb]</option> </select> </td> <td>5th subjects : <select name="5thsub" id="5thsub" disabled="disabled"> <option>select</option> </select> </td> </tr>
part of form data passed savedata.php file saving value.
<td>category : <select name="cast_cate" > <option value="gen"<?php if(isset($_post['cast_cate'])){if($_post['cast_cate']=="gen"){?>selected <?php }} ?>>general</option> <option value="sc" <?php if(isset($_post['cast_cate'])){if($_post['cast_cate']=="sc"){?>selected <?php }} ?>>sc</option> <option value="st" <?php if(isset($_post['cast_cate'])){if($_post['cast_cate']=="st"){?>selected <?php }} ?>>st</option> <option value="crem" <?php if(isset($_post['cast_cate'])){if($_post['cast_cate']=="crem"){?>selected <?php }} ?>>obc - creamy</option> <option value="ncrem" <?php if(isset($_post['cast_cate'])){if($_post['cast_cate']=="ncrem"){?>selected <?php }} ?>>obc - non-creamy</option> </select> </td>
you can add "hidden" input object contains value of second select box, , write simple function assign value box:
add js:
function setvalue() { document.getelementbyid("selected_value").value = document.getelementbyid("5thsub").value; }
than change first select box, run function:
<select name="stream" id="stream" onchange="setsubject(this);setvalue()">
last, make second select box run function:
<select name="5thsub" id="5thsub" disabled="disabled" onchange="setvalue();">
now reading selected value easier you.
Comments
Post a Comment