bala3569
bala3569

Reputation: 11010

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?

Upvotes: 2

Views: 4340

Answers (3)

Claudio Redi
Claudio Redi

Reputation: 68440

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);
}

Upvotes: 5

AlexCuse
AlexCuse

Reputation: 18316

I think you're missing document.getElementById.

So something like:

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

Upvotes: 0

Kimtho6
Kimtho6

Reputation: 6184

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;

Upvotes: 0

Related Questions