php - Display related data from database based on dropdown selection JavaScript -
in task want select 1 name drop down. want print technology related name in other div tag. don't know how this. data data base dropdown option. here code.
candidate name: <select name="candidate_id" class="form-control" id="can_name" value="<?php echo set_value('candidate_id');?>"palceholder="candidate full name" required> <option></option> <?php foreach ($candidate $r): ?> <option value="<?php echo $r->candidate_id; ?>"><?php echo $r->candidate_name." "; ?></option> <?php endforeach; ?> </select> </select> <div class="error"><?php echo form_error("candidate_name");?></div><br> <div></div><br> <!-- here want print technology related canididate name -->
let's use jquery library, simplify syntax of want considerably.
you include in page this:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
this pull in recent minified version of 1.x branch of library.
then need select. say, let's use below ex.
let's use select anyway, can change if isn't correct:
<label for="meetingplace">meeting place: </label> <select id="meetingplace"> <option>please select</option> <option>buckingham palace</option> <option>the white house</option> <option>mount everest</option> </select>
with in place need hook select's on change event. can in javascript:
$("#meetingplace").on("change", function(){ // code fire every time user selects })
all select element id of "#meetingplace" , declare anonymous function should run every time user selects different.
as final step post, let's have js output user selected page.
create div id of "results":
<div id="results"></div>
then within onchange callback add following code:
var selected = $(this).val(); $("#results").html("you selected: " + selected);
what assign value of selected option element variable, set innerhtml of results accordingly.
Comments
Post a Comment