Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Calling jquery functions from jsp  RSS feed

 
Shavik Harindra Gunarathne
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Below is the jquery function i want to call from my jsp page.
$(function() {
$('.date-picker').datepicker( {
changeMonth: true,
changeYear: true,
showButtonPanel: true,
dateFormat: 'MMyy',
onClose: function(dateText, inst) {
var month = $("#ui-datepicker-div .ui-datepicker-month :selected").val();
var year = $("#ui-datepicker-div .ui-datepicker-year :selected").val();
$(this).datepicker('setDate', new Date(year, month, 1));
}
});
});

This works fine with below tag
<input name="month" id="startDate" class="date-picker" />
But I want it to use with <html:text> tag which is inside <html:form>. I tried variations of onclick,onchange etc.. but did not had any luck. What did I do wrong. Appreciate if you can tell me how to fix it. Thank you.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please read this article to understand how JSP works. The Struts input tag is evaluated on the server to create the HTML to send to the client. The generated HTML is all that matters to jQuery, so you need to see what's being sent to the browser to see why it's not working.
 
Shavik Harindra Gunarathne
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you for the reply. I will use those from here onward.

I was able to solve the problem with the below code
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Embedding the script in onXyz attributes on the elements isn't considered a best practice, but if it's working for you, that's good. It gives you some time to find out why the other wasn't working.

But, remove the "javascript:" pseudo-protical form the attribute value. It's needless can may foul up in some browsers.
 
Shavik Harindra Gunarathne
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!