Get in touch with our hands-on, fast and professional Support Team

  • This topic is empty.
Viewing 15 posts - 16 through 30 (of 31 total)
  • Author
    Posts
  • #9364

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    This work for me:

    $("#city :selected").text();
    

    I’m using jQuery 1.10.2

    #9365

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    the following worked for me:

    $.trim($('#dropdownId option:selected').html())
    
    #9369

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    Select Text and selected value on dropdown/select change event in jQuery

    $("#yourdropdownid").change(function() {
        console.log($("option:selected", this).text()); //text
        console.log($(this).val()); //value
    })
    
    #9370

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    For getting selected value use

    $('#dropDownId').val();
    

    and for getting selected item text use this line:

    $("#dropDownId option:selected").text();
    
    #9361

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster
    $(function () {
      alert('.val() = ' + $('#selectnumber').val() + '  AND  html() = ' + $('#selectnumber option:selected').html() + '  AND .text() = ' + $('#selectnumber option:selected').text());
    });
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <html xmlns="http://www.w3.org/1999/xhtml">
      <head runat="server">
        <title></title>
    
      </head>
      <body>
        <form id="form1" runat="server">
          <div>
            <select id="selectnumber">
              <option value="1">one</option>
              <option value="2">two</option>
              <option value="3">three</option>
              <option value="4">four</option>
            </select>
    
          </div>
        </form>
      </body>
    </html>

    Click to see OutPut Screen

    #9367

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster
    var e = document.getElementById("dropDownId");
    var div = e.options[e.selectedIndex].text;
    
    #9359

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    If you want the result as a list, then use:

    x=[];
    $("#list_id").children(':selected').each(function(){x.push($(this).text());})
    
    #9371

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    Try:

    $var = jQuery("#dropdownid option:selected").val();
       alert ($var);
    

    Or to get the text of the option, use text():

    $var = jQuery("#dropdownid option:selected").text();
       alert ($var);
    

    More Info:

    #9358

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    For multi-selects:

    $("#yourdropdownid :selected").map(function(i, v) { return $.trim($(v).text()); }
    
    #9360

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster
    $("#dropdownid option:selected").text();
    

    if you use asp.net and write

    <Asp:dropdownlist id="ddl" runat="Server" />
    

    then you should use

    $('#<%=ddl.Clientid%> option:selected').text();
    
    #9372

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    Simply try the following code.

    var text= $('#yourslectbox').find(":selected").text();
    

    it returns the text of the selected option.

    #9357

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    Just add the below line

    $(this).prop('selected', true);
    

    replaced .att to .prop it worked for all browsers.

    #9373

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster
    $("#dropdown").find(":selected").text();
    
    
    $("#dropdown :selected").text();
    

    $("#dropdown option:selected").text();

    $("#dropdown").children(":selected").text();
    
    #9362

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    Try

    dropdown.selectedOptions[0].text
    
    function read() {
      console.log( dropdown.selectedOptions[0].text );
    }
    <select id="dropdown">
      <option value="1">First</option>
      <option value="2">Second</option>
    </select>
    <button onclick="read()">read</button>
    #9376

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131

    Deprecated: Function seems_utf8 is deprecated since version 6.9.0! Use wp_is_valid_utf8() instead. in /home/u337135316/domains/bzotech.com/public_html/wp-includes/functions.php on line 6131
    David Hoang
    Keymaster

    This code worked for me.

    $("#yourdropdownid").children("option").filter(":selected").text();
    
Viewing 15 posts - 16 through 30 (of 31 total)
  • You must be logged in to reply to this topic.