1,105,625 Community Members

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

Member Avatar
korathualex
Light Poster
41 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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....

Member Avatar
hometownnerd
Junior Poster in Training
50 posts since Sep 2007
Reputation Points: 13 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 4 [?]
 
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

Member Avatar
korathualex
Light Poster
41 posts since Jan 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

Member Avatar
hometownnerd
Junior Poster in Training
50 posts since Sep 2007
Reputation Points: 13 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 4 [?]
 
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

Member Avatar
hometownnerd
Junior Poster in Training
50 posts since Sep 2007
Reputation Points: 13 [?]
Q&As Helped to Solve: 6 [?]
Skill Endorsements: 4 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article