user1667633
user1667633

Reputation: 4619

Select box in php not getting the selected value in jQuery

I have a select box like

<select id="addressbook_user" name="addressboook_user">
   <?php 
      $asql = "SELECT *  from demo_addressbook WHERE user_created_id IN(SELECT id FROM demo_user WHERE user_name = '$get_user_name') AND type = 1 ";                        
      //    $result = mysql_query($query);
      //    mysql_real_escape_string($asql);
      $aresult  = mysql_query($asql) or die (mysql_error());
      while($arow_list=mysql_fetch_assoc($aresult)){
   ?>                       
   <option value="<?php echo $arow_list['guest_name']; ?>"><?php echo $arow_list['guest_name']; ?></option>
   <?php                                    
      }
   ?>
</select>

Here is my jQuery code to get this value .

function save() {
    alert($("#addressboook_user").val());
    var selectVal = $('#addressboook_user :selected').val();
    alert(selectVal);
    var user = $("#addressboook_user").val();
}​

My question is when select box has a selected value then why my jQuery code alert is always showing undefined ?

please help me out here really got frustrated .

Upvotes: 0

Views: 418

Answers (1)

GBD
GBD

Reputation: 15981

You havn't used ID of select box

Change

alert($("#addressboook_user").val());

To

alert($("#addressbook_user").val());

Upvotes: 2

Related Questions