Reputation: 1103
I want to pass my javascript variable to jsp file . How is it possible? Following is my code
<script type="text/javascript">
function js_alert(selected){
var selectText=selected.options[selected.selectedIndex].text;
alert(selectText);
}
</script>
I want to pass selectText in following label
<aui:input name="demo" label="???" type="text" id="demo" />
How is it possible in liferay? please help
Thanks!!!
Upvotes: 1
Views: 2120
Reputation: 39
document.getElementById('demo').value = selectText;
Remove the ID attribute from the aui:input tag
Upvotes: 0
Reputation: 46
You need the portlet namespace. From the aui:input you will get a simple input field the ID of that input field will be the portletnamespace+yourAuiInputName
I think this script is on the jsp so this can work.
document.getElementById('<portlet:namespace />demo').value = selectText;
If this js is not on the jsp but in a separate js file. You have to pass the namespace in a parameter.
function js_alert(selected, namespace){
var selectText=selected.options[selected.selectedIndex].text;
alert(selectText);
document.getElementById(namespace+'demo').value = selectText;
}
<script>
js_alert(selected, <portlet:namespace />);
</script>
Edit: Remove the ID field from the aui:input. That will be generated by the aui tag. In liferay 6.2 I had a lot of problem when I used the short endings. It would be better if you use the the aui tags like this:
<aui:input name="yourname" label="yourlLabel">
</aui:input>
Upvotes: 2