How to display DropDown selected item text and TextBox text on Confirmation box using JavaScript

Last Reply on Feb 22, 2017 01:02 AM By amitsinghr

Posted on Feb 20, 2017 10:46 PM

Dear sir

Below code i am trying to show confirmation box regarding information for user

in there dropdown list it always show first dropdown item 

and text box empty data

but there is data

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        du.bindDropDown(ddlRoomNo, "spGetBookedRoom", "Value", "Id");
        du.bindDropDown(ddlRoomStatus, "spGetRoomStatus", "Value", "Id");   
    }
    // du.DataLoadToGridView("spCheckCheckOutData", GridViewCheckOutData);
}

protected void btnSubmit_Click(object sender, EventArgs e)
{

    string confirmValue = Request.Form["confirm_value"];
    if (confirmValue == "Yes")
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
    }
    else
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked No!')", true);

    }
}

HTML

 

<div class="form">
    <div class="validation-system">
        <div class="validation-form">
            <!---->
            <div class="vali-form">
                <div class="col-md-4">
                    <label class="control-label">
                        Room No</label>
                    <asp:DropDownList ID="ddlRoomNo" runat="server" CssClass="formInput">
                    </asp:DropDownList>
                </div>
                <div class="col-md-4" style="margin-left: auto; margin-right: auto;">
                    <label class="control-label">
                        Room Status</label>
                    <asp:DropDownList ID="ddlRoomStatus" runat="server" CssClass="formInput">
                    </asp:DropDownList>
                    <%-- <input id="txtName" type="text" placeholder="Firstname" runat="server" required="">--%>
                </div>
                <div class="col-md-4" style="margin-left: auto; margin-right: auto;">
                    <label class="control-label">
                        Remark</label>
                    <asp:TextBox ID="txtRemark" runat="server" placeholder="Your Remark" CssClass="formInput"
                        TextMode="MultiLine"></asp:TextBox>
                </div>
                <div class="clearfix">
                </div>
            </div>
            <div class="vali-form">
                <div class="col-md-4">
                    <label class="control-label">
                        Departure Date</label>
                    <asp:TextBox ID="txtDepartureDate" type="date" runat="server" class="form-control1 ng-invalid ng-invalid-required"
                        ng-model="model.date"></asp:TextBox>
                </div>
                <div class="clearfix">
                </div>
            </div>
            <br />
            <div class="vali-form" style="margin-left: 15px;">
                <div class="col-md-4">
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="Confirm()"
                        OnClick="btnSubmit_Click" class="btn btn-primary" />
                    <script type="text/javascript">
                        function Confirm() {
                            var confirm_value = document.createElement("INPUT");
                            confirm_value.type = "hidden";
                            confirm_value.name = "confirm_value";
                            if (confirm("Do you want to Checkout \n Room No :- <%=ddlRoomNo.SelectedItem.Text %> \n Room Status :- <%=ddlRoomStatus.SelectedItem.Text %> \n Departure Date :- <%=txtDepartureDate.Text %>")) {
                                confirm_value.value = "Yes";
                                document.forms[0].appendChild(confirm_value);
                            }
                            else {
                                confirm_value.value = "No";
                                document.forms[0].appendChild(confirm_value);
                            }
                        }
                    </script>
                    <asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" class="btn btn-default" />
                </div>
                <div class="clearfix">
                </div>
            </div>
        </div>
    </div>
</div>

SCRIPT

<script type="text/javascript">
    function Confirm() {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";
        if (confirm("Do you want to Checkout \n Room No :- <%=ddlRoomNo.SelectedItem.Text %> \n Room Status :- <%=ddlRoomStatus.SelectedItem.Text %> \n Departure Date :- <%=txtDepartureDate.Text %>")) {
            confirm_value.value = "Yes";
            document.forms[0].appendChild(confirm_value);
        }
        else {
            confirm_value.value = "No";
            document.forms[0].appendChild(confirm_value);
        }
    }
</script>

 

Posted on Feb 20, 2017 10:46 PM
Hi @amitsinghr,
Please try the following

Display Selected Items of List Box in TextBox using JavaScript

It might help you.

Cheers Andrea.

Posted on Feb 21, 2017 07:42 AM Modified on on Feb 21, 2017 07:43 AM
amitsinghr says:

Dear sir

Below code i am trying to show confirmation box regarding information for user

in there dropdown list it always show first dropdown item 

and text box empty data

but there is data

C#

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        du.bindDropDown(ddlRoomNo, "spGetBookedRoom", "Value", "Id");
        du.bindDropDown(ddlRoomStatus, "spGetRoomStatus", "Value", "Id");  
    }
    // du.DataLoadToGridView("spCheckCheckOutData", GridViewCheckOutData);
}
 
protected void btnSubmit_Click(object sender, EventArgs e)
{
 
    string confirmValue = Request.Form["confirm_value"];
    if (confirmValue == "Yes")
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked YES!')", true);
    }
    else
    {
        this.Page.ClientScript.RegisterStartupScript(this.GetType(), "alert", "alert('You clicked No!')", true);
 
    }
}

HTML

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
<div class="form">
    <div class="validation-system">
        <div class="validation-form">
            <!---->
            <div class="vali-form">
                <div class="col-md-4">
                    <label class="control-label">
                        Room No</label>
                    <asp:DropDownList ID="ddlRoomNo" runat="server" CssClass="formInput">
                    </asp:DropDownList>
                </div>
                <div class="col-md-4" style="margin-left: auto; margin-right: auto;">
                    <label class="control-label">
                        Room Status</label>
                    <asp:DropDownList ID="ddlRoomStatus" runat="server" CssClass="formInput">
                    </asp:DropDownList>
                    <%-- <input id="txtName" type="text" placeholder="Firstname" runat="server" required="">--%>
                </div>
                <div class="col-md-4" style="margin-left: auto; margin-right: auto;">
                    <label class="control-label">
                        Remark</label>
                    <asp:TextBox ID="txtRemark" runat="server" placeholder="Your Remark" CssClass="formInput"
                        TextMode="MultiLine"></asp:TextBox>
                </div>
                <div class="clearfix">
                </div>
            </div>
            <div class="vali-form">
                <div class="col-md-4">
                    <label class="control-label">
                        Departure Date</label>
                    <asp:TextBox ID="txtDepartureDate" type="date" runat="server" class="form-control1 ng-invalid ng-invalid-required"
                        ng-model="model.date"></asp:TextBox>
                </div>
                <div class="clearfix">
                </div>
            </div>
            <br />
            <div class="vali-form" style="margin-left: 15px;">
                <div class="col-md-4">
                    <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="Confirm()"
                        OnClick="btnSubmit_Click" class="btn btn-primary" />
                    <script type="text/javascript">
                        function Confirm() {
                            var confirm_value = document.createElement("INPUT");
                            confirm_value.type = "hidden";
                            confirm_value.name = "confirm_value";
                            if (confirm("Do you want to Checkout \n Room No :- <%=ddlRoomNo.SelectedItem.Text %> \n Room Status :- <%=ddlRoomStatus.SelectedItem.Text %> \n Departure Date :- <%=txtDepartureDate.Text %>")) {
                                confirm_value.value = "Yes";
                                document.forms[0].appendChild(confirm_value);
                            }
                            else {
                                confirm_value.value = "No";
                                document.forms[0].appendChild(confirm_value);
                            }
                        }
                    </script>
                    <asp:Button ID="btnReset" runat="server" Text="Reset" OnClick="btnReset_Click" class="btn btn-default" />
                </div>
                <div class="clearfix">
                </div>
            </div>
        </div>
    </div>
</div>

SCRIPT

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<script type="text/javascript">
    function Confirm() {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";
        if (confirm("Do you want to Checkout \n Room No :- <%=ddlRoomNo.SelectedItem.Text %> \n Room Status :- <%=ddlRoomStatus.SelectedItem.Text %> \n Departure Date :- <%=txtDepartureDate.Text %>")) {
            confirm_value.value = "Yes";
            document.forms[0].appendChild(confirm_value);
        }
        else {
            confirm_value.value = "No";
            document.forms[0].appendChild(confirm_value);
        }
    }
</script>

 

Hi amitsinghr,

Refer the below Script code for your reference for how to show selected Item text of dropdown also the textbox box value in alert box.

<script type="text/javascript">
    function Confirm() {
        var confirm_value = document.createElement("INPUT");
        confirm_value.type = "hidden";
        confirm_value.name = "confirm_value";

        var ddlRoomNo = document.getElementById('<%= ddlRoomNo.ClientID %>');
        var ddlRoomNoSelectedText = ddlRoomNo.options[ddlRoomNo.selectedIndex].innerHTML;    
        
        var ddlRoomStatus = document.getElementById('<%= ddlRoomStatus.ClientID %>');
        var ddlRoomStatusSelectedText = ddlRoomStatus.options[ddlRoomStatus.selectedIndex].innerHTML;

        var txtDepartureDate = document.getElementById('<%= txtDepartureDate.ClientID %>');
        var txtDepartureDateText = txtDepartureDate.value;        

        if (confirm("Do you want to Checkout \n Room No :- " + ddlRoomNoSelectedText + " \n Room Status :- " + ddlRoomStatusSelectedText + " \n Departure Date :- " +txtDepartureDateText)) {
            confirm_value.value = "Yes";
            document.forms[0].appendChild(confirm_value);
        }
        else {
            confirm_value.value = "No";
            document.forms[0].appendChild(confirm_value);
        }
    }
</script>

 

 


Posted on Feb 22, 2017 01:02 AM

<script type="text/javascript">
function Confirm() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
var dropRoomNo = document.getElementById('<%=ddlRoomNo.ClientID %>').options[document.getElementById('<%=ddlRoomNo.ClientID %>').selectedIndex].text;
var dropRoomStatus = document.getElementById('<%=ddlRoomStatus.ClientID %>').options[document.getElementById('<%=ddlRoomStatus.ClientID %>').selectedIndex].text;
var departureDate = document.getElementById('<%=txtDepartureDate.ClientID %>').value;
if (confirm("Do you want to Checkout \n Room No :-" + dropRoomNo + "\n Room Status :- " + dropRoomStatus + " \n Departure Date :- " + departureDate+"")) {
confirm_value.value = "Yes";
document.forms[0].appendChild(confirm_value);
}
else {
confirm_value.value = "No";
document.forms[0].appendChild(confirm_value);
}
}


</script>