Message Boards

How to get value from liferay-ui:input-date to function in javascript ?

Amar Daulatkar, modified 12 Years ago.

How to get value from liferay-ui:input-date to function in javascript ?

New Member Posts: 8 Join Date: 3/30/12 Recent Posts
Hello
I have to validate values getting from liferay-ui:input-date using javascript. But i don't know how to get values of liferay-ui:input-date in javascript.

<liferay-ui:input-date
formName="projectFromDate"
monthParam="fromDateMonth"
dayParam="fromDateDay"
yearParam="fromDateYear"
yearRangeStart="1990"
yearRangeEnd="2012">
</liferay-ui:input-date>

<script type="text/javascript">
var day = document.forms["projectFromDate"]["dayParam"].value;
</script>

Please help me.....
thumbnail
David H Nebinger, modified 12 Years ago.

RE: How to get value from liferay-ui:input-date to function in javascript ?

Liferay Legend Posts: 14915 Join Date: 9/2/06 Recent Posts
If you view the source on the generated page, you'll see that all tag IDs are prefixed w/ namespace information. This helps to ensure you won't end up with field ID collisions on the final rendered phase (i.e. two different portlets use two different forms that just happen to want to use the ID "projectFromDate" or input fields w/ the same ID "name").

When writing javascript code you either want to pass in namespaced IDs as function parameters or leverage some CSS selector magic to expose your particular form (i.e. give the elements a special class so you can write selectors to find the elements w/ the class).
thumbnail
Hitoshi Ozawa, modified 12 Years ago.

RE: How to get value from liferay-ui:input-date to function in javascript ?

Liferay Legend Posts: 7942 Join Date: 3/24/10 Recent Posts
With jQuery, it can be accessed like below:

jQuery('#<portlet:namespace />dayParam').
Amar Daulatkar, modified 12 Years ago.

RE: How to get value from liferay-ui:input-date to function in javascript ?

New Member Posts: 8 Join Date: 3/30/12 Recent Posts
But How to use jQuery to get value in variable of javascript i.e var day.
thumbnail
Hitoshi Ozawa, modified 12 Years ago.

RE: How to get value from liferay-ui:input-date to function in javascript ?

Liferay Legend Posts: 7942 Join Date: 3/24/10 Recent Posts
Just do this like I've shown you above:

jQuery('#<portlet:namespace />day').