We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,586 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Get listbox values added via javascript on server side via hidden field...

Get listbox values added via javascript on server side via hidden field....
See more: ASP.NET
Get listbox values added via javascript on server side via hidden field....

2
Contributors
4
Replies
3 Days
Discussion Span
3 Months Ago
Last Updated
15
Views
korathualex
Light Poster
41 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Your main thing to do is get the hidden field's name correct in javascript, which you can do via view source of the page in IE or another browser. I would set the hidden field's value either on a button press which fires the function that does this or through a keypress event in javascript.

Hope that helps a little,
Larry

hometownnerd
Light Poster
37 posts since Sep 2007
Reputation Points: 21
Solved Threads: 4
Skill Endorsements: 3

Please provide a complete code of getting list box values added client side to server side...

korathualex
Light Poster
41 posts since Jan 2013
Reputation Points: 0
Solved Threads: 0
Skill Endorsements: 0

Can you post your code you are using to populate the listbox? It seems you are adding items dynamically on client and I can add code to that to fill the hidden field with the new entries.

Thanks,
Larry

hometownnerd
Light Poster
37 posts since Sep 2007
Reputation Points: 21
Solved Threads: 4
Skill Endorsements: 3

Ok, here is a mock up for you, it fires when the listbox has a different selection made, I do not know what code you are using to populate the listbox or what code you are using to add entries, you can place the code that is in the .change event into your jquery that adds new entries to the listbox.

<input type='hidden' name='ctl00$ContentPlaceHolder1$txtTest' id='ctl00_ContentPlaceHolder1_txtTest' class='txt'></input>
You will be able to pick up the listbox items by looking at the txtTest.value in your code behind
<select id='dropdown' class='dd'>
<OPTION VALUE="Cape Fear">Cape Fear
<OPTION VALUE="The Good, the Bad and the Ugly">The Good, the Bad and the Ugly
<OPTION VALUE="The Omen">The Omen
<OPTION VALUE="The Godfather">The Godfather
<OPTION VALUE="Forrest Gump">Forrest Gump
</select>
<script>
$('.dd').change(function () {
    //this fires when the listbox has a different selection made
    //you should put this where a new entry is created for the listbox
    var vals='|';//initialize the variable
    $('.dd').children().each(function() {
        vals=vals + $(this).val() + '|';//set the variable to the dropdownlist value
        }
});

//alert(vals);
    //the following line sets the class "txt" which is the textbox to the dropdownlist entries
$('.txt').val(vals);
});
</script>

You can change the <input type='hidden' to <input type='text' and then you can see the values filling in for testing. We will need to finetune it depending on what you are making and the variables you are using. Just remember to set the txtTest textbox cssClass to "txt" and set the listbox cssClass to "dd" that way you can reference them from jquery easier.

Let me know if you need more help,
Larry

hometownnerd
Light Poster
37 posts since Sep 2007
Reputation Points: 21
Solved Threads: 4
Skill Endorsements: 3

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page generated in 0.0657 seconds using 2.7MB