PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, April 22, 2022

[FIXED] how get value onchange event from drop down event in select(chosen) jquery

 April 22, 2022     cakephp-2.3, jquery, jquery-plugins, select     No comments   

Issue

i made drop down list with help of select jquery

echo $this->Form->input('Category', 
            array(
                'data-rel' =>'chosen',
                'style' => 'width:220px; margin-bottom:10px',
                'placeholder' => 'Select Category',
                'empty'=>'Select',
                'id'=>'ProductCategoryId',
                array('class'=>'required') 
                )); 

now i'm trying to retrieve value onchange i tried following code to get value and text. (my basic purpose is to get value)

<script>
$(document).ready(function () {
    alert($("#ProductCategoryId option:selected").text()); 
    alert($('#ProductCategoryId').val());
</script>

may be there are many answer of this question already on SO, but those did't resolve my problem.


Solution

Missing }); at the end, and you do need to listen to the change event.

Try this instead:

$(document).ready(function () {
    $('#ProductCategoryId').on('change', function() {
        alert( $('option:selected', this).text() ); 
        alert( $(this).val() );
    });
});


Answered By - PeterKA
Answer Checked By - Pedro (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing