Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i want to display a selected ddl value in label .

XML
<script type="text/javascript">
        $(document).ready(function () {
            function addtextboxes(ddlId, tbdivId) {
                var count = $("#" + tbdivId + " input").size();
                var requested = parseInt($("#" + ddlId).val(), 10);

                if (requested > count) {
                    for (i = count; i < requested; i++) {
                        var $ctrl = $('<input/>').attr({ type: 'text', name: 'text', value: 'text' });
                        $("#" + tbdivId).append($ctrl);
                    }
                }
                else if (requested < count) {
                    var x = requested - 1;
                    if (requested == 0)
                        $("#" + tbdivId + " input").remove();
                    else
                        $("#" + tbdivId + " input:gt(" + x + ")").remove();
                }
            }

            var counter = 0;
            $('#roomconfig').hide();

            var index = 0;
            $('#guestsRoomsSelect').change(function () {

                if ($(this).val() === '0') {

                    var $var2 = '<div id="dropdown2_ ' + (counter) + ' " class="class1"> <div class="wrapadults" style="float:left"> <label class="lbl_sm" style="font-size: 0.75em" for="adults">Adults</label>'
                    $var2 = $var2 + '<br/><span> <span>     <select id="adults" class="t_adults" style="margin-left:7px;margin-right:7px; border-right: 0.5px solid #FFFFFF;">      <option value="1">1</option>        <option value="2" selected="selected">2</option>'
                    $var2 = $var2 + '<option value="3">3</option>       <option value="4">4</option>        <option value="5">5</option>        <option value="6">6</option>        <option value="7">7</option>'
                    $var2 = $var2 + '<option value="8">8</option>       <option value="9">9</option>        <option value="10">10</option>      </select>     </span>       </span>  </div>'
                    $var2 = $var2 + '<div class="children" style="float:left" > <label class="lbl_sm" style="font-size: .75em;" for="children">Children</label><br/> <span>  <select id="hc_f_children" class="hc_evt_children " style="border-right: 0.5px solid #FFFFFF;">'
                    $var2 = $var2 + '<option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option>'
                    $var2 = $var2 + '<option value="4">4</option> </select> </span>  </div> <div id="chileage" class="ch"></div>  </div>  </div>';
                    $("#Addition").prepend('<fieldset id="' + counter + '" data-index="' + index + '">' + $var2 + '</fieldset>');

                    //$('#hc_f_children').bind('change', function () {
                    //    var divId = "chileage";
                    //    addtextboxes(this.id, divId);
                    //});
                    counter = counter + 1;
                    index++;

                    $('#roomconfig').show(300);

                }
                else if ($(this).val() === '1-1' || $(this).val() === '3-1' || $(this).val() === '4-1' || $(this).val() === '2-2' || $(this).val() === '2-1') {

                    $('#roomconfig').hide(300);

                    $('#Addition fieldset :first').remove();
                }

            });
            var forage = 0;
            $(".addRoom").click(function () {
                // on add room event

                var $var1 = '<div id="dropdown2_ ' + (counter) + ' " class="class1"> <div class="wrapadults" style="float:left"> '
                $var1 = $var1 + '<span> <span>      <select id="adults" class="t_adults" style="margin-left:7px;margin-right:7px; border-right: 0.5px solid #FFFFFF;">      <option value="1">1</option>        <option value="2" selected="selected">2</option>'
                $var1 = $var1 + '<option value="3">3</option>       <option value="4">4</option>        <option value="5">5</option>        <option value="6">6</option>        <option value="7">7</option>'
                $var1 = $var1 + '<option value="8">8</option>       <option value="9">9</option>        <option value="10">10</option>      </select>     </span>       </span>  </div>'
                $var1 = $var1 + '<div class="children" style="float:left" > <span>  <select id="hc_f_children_' + forage + '" class="hc_evt_children " style="border-right: 0.5px solid #FFFFFF;" onselect="getIdvalue()">'
                $var1 = $var1 + '<option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option>'
                $var1 = $var1 + '<option value="4">4</option> </select> </span>  </div> <div id="chileage_' + forage + '" class="ch"></div>  </div>'
                $var1 = $var1 + '<div class="btnrmv" id="' + counter + '" > <a class="removeRoom " style=" width:30px; height:0px; margin:0px;left:200px;position:relative; top:-30px; background-image:none; color:#b11500;font-weight:normal;font-size:0.77em;" href="javascript:void(0);">remove<span></span> </a> </div>';

                $("#Addition").append('<fieldset id="' + counter + '" data-index="' + index + '"' + $var1 + '</fieldset>');

                //$('#hc_f_children_' + forage).bind('change', function () {
                //    var divId = "chileage_" + this.id.replace('hc_f_children_', '');
                //    addtextboxes(this.id, divId);
                //});

                counter++;
                index++;
                forage++;
                // for remove element
                $(".btnrmv").click(function () {
                    $("#roomconfig fieldset#" + this.id).remove();
                    counter--;

                });

              //  var Idvalue = null;
                // Add childage textbox
                //function getIdvalue() {
                //    Idvalue = $('.hc_evt_children').attr("id");
                //}

                //$(Idvalue).change(function () {

                //    var index1 = $(".ch input").size();
                //    var requested = parseInt($(".hc_evt_children").val(), 5);

                //    if (requested > index1) {
                //        for (i = index1; i < requested; i++) {
                //            var $ctrl = $('<input/>').attr({ type: 'text', name: 'text', value: '' });
                //            $("#chileage_" + forage).append($ctrl);
                //        }
                //    }
                //    else if (requested < index1) {
                //        var x = requested - 1;
                //        $("#chileage_ input:gt(" + x + ")").remove();
                //    }
                //});


            });

        });

        //$("slctroom").append(" <asp:DropDownList>Test </asp:DropDownList>");
    </script>





aspx page --------------------


XML
 <div id="guestsRooms" class="clear">
        <label class="label1" for="guestsRoomsSelect">Guests:</label>
        <span>
            <span>
                <select id="guestsRoomsSelect"  name="GuestsRooms" style="width: 217; padding: 5px">
                    <option value="1-1">1 adult</option>
                    <option selected="selected" value="2-1">2 adults in 1 room</option>
                    <option value="3-1">3 adults in 1 room</option>
                    <option value="4-1">4 adults in 1 room</option>
                    <option value="2-2">2 adults in 2 rooms</option>
                    <option value="0">Need more rooms or have children?</option>
                </select>
            </span>
        </span>
    </div>

 <div id="roomconfig" class="roomconfig_fc">
<div id="Addition">

</div>


       <div class="btnWrap" style="clear:both;border-bottom: 0.5px solid #FFFFFF;">
<a class="addRoom"  style="background-image:none; color:darkred;height:20px; margin-left:0px" href="javascript:void(0);"><%--<img  src="../Images/SearchBox/image1.png" class="addimage "  />--%>
Add room</a>

</div>


    </div>






button ------------

<asp:Button class="MyButton" ID="btnBook" runat="server" Text="ADD" OnClick="btnBook_Click" Width="126px" />


when click on that button selected value should be display on label ?????
Posted
Updated 27-Aug-15 2:05am

Use OnClientClick of Button. For example.

<asp:button class="MyButton" id="btnBook" runat="server" text="ADD" onclientclick="myfun()" onclick="btnBook_Click" width="126px" xmlns:asp="#unknown">

HTML
<script>
  function myfun()
  {
   var e = document.getElementById("guestsRoomsSelect");
   var yourLabel = document.getElementById("yourLabelId");
   yourLabel  = e.options[e.selectedIndex].text;
  }
</script>


Regards,
AARIF SHAIKH
 
Share this answer
 
You can access form elements via their "name" property using Request.Form

C#
string val = Request.Form["GuestsRooms"]


Note you'll get the value of your dropdown, not the text, so you'll see "3-1" or something like that. If you want both then amend your options

XML
option value="3-1|3 adults in 1 room">3 adults in 1 room</option>


then on the server do a string.Split on the | to separate the value and the text. Google "c# string.Split" if you don't know how to use it.
 
Share this answer
 
Mark the as runat = 'Server', the control will get accessible at server side code in C#
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900