How to get value of selected items from listbox and storing into a variable











up vote
0
down vote

favorite












I use a list box and its item comes from the database i looped it over using while loop. All i want is when I select an item from the dropdown listbox, i can also get other selected item value from the database. Like in the picture, if i select an item in the drop down i need to get its quantity from the database. Thanks










share|improve this question




















  • 2




    What have you tried so far? Are you using any Framework?
    – Nebi
    Nov 22 at 7:57










  • No im not im just using native php code. I already have the database value into my drop down. What i dont know is that how can i get the quantity of the selected items. (The quantity is also on the database)
    – Charlie Matanguihan
    Nov 22 at 8:00










  • @Nebi can you recommend some documentation on how to solve my problem?
    – Charlie Matanguihan
    Nov 22 at 8:02










  • Native PHP? You mean Core PHP? Ok then you can do. there are 3 methods. 1.using AJAX and 2.using pre-loaded Javascript Array and 3. Add a custom Data-Property. Choose a method (It depends on how large is your data)
    – Banujan Balendrakumar
    Nov 22 at 8:04

















up vote
0
down vote

favorite












I use a list box and its item comes from the database i looped it over using while loop. All i want is when I select an item from the dropdown listbox, i can also get other selected item value from the database. Like in the picture, if i select an item in the drop down i need to get its quantity from the database. Thanks










share|improve this question




















  • 2




    What have you tried so far? Are you using any Framework?
    – Nebi
    Nov 22 at 7:57










  • No im not im just using native php code. I already have the database value into my drop down. What i dont know is that how can i get the quantity of the selected items. (The quantity is also on the database)
    – Charlie Matanguihan
    Nov 22 at 8:00










  • @Nebi can you recommend some documentation on how to solve my problem?
    – Charlie Matanguihan
    Nov 22 at 8:02










  • Native PHP? You mean Core PHP? Ok then you can do. there are 3 methods. 1.using AJAX and 2.using pre-loaded Javascript Array and 3. Add a custom Data-Property. Choose a method (It depends on how large is your data)
    – Banujan Balendrakumar
    Nov 22 at 8:04















up vote
0
down vote

favorite









up vote
0
down vote

favorite











I use a list box and its item comes from the database i looped it over using while loop. All i want is when I select an item from the dropdown listbox, i can also get other selected item value from the database. Like in the picture, if i select an item in the drop down i need to get its quantity from the database. Thanks










share|improve this question















I use a list box and its item comes from the database i looped it over using while loop. All i want is when I select an item from the dropdown listbox, i can also get other selected item value from the database. Like in the picture, if i select an item in the drop down i need to get its quantity from the database. Thanks







php sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 at 10:58









Sanal Sunny

6548




6548










asked Nov 22 at 7:54









Charlie Matanguihan

467




467








  • 2




    What have you tried so far? Are you using any Framework?
    – Nebi
    Nov 22 at 7:57










  • No im not im just using native php code. I already have the database value into my drop down. What i dont know is that how can i get the quantity of the selected items. (The quantity is also on the database)
    – Charlie Matanguihan
    Nov 22 at 8:00










  • @Nebi can you recommend some documentation on how to solve my problem?
    – Charlie Matanguihan
    Nov 22 at 8:02










  • Native PHP? You mean Core PHP? Ok then you can do. there are 3 methods. 1.using AJAX and 2.using pre-loaded Javascript Array and 3. Add a custom Data-Property. Choose a method (It depends on how large is your data)
    – Banujan Balendrakumar
    Nov 22 at 8:04
















  • 2




    What have you tried so far? Are you using any Framework?
    – Nebi
    Nov 22 at 7:57










  • No im not im just using native php code. I already have the database value into my drop down. What i dont know is that how can i get the quantity of the selected items. (The quantity is also on the database)
    – Charlie Matanguihan
    Nov 22 at 8:00










  • @Nebi can you recommend some documentation on how to solve my problem?
    – Charlie Matanguihan
    Nov 22 at 8:02










  • Native PHP? You mean Core PHP? Ok then you can do. there are 3 methods. 1.using AJAX and 2.using pre-loaded Javascript Array and 3. Add a custom Data-Property. Choose a method (It depends on how large is your data)
    – Banujan Balendrakumar
    Nov 22 at 8:04










