开发者

Unable to load the Javascript calendar on Href by using Jquery function

I have my function as follows

 <script type="text/javascript">
$(function() {
$('#ctl00_ContentPlaceHolder1_TextBox2').datepick();
});

function showDate(date) {
//alert('The date chosen is ' + date);
}
</script>

I need this to be called when i click on Href tag

<a onclick="" href="#">


Metaforce as per you said i tried this 



<script type="text/javascript">
$(f开发者_JS百科unction click() {
    $('#ctl00_ContentPlaceHolder1_TextBox2').datepick();
});

function showDate(date) {
    //alert('The date chosen is ' + date);
}
    </script>

  <a onclick="return click();" href="#">

    <img alt="cal" src="calendar.gif" style="vertical-align: text-bottom;" border="0" /></a>

In onclick i have to call that how can i any help please

Patrick Kaufmann and Phillip Kovalev as per your said i write as follows

    <script type="text/javascript">
function showDate(date) {
  //alert('The date chosen is ' + date);
}

$(function() {
  $('#ctl00_ContentPlaceHolder1_TextBox2').datepick();

  // assign anonimous function as event handler and call showdate from it 
  $('#clickOnIt').click( function() {
    showDate( $(this).val() );
  } );
});
</script>

<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
 <a href="#" id="clickOnIt">click me</a>

But i am not getting the desired calendar


if <a/> has an unique id or class attribute you can assign event in your javascript:

<script type="text/javascript">

$(function() {
  var dateField = $('#ctl00_ContentPlaceHolder1_TextBox2');
  dateField.datepick();

  // assign anonimous function as event handler and call showdate from it 
  $('#your_a_selector').click( function() {
    dateField.datepick('show');
  } );
});
</script>


Better use the jquery click handler to separate the javascript code from the markup.

Example:

<a href="#" id="clickOnIt">click me</a>

An then in the javascript file:

$('#clickOnIt').click(function() {
    //do the stuff for the click here
});


try like this:

function clickDatePick() {
    $('#ctl00_ContentPlaceHolder1_TextBox2').datepick();
}

and add this in onclick: <a onclick="clickDatePick();" href="#">

or

<a onclick="$('#ctl00_ContentPlaceHolder1_TextBox2').datepick();" href="#">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