OnClientClick Javascript:confirm get value in textbox?

守給你的承諾、 提交于 2019-12-11 20:46:17

问题


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:


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>


来源:https://stackoverflow.com/questions/25407975/onclientclick-javascriptconfirm-get-value-in-textbox

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!