php - how to call a sql variable in javascript selected by html onchange, canned response function -
what want able to:
--- have "on change" on drop list (containing table data "titles")
--- on change runs javascript function
--- javascript populates text area "message" column of data in same table corresponding title being selected in drop list.
<li><label for="frm_precan">canned response</label> <span class="input"> <select id="frm_precan" name="precan" onchange="updatetext();"> <option value="">--please select--</option> <?php foreach($precan_list $precan) : ?> <option value="<?=$precan['id'];?>"><?=$precan['name'];?></option> <?php endforeach; ?> </select> </span> </li> </ul> <textarea style="width: 100%; margin: 0; padding: 0; border-width: 1; font-family: courier;" name="message" rows="10" id="text_area"></textarea> <script type="text/javascript"> function updatetext() { var value = $("#frm_precan option:selected").text(); $('#text_area').val(value);; } </script>
this code, , can put selected title in text area. however, need data database according selected index of dropdown , fill textbox it. how can this?
you cannot fill textbox pure javascript. javascript works client-side , need access database on change of selection in dropdown menu. that, need recall same page on dropdown selection change. after data database, it's easy create textbox data "echo" command.
<? if (isset($_post['my_selection'])) { $result=mysql_query("select * `table` `column`='".mysql_real_escape_string($_post['my_selection'])."'"); $row=mysql_fetch_array($result); echo "<input type='text' value='".$row['column']."'>"; echo "<input type='text' value='".$row['column1']."'>"; } ?> <select name='my_selection'> existing select box here...
Comments
Post a Comment