javascript - How to get the text value from my select populated with PHP -


i populated select dropdown menu mysql data using php

<select name="course" onchange="tester()">      <option>select course</option>       <?php $result= mysql_query('select distinct course tasks'); ?>        <?php while($row= mysql_fetch_assoc($result)) { ?>          <option value="<?php echo htmlspecialchars($row['course']);?>">              <?php echo htmlspecialchars($row['course']); ?>          </option>        <?php }        ?>  </select>  

to printed on change tester() function

<script type="text/javascript" >   function tester()   {     var testme = $('#course option:selected').text()     alert(testme);   } </script> 

to receive alert:

"the page @ localhost says: undefined" 

$('#course option:selected') isn't defined.

in html have:

<select name="course" onchange="tester()">  

if want use #course selector, need add id html code.

ie.

<select id="course" name="course" onchange="tester()">  

Comments

Popular posts from this blog

apache - Remove .php and add trailing slash in url using htaccess not loading css -

javascript - jQuery show full size image on click -