php - Appending html select box to page that is populated with MYSQL query results -
php - Appending html select box to page that is populated with MYSQL query results -
normally when creating dynamically populated drop-downs i'd utilize simple foreach loop below data:
<select name="region" id="region" tabindex="1"> <option value="">select course</option> <?php foreach ( $courses $course ) : ?> <option value="<?php echo $course->coursename; ?>"><?php echo $course->coursename; ?></option> <?php endforeach; ?> </select> *where $courses = select("select * courses");
etc etc
what i'm not sure possible utilize in current form within javascript function such 1 below i've been using on forms append additional input fields per requirements of user. works fine text input, illustration (and below can utilize if type out each input alternative manually) i'm not @ sure best way recreate php/mysql illustration above javascript doesn't in way. i've tried whether done ajax have not been able find examples of i'm trying do.
<script type="text/javascript"> var count = 0; $(function(){ $('p#add_field').click(function(){ count += 1; $('#container').append( '<h4>link #' + count + '</h4> ' +'<select id="field_' + count + '" name="fields[]">' + '<option>select course</option>'+'</select>'); }); }); </script>
many advice best way this.
update - managed reply own question - solution per code below.
<script type="text/javascript"> var count = 0; $(function(){ $('p#add_field').click(function(){ count += 1; $('#container2').append( '<strong>golf course of study ' + count + '</strong>   ' +'<select id="field_' + count + '" name="fields[]">' + "<?php foreach ( $courses $course ) { $name = $course->coursename; ?>"+"<?php echo '<option value=\''.htmlspecialchars($name).'\'>'.$name.'</option>'; ?>"+"<?php } ?>"+'</select><br />') }); }); </script>
php javascript mysql database append
Comments
Post a Comment