2




2




What have you tried so far? Are you using any Framework?
– Nebi
Nov 22 at 7:57




What have you tried so far? Are you using any Framework?
– Nebi
Nov 22 at 7:57












No im not im just using native php code. I already have the database value into my drop down. What i dont know is that how can i get the quantity of the selected items. (The quantity is also on the database)
– Charlie Matanguihan
Nov 22 at 8:00




No im not im just using native php code. I already have the database value into my drop down. What i dont know is that how can i get the quantity of the selected items. (The quantity is also on the database)
– Charlie Matanguihan
Nov 22 at 8:00












@Nebi can you recommend some documentation on how to solve my problem?
– Charlie Matanguihan
Nov 22 at 8:02




@Nebi can you recommend some documentation on how to solve my problem?
– Charlie Matanguihan
Nov 22 at 8:02












Native PHP? You mean Core PHP? Ok then you can do. there are 3 methods. 1.using AJAX and 2.using pre-loaded Javascript Array and 3. Add a custom Data-Property. Choose a method (It depends on how large is your data)
– Banujan Balendrakumar
Nov 22 at 8:04






Native PHP? You mean Core PHP? Ok then you can do. there are 3 methods. 1.using AJAX and 2.using pre-loaded Javascript Array and 3. Add a custom Data-Property. Choose a method (It depends on how large is your data)
– Banujan Balendrakumar
Nov 22 at 8:04














2 Answers
2






active

oldest

votes

















up vote
0
down vote













If you use Jquery framework,you can get it like this



1:var options=$(“your css selector”); //choose the item

2:options.val(); //selected value

3:options.text(); //selected text





share|improve this answer





















  • Can you explain your code please?
    – Banujan Balendrakumar
    Nov 22 at 8:07










  • Is it inside form? if so you can grab the value using $_post['fieldname'] or $_GET['fieldname']
    – Birhan Nega
    Nov 22 at 11:22


















up vote
0
down vote













You can try like -




  1. Try getting selected item's div class. Suppose could be "selected"


  2. Get div value by below -



    var selectedListval = $("#ddlist").find('.selected').val();



  3. Do null check for selectedListval and execute ajax call to function - which will serve purpose of fetching quality of selected dropdown item Refer http://api.jquery.com/jquery.ajax/
    for ajax syntax.


  4. after null check ,bind Quantity value to the Quantity textbox.



Hope this helps you.






share|improve this answer





















  • Thanks! @Bharati
    – Charlie Matanguihan
    Nov 22 at 11:06











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426192%2fhow-to-get-value-of-selected-items-from-listbox-and-storing-into-a-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote













If you use Jquery framework,you can get it like this



1:var options=$(“your css selector”); //choose the item

2:options.val(); //selected value

3:options.text(); //selected text





share|improve this answer





















  • Can you explain your code please?
    – Banujan Balendrakumar
    Nov 22 at 8:07










  • Is it inside form? if so you can grab the value using $_post['fieldname'] or $_GET['fieldname']
    – Birhan Nega
    Nov 22 at 11:22















up vote
0
down vote













If you use Jquery framework,you can get it like this



1:var options=$(“your css selector”); //choose the item

2:options.val(); //selected value

3:options.text(); //selected text





share|improve this answer





















  • Can you explain your code please?
    – Banujan Balendrakumar
    Nov 22 at 8:07










  • Is it inside form? if so you can grab the value using $_post['fieldname'] or $_GET['fieldname']
    – Birhan Nega
    Nov 22 at 11:22













up vote
0
down vote










up vote
0
down vote









If you use Jquery framework,you can get it like this



1:var options=$(“your css selector”); //choose the item

2:options.val(); //selected value

3:options.text(); //selected text





share|improve this answer












