OnClientClick [removed]confirm get value in textbo

2019-09-03 19:06发布

So I can't seem to find anywhere how to do this. I want to be able to use the value of BuyOutPrice in the text(confirm) box but can't seem to make it work.

More specificly, how am I supposed to write this part: ('Are you sure you want to buy-out for $' + BuyOutPrice + '?')

This was just my closest guess from experience in other programming languages but it appears invalid in JavaScript.

var BuyOutPrice = '<%= Content.ComparisonPrice %>';


<asp:ImageButton ID="BuyNowButton" OnClick="BuyNowButton_Click" Style="vertical-align:top;" ImageUrl="Images/btn_buyNow.png" runat="server" OnClientClick="javascript:return confirm('Are you sure you want to buy-out for $' + BuyOutPrice + '?'); BuyNow(); return ValidateBuyNow();" />

1条回答
Melony?
2楼-- · 2019-09-03 19:44

If ComparisonPrice is a TextBox so try this:

<asp:TextBox ID="ComparisonPrice" runat="server"></asp:TextBox>
<asp:ImageButton ID="BuyNowButton" Style="vertical-align:top;" ImageUrl="Images/btn_buyNow.png" runat="server" OnClientClick="javascript:return confirm('Are you sure you want to buy-out for' + momo() + '?'); BuyNow(); return ValidateBuyNow();" />

And JavaScript:

<script>
    function momo() {
        return document.getElementById('<%= ComparisonPrice.ClientID %>').value
    }
</script>
查看更多
登录 后发表回答