在新标签中有条件地打开网址

时间:2015-04-23 14:17:59

标签: javascript html asp-classic

如果选中了复选框,我有一个当前重定向的页面,然后提交"提交"点击按钮:

if  request.Form("myCheckbox") = "on" then
        response.Redirect("/newPage.asp?txt="staff"")
else
        response.Redirect("/thisPage.asp")
end if

如果选中该复选框,我希望它在新标签页中打开。 我从这里的类似问题中得知,这不能用HTML完成,最好用Javascript实现,但不清楚如何超越以下内容:

function sendForm(action){
     if (document.getElementById('myCheckbox').checked) {
         window.open('/newPage.asp?txt="staff"', '_blank')
     }
}

我知道它错了,因为它停留在同一页面上但是我已经管理过了。 有人能告诉我我做错了吗?

1 个答案:

答案 0 :(得分:2)

正如您所知,使用Classic ASP无法从服务器打开新的选项卡/窗口。

你的'window.open'行是正确的,应该触发,所以我认为问题在于你的复选框的功能和/或ID。

有关工作示例,请参阅我的JSFiddle,或查看以下代码。

   public frmVoucher()
    {
        InitializeComponent();
        DoNewVoucher();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

        txtVDt.Text = DateTime.Today.ToString();

    }

   public void DoNewVoucher()
    {
        vr.VoucherType = 1;
        ds = vr.NewVoucher();



        //Create New binding source for Order
        bs = new BindingSource();
        //Create New binding source for Order Details
        bsDet = new BindingSource();
        //Set Order binding source to Dataset ds
        bs.DataSource = ds;
        //Set Order Data Member to Dataset ds table "Orders"
        bs.DataMember = "vMaster";
        //Set Order Details binding source to Order's Binding Source
        bsDet.DataSource = bs;
        //Set Order Data Member to Dataset's Relationship for data integrity
        bsDet.DataMember = "VouchersToVoucherDetails";

        BindControls();



        bs.AddNew();
        txtVDt.Text = DateTime.Today.ToString();
     //   txtChqDt.Text = DateTime.Today.ToString();

    }

public void BindControls()
    {


        txtvTypeID.Text = null;
        txtVType.Text = null;
        txtVNum.Text = null;
        txtVDesc.Text = null;
        txtVDt.Text = null;
        if (vr.VoucherType == 1)
        {
            txtChqNo.Text = null;
            txtChqDt.Text = null;
            txtDrAcc.Text = null;
            txtDrAccDesc.Text = null;
            txtCrAcc.Text = null;
            txtCrAccDesc.Text = null;
            txtPayName.Text = null;
            txtAmount.Text = null;
        }


        txtRemarks.Text = null;


        txtTransID.DataBindings.Clear();
        txtvTypeID.DataBindings.Clear();
        txtVType.DataBindings.Clear();
        txtVNum.DataBindings.Clear();
        txtVDt.DataBindings.Clear();
        if (vr.VoucherType == 1)
        {
            txtChqNo.DataBindings.Clear();
            txtChqDt.DataBindings.Clear();
            txtDrAcc.DataBindings.Clear();
            txtCrAcc.DataBindings.Clear();
            txtPayName.DataBindings.Clear();
            txtAmount.DataBindings.Clear();
        }
        txtRemarks.DataBindings.Clear();



        txtTransID.DataBindings.Add(new Binding("Text", bs, "vID"));
        txtvTypeID.DataBindings.Add(new Binding("Text", bs, "vTypeID"));
        txtVNum.DataBindings.Add(new Binding("Text", bs, "vNo"));
        txtVDt.DataBindings.Add(new Binding("Text", bs, "vDate"));
        if (vr.VoucherType == 1)
        {
            txtChqNo.DataBindings.Add(new Binding("Text", bs, "vChqNo"));
            //string s = txtChqDt.Value.ToString("yyyy-MM-dd HH:mm");
            //DateTime dt = DateTime.ParseExact(txtChqDt.Text, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
            txtChqDt.DataBindings.Add(new Binding("Text", bs, "vChqDt"));
            txtDrAcc.DataBindings.Add(new Binding("Text", bs, "accCodeDR"));
            txtCrAcc.DataBindings.Add(new Binding("Text", bs, "accCodeCR"));
            txtPayName.DataBindings.Add(new Binding("Text", bs, "vPayName"));
            txtAmount.DataBindings.Add(new Binding("Text", bs, "vAmount"));
        }
        txtRemarks.DataBindings.Add(new Binding("Text", bs, "vRemarks"));



        txtVDt.Text = DateTime.Today.ToString();
        if (vr.VoucherType == 1)
        {
            txtChqDt.Text = DateTime.Today.ToString();
        }


        if (txtvTypeID.Text == null || txtvTypeID.Text == string.Empty)
        {
            //txtVType.Text = dm.GetData("Select vType from vType Where vTypeID = '" + txtvTypeID.Text + "'").Rows[0]["vType"].ToString();
            txtVType.Text = null;
        }
        else
        {

            txtVType.Text = dm.GetData("Select vType from vType Where vTypeID = '" + txtvTypeID.Text + "'").Rows[0]["vType"].ToString();


        }

        dgVDet.AutoGenerateColumns = false;
        dgVDet.DataSource = bsDet;

        dgVDet.Columns["vDetID"].DataPropertyName = "vDetID";
        dgVDet.Columns["vID"].DataPropertyName = "vID";
        dgVDet.Columns["accCode"].DataPropertyName = "accCode";
        dgVDet.Columns["accName"].DataPropertyName = "accName";
        dgVDet.Columns["accDebit"].DataPropertyName = "accDebit";
        dgVDet.Columns["accCredit"].DataPropertyName = "accCredit";
        dgVDet.Columns["accRemarks"].DataPropertyName = "accRemarks";


        //CalculateTotals();


    }

private void btnSave_Click(object sender, EventArgs e)
    {
        int rowCount = 0;
        rowCount = dgVDet.Rows.Count - 1;




        this.Validate();
        bs.EndEdit();

        double dCr = 0;
        double dDr = 0;
        Double.TryParse(txtTotDR.Text.ToString(), out dDr);
        Double.TryParse(txtTotCR.Text.ToString(), out dCr);

        if (!ds.HasChanges())
        {

            MessageBox.Show("No changes to save.", "Saving Records");
            return;
        }

        if (dCr != dDr)
        {

            MessageBox.Show("Total of Debit and Credit are not equal.", "Saving Records");
            return;
        }


        try
        {


            if (txtvTypeID.Text == null || txtvTypeID.Text == string.Empty)
            {
                return;
            }
            else
            {
                if (txtVNum.Text == null || txtVNum.Text == string.Empty)
                {

                    int temp = int.Parse(this.txtvTypeID.Text.ToString());
                    ds.Tables[0].Rows[0]["vNo"] = vr.GetVoucherNum(temp);
                }

            }


            vr.SaveVoucher(ds);


        }


        catch (MySqlException err)
        {

           // MessageBox.Show(err.Message.ToString() +" "+ err.ErrorCode );
            MessageBox.Show(err.ErrorCode.ToString());

        }

        CellSum(5);
        CellSum(6);
    }