简体   繁体   中英

How to pass textbox value to JavaScript?

How to pass two textbox values to a javascript function on a button click event.I have tried it like this but it is not working.here is my code

<asp:LinkButton ID="lnkBTNSubmit" runat="server" CssClass="buttonlink"
  OnClientClick="checkDateRange(GetTextBoxValue('<%= txtATrendStartDate.ClientID %>'.value),GetTextBoxValue('<%= txtATrendEndDate.ClientID %>'.value))">Submit</asp:LinkButton>

and

function checkDateRange(start, end)
{
}

Any Suggestion?

Something like this would do the trick

<asp:LinkButton ID="lnkBTNSubmit" runat="server" CssClass="buttonlink"
  OnClientClick="return onBtnSubmitClick()">Submit</asp:LinkButton>

function onBtnSubmitClick(){
   var start = document.getElementById('<%= txtATrendStartDate.ClientID %>').value;
   var end = document.getElementById('<%= txtATrendEndDate.ClientID %>').value;
   return checkDateRange(start, end);
}

do it in your inline/header javascript like this:

var element = document.getElementById('<%= txtATrendEndDate.ClientID %>');

element.value

and if you set ClientIDMode="Static" you can do:

var value= document.getElementById('txtATrendEndDate').value;

I think you're missing document.getElementById.

So something like:

document.getElementById('<%=txtATrendStartDate.ClientID%>').value

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM