tags:

views:

45

answers:

3

Hi!

I wrote a script that changes text based on user selection, which is working fine. I am not sure how using Jquery to capture the user selected selection and pass the value below to the hidden field ie replace the value="100" with the user selected value example value="trade"? -thanks

JQUERY

    $(document).ready(function() {    
        $('#trade').click(function() {
            $('#form').attr("class","trade");    //trade selected
            $('#trade').addClass("current");
            $('.lblMadlib112').text("some text1");// adds some text to this field           

         });

$('#football').click(function() {
            $('#formr').attr("class","football");//football    
            $('#football').addClass("current");
                       $('.lblMadlib112').text("some text here");// adds some text to this field      



         });

});

.NET stuff

<asp:HiddenField ID="hdnThemeId" runat="server" Value="100" />
A: 

You can give that control a class, like this:

<asp:HiddenField ID="hdnThemeId" CssClass="hdnThemeId" runat="server" Value="100" />

Then select it that way and use .val() to set the value, like this:

$('#trade').click(function() {
  $('#form').attr("class","trade");
  $('#trade').addClass("current");
  $('.lblMadlib112').text("some text1");
  $('.hdnThemeId').val("some value");
});
Nick Craver
Thanks . I wanted to replace the value="100" with teh user selected value for example trade.
@user244394 -is `#trade` an input or...?
Nick Craver
trade is one of the values that user clicks. i want to capture and change the value="100" with the "trade" value or value of "football", depending what the user clicked. so that the value becomes value="trade" or value="football"
@user244394 - ah in that case use the code above, just replace `$('.hdnThemeId').val("some value");` with `$('.hdnThemeId').val("trade");`
Nick Craver
A: 
$('#hdnThemeId').val($('#trade').val());
XSaint32
This is ASP.Net, that ID isn't guaranteed to stay `hdnThemeId`.
Nick Craver
The latest version of .NET allows for controlling how IDs are generated: http://weblogs.asp.net/scottgu/archive/2010/03/30/cleaner-html-markup-with-asp-net-4-web-forms-client-ids-vs-2010-and-net-4-0-series.aspx
XSaint32
A: 

like

<span id='football' rel='football_value'>football</span>

and

$('#football').click(function() {
            $('#formr').attr("class","football");//football    
            $('#football').addClass("current");
            $('.lblMadlib112').text("some text here");// adds some text to this field 
            $('#hdnThemeId').val($(this).attr('rel'));     



         });

});
FatherStorm
Thanks...I forgot to add i want to change the value="100" with the user selected value. - thnaks