If you use Jquery framework,you can get it like this



1:var options=$(“your css selector”); //choose the item

2:options.val(); //selected value

3:options.text(); //selected text






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 8:05









Mr.xu

11




11












  • Can you explain your code please?
    – Banujan Balendrakumar
    Nov 22 at 8:07










  • Is it inside form? if so you can grab the value using $_post['fieldname'] or $_GET['fieldname']
    – Birhan Nega
    Nov 22 at 11:22


















  • Can you explain your code please?
    – Banujan Balendrakumar
    Nov 22 at 8:07










  • Is it inside form? if so you can grab the value using $_post['fieldname'] or $_GET['fieldname']
    – Birhan Nega
    Nov 22 at 11:22
















Can you explain your code please?
– Banujan Balendrakumar
Nov 22 at 8:07




Can you explain your code please?
– Banujan Balendrakumar
Nov 22 at 8:07












Is it inside form? if so you can grab the value using $_post['fieldname'] or $_GET['fieldname']
– Birhan Nega
Nov 22 at 11:22




Is it inside form? if so you can grab the value using $_post['fieldname'] or $_GET['fieldname']
– Birhan Nega
Nov 22 at 11:22












up vote
0
down vote













You can try like -




  1. Try getting selected item's div class. Suppose could be "selected"


  2. Get div value by below -



    var selectedListval = $("#ddlist").find('.selected').val();



  3. Do null check for selectedListval and execute ajax call to function - which will serve purpose of fetching quality of selected dropdown item Refer http://api.jquery.com/jquery.ajax/
    for ajax syntax.


  4. after null check ,bind Quantity value to the Quantity textbox.



Hope this helps you.






share|improve this answer





















  • Thanks! @Bharati
    – Charlie Matanguihan
    Nov 22 at 11:06















up vote
0
down vote













You can try like -




  1. Try getting selected item's div class. Suppose could be "selected"


  2. Get div value by below -



    var selectedListval = $("#ddlist").find('.selected').val();



  3. Do null check for selectedListval and execute ajax call to function - which will serve purpose of fetching quality of selected dropdown item Refer http://api.jquery.com/jquery.ajax/
    for ajax syntax.


  4. after null check ,bind Quantity value to the Quantity textbox.



Hope this helps you.






share|improve this answer





















  • Thanks! @Bharati
    – Charlie Matanguihan
    Nov 22 at 11:06













up vote
0
down vote










up vote
0
down vote









You can try like -




  1. Try getting selected item's div class. Suppose could be "selected"


  2. Get div value by below -



    var selectedListval = $("#ddlist").find('.selected').val();



  3. Do null check for selectedListval and execute ajax call to function - which will serve purpose of fetching quality of selected dropdown item Refer http://api.jquery.com/jquery.ajax/
    for ajax syntax.


  4. after null check ,bind Quantity value to the Quantity textbox.



Hope this helps you.






share|improve this answer












You can try like -




  1. Try getting selected item's div class. Suppose could be "selected"


  2. Get div value by below -



    var selectedListval = $("#ddlist").find('.selected').val();



  3. Do null check for selectedListval and execute ajax call to function - which will serve purpose of fetching quality of selected dropdown item Refer http://api.jquery.com/jquery.ajax/
    for ajax syntax.


  4. after null check ,bind Quantity value to the Quantity textbox.



Hope this helps you.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 22 at 9:02









Bharati Mathapati

543




543












  • Thanks! @Bharati
    – Charlie Matanguihan
    Nov 22 at 11:06


















  • Thanks! @Bharati
    – Charlie Matanguihan
    Nov 22 at 11:06
















Thanks! @Bharati
– Charlie Matanguihan
Nov 22 at 11:06




Thanks! @Bharati
– Charlie Matanguihan
Nov 22 at 11:06


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426192%2fhow-to-get-value-of-selected-items-from-listbox-and-storing-into-a-variable%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Contact image not getting when fetch all contact list from iPhone by CNContact

count number of partitions of a set with n elements into k subsets

A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks