QasimRamzan
QasimRamzan

Reputation: 397

How to alert(date) with jquery?

I am trying with this, but it is undignified.

In html.

 <BDP:BasicDatePicker ID="DOBpicker" runat="server" CssClass="txtBox" DisplayType="TextBox"
  ValidationGroup="userRegistration" /> 

in jquery, I tried with this

 function btn()
{
  var date = $('#DOBpicker').val();
  alert(date);
}

or

function btn()
{
  var date = document.getElementById('DOBpicker').value;
  alert(date);
}

call this function on btn

<input id="test" type="button" value="go" onclick="btn()" />

But it undefined.

Upvotes: 0

Views: 1815

Answers (2)

Dips
Dips

Reputation: 3290

Try attr() instead of val(). See demo here You have to have value otherwise it doesn't fire anything or just undefined. For instance I have added value="Hello World"

<BDP:BasicDatePicker ID="DOBpicker" runat="server" CssClass="txtBox" DisplayType="TextBox"
  ValidationGroup="userRegistration" value="Hello World" /> 

var date = $('#DOBpicker').attr('value');

alert(date);​

Upvotes: 1

TGH
TGH

Reputation: 39258

It's a server side control, so you have to do something like $("[id*=DOBpicker]").val(). It's because the id ends up being longer in the DOM after it's rendered since ASP.Net appends the ids of its parents etc

You can also do $(#+'<%=DOBpicker.ID %>').val() since that gets the full id and not just the partial ID

Upvotes: 0

Related Questions