尝试从网页上的文本框中填充弹出窗口

时间:2019-02-14 14:54:36

标签: javascript asp.net

我在asp.net中使用JavaScript弹出窗口,需要显示网页上文本框中的变量。变量变回空白,所以我相信我缺少了一些东西。我认为我在document.getElementById中丢失了一些东西,或者我应该使用与我使用不正确的东西不同的东西

这是我的JavaScript

<!DOCTYPE html>

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

        var ppn = document.getElementById("<%= pifPassportNbr %>")
        var pid = document.getElementById("<%= pifIssueDate.Text %>")
        var pil = document.getElementById("<%= pifIssueLoc.Text %>")    
        var ped = document.getElementById("<%= pifExpirationDate.Text %>")        

        if (ppn == null || pid == null || pil == null || ped == null) {
            if (confirm(ppn + " " + pid + " " + pil + " " + ped)) {
                confirm_value.value = "Yes";
            }
            else {
                confirm_value.value = "No";
            }
            document.forms[0].appendChild(confirm_value);
        }
    }

    </script>

这是我的asp.net代码

   <tr>
                    <td style="padding-top: 5px;">
                        <asp:UpdatePanel ID="updPassport" runat="server" UpdateMode="Conditional" Visible="false" >
                            <ContentTemplate>
                                <asp:Table runat="server" ID="tblPassport" GridLines="Both" CellSpacing="0" BorderColor="Black" BorderStyle="Solid" 
                                        BorderWidth="1.5px" Font-Size="9pt">
                                    <asp:TableHeaderRow VerticalAlign="Bottom" Height="20px">
                                        <asp:TableHeaderCell ColumnSpan="2" CssClass="lblValueBlackFont" HorizontalAlign="Left" BackColor="#B0CCFF" >
                                            &nbsp<asp:Label ID="lblPassportTbl_Title" Text="Passport Information" runat="server" />
                                        </asp:TableHeaderCell>
                                        <asp:TableHeaderCell ID="thcPassport_Sync" runat="server" ColumnSpan="2" CssClass="lblValueBlackFont" HorizontalAlign="Right" BackColor="#B0CCFF" >
                                            <asp:Label ID="lblPassportSyncDate_Title" runat="server" Text="GIF Info Sync'd with TS: " Font-Size="8pt" Visible="False" />
                                            <asp:Label ID="lblPassportSyncDate" runat="server" Font-Size="8pt" Visible="False" />
                                            &nbsp<asp:Label ID="lblPassportSyncBy_Title" runat="server" Text="By: " Font-Size="8pt" Visible="False" />
                                            <asp:Label ID="lblPassportSyncBy" runat="server" Font-Size="8pt" Visible="False" />
                                            &nbsp
                                        </asp:TableHeaderCell>
                                    </asp:TableHeaderRow>
                                    <asp:TableHeaderRow VerticalAlign="Bottom" HorizontalAlign="Center" CssClass="gv_Header" Font-Size="9pt">
                                        <asp:TableHeaderCell runat="server" ID="thcPassport_Fields" Text=" Fields" />
                                        <asp:TableHeaderCell runat="server" ID="thcPassport_TS" Text="Existing Data in Travel Studio"  Width="350"/>
                                        <asp:TableHeaderCell runat="server" ID="thcPassport_PIF" Text="Data Submitted on GIF" Width="420" />
                                        <asp:TableHeaderCell runat="server" ID="thcPassport_Update" Text="Accept New Value" Width="75px" Font-Size="8pt" 
                                                ToolTip="When checked, TS data for the field will be updated with the data in the GIF column" />
                                    </asp:TableHeaderRow>
                                    <asp:TableRow VerticalAlign="Top" Font-Size="9pt" >
                                        <asp:TableCell>
                                            &nbsp
                                            <asp:TextBox ID="rhNationality" runat="server" ReadOnly="True" Text="Nationality:" BorderStyle="Solid" BorderColor="White" 
                                                    Font-Bold="True" Font-Size="8pt" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="tsNationality" runat="server" Text="No Existing Value" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Width="75%" />
                                            <asp:TextBox ID="tsNationalityID" runat="server" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Visible="false" />
                                            <asp:TextBox ID="tsPassportCountryID" runat="server" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Visible="false"/>
                                            <asp:TextBox ID="tsPassportID" runat="server" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Visible="false" />
                                        </asp:TableCell>
                                        <asp:TableCell VerticalAlign="Middle">
                                            <asp:TextBox ID="pifNationality" runat="server" Text="Nationality" BorderStyle="Solid" BorderColor="White" ToolTip="Value entered is not in available list. Please choose a correct value from the dropdown." ForeColor="Red" />    
                                            <asp:DropDownList ID="ddlNationality" runat="server" AutoPostBack="True" Width="75%" />                                    
                                            <asp:TextBox ID="pifNationalityID" runat="server" Text="ID" BorderStyle="Solid" BorderColor="White" Visible="false" />
                                            <asp:TextBox ID="pifNationalityCountryID" runat="server" Text="ID" BorderStyle="Solid" BorderColor="White" Visible="false" />
                                        </asp:TableCell><asp:TableCell HorizontalAlign="Center">
                                            <asp:CheckBox ID="ckbNationality" runat="server" Checked="false" />
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow VerticalAlign="Top">
                                        <asp:TableCell>
                                            &nbsp
                                            <asp:TextBox ID="rhPassportNbr" runat="server" ReadOnly="True" Text="Passport Number:" BorderStyle="Solid" 
                                                    BorderColor="White" Font-Bold="True" Font-Size="8pt" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="tsPassportNbr" runat="server" Text="No Existing Value" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Width="95%" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="pifPassportNbr" runat="server" Text="No Data Entered" BorderStyle="Solid" BorderColor="White" Width="95%" />
                                        </asp:TableCell>
                                        <asp:TableCell HorizontalAlign="Center">
                                            <asp:CheckBox ID="ckbPassportNbr" runat="server" Checked="false" />
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow VerticalAlign="Top">
                                        <asp:TableCell>
                                            &nbsp
                                            <asp:TextBox ID="rhPassportName" runat="server" ReadOnly="True" Text="Passport Name:" BorderStyle="Solid" BorderColor="White" 
                                                    Font-Bold="True" Font-Size="8pt" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="tsPassportName" runat="server" Text="No Existing Value" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Width="95%" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="pifPassportName" runat="server" Text="No Data Entered" BorderStyle="Solid" BorderColor="White" MaxLength="60" Width="100%" />
                                        </asp:TableCell>
                                        <asp:TableCell HorizontalAlign="Center">
                                            <asp:CheckBox ID="ckbPassportName" runat="server" Checked="false" />
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow VerticalAlign="Top">
                                        <asp:TableCell>
                                            &nbsp
                                            <asp:TextBox ID="rhIssueLoc" runat="server" ReadOnly="True" Text="Place of Issue:" BorderStyle="Solid" BorderColor="White" 
                                                    Font-Bold="True" Font-Size="8pt" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="tsIssueLoc" runat="server" Text="No Existing Value" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Width="95%" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="pifIssueLoc" runat="server" Text="No Data Entered" BorderStyle="Solid" BorderColor="White" MaxLength="50" Width="100%" />
                                        </asp:TableCell>
                                        <asp:TableCell HorizontalAlign="Center">
                                            <asp:CheckBox ID="ckbIssueLoc" runat="server" Checked="false" />
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow VerticalAlign="Top">
                                        <asp:TableCell>
                                            &nbsp
                                            <asp:TextBox ID="rhIssueDate" runat="server" ReadOnly="True" Text="Issue Date:" BorderStyle="Solid" BorderColor="White" 
                                                    Font-Bold="True" Font-Size="8pt" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="tsIssueDate" runat="server" Text="No Existing Value" ReadOnly="True" BorderStyle="Solid" BorderColor="White" Width="95%" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="pifIssueDate" runat="server" Text="No Data Entered" BorderStyle="Solid" BorderColor="White" Width="95%" />
                                            &nbsp&nbsp<asp:Label ID="pifIssueDate_Err" runat="server" Text="The value entered is not a date. Please use mm/dd/yyyy format." Font-Size="7pt" CssClass="lblValueRed" Visible="False" />
                                        </asp:TableCell>
                                        <asp:TableCell HorizontalAlign="Center">
                                            <asp:CheckBox ID="ckbIssueDate" runat="server" Checked="false" />
                                        </asp:TableCell>
                                    </asp:TableRow>
                                    <asp:TableRow VerticalAlign="Top">
                                        <asp:TableCell>
                                            &nbsp
                                            <asp:TextBox ID="rhExpirationDate" runat="server" ReadOnly="True" Text="Expiration Date:" BorderStyle="Solid" BorderColor="White" 
                                                    Font-Bold="True" Font-Size="8pt" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="tsExpirationDate" runat="server" Text="No Existing Value" ReadOnly="True" BorderStyle="Solid" BorderColor="White" />
                                        </asp:TableCell>
                                        <asp:TableCell>
                                            <asp:TextBox ID="pifExpirationDate" runat="server" Text="No Data Entered" BorderStyle="Solid" BorderColor="White" />
                                            &nbsp&nbsp
                                            <asp:Label ID="pifExpDate_Err" runat="server" Text="The value entered is not a date. Please use mm/dd/yyyy format." Font-Size="7pt" CssClass="lblValueRed" Visible="False" />                                        
                                        </asp:TableCell>
                                        <asp:TableCell HorizontalAlign="Center">
                                            <asp:CheckBox ID="ckbExpirationDate" runat="server" Checked="false" />
                                        </asp:TableCell>
                                        </asp:TableRow></asp:Table><table width="98%" cellpadding="20px" style="margin-top: 5px;margin-bottom: 3px" >
                                    <tr valign="middle">
                                        <td>
                                            <asp:Label runat="server" ID="lblPassportUpdateMsg" Text="Unable to create or update this passenger's passport data." 
                                                    CssClass="ErrorMessageRed" Width="100%" />
                                            <asp:Label ID="lblNationality" runat="server" Text="  *Invalid Nationality " Font-Size="8pt" Visible="False" Font-Bold="True" ForeColor="Red" />
                                        </td>
                                        <td align="right">
                                            <asp:Button ID="btnPassportUpdate" visible = "true" text="Update" CssClass="btnUpdate" runat="server" OnClientClick="Confirm()"/>
                                        </td>
                                    </tr>
                                </table> 
                            </ContentTemplate>
                        </asp:UpdatePanel>
                    </td>
                </tr>

1 个答案:

答案 0 :(得分:1)

在您的JavaScript中,您似乎正在根据文本框值(textbox_id.Text)选择文档ID?尝试选择文本框的client id属性,然后选择javascript文本值。像这样:

var ppn = document.getElementById("<%= pifPassportNbr.ClientID %>").value;
var pid = document.getElementById("<%= pifIssueDate.ClientID %>").value;
var pil = document.getElementById("<%= pifIssueLoc.ClientID %>").value;
var ped = document.getElementById("<%= pifExpirationDate.ClientID %>").value;