Foren

ID of input tag

thumbnail
Kevin Jebel, geändert vor 13 Jahren.

ID of input tag

Junior Member Beiträge: 80 Beitrittsdatum: 27.05.10 Neueste Beiträge
Hello

I'd like to get the id of my alloy input into my javascript code but the id I specified is not the id I get :

JSP page :

<aui:input id="inputPassword1" label="password" name="password1" size="24" type="password" value="" onChange="verifierPassword()" />


Javascript :

var inputPassword1 = document.getElementById('inputPassword1');


I used firebug to get the id generated : _58_inputPassword1 in spite of inputPassword1.

Has anyone an explanation ?
Thanks
Sébastien Meunier, geändert vor 13 Jahren.

RE: ID of input tag

Junior Member Beiträge: 33 Beitrittsdatum: 26.01.10 Neueste Beiträge
Hello,

The aui:input taglib automatically adds the portlet namespace to the id of the input.

So to get this input, you need to do something like this :
var inputPassword1 = document.getElementById('<portlet:namespace />inputPassword1');
thumbnail
Kevin Jebel, geändert vor 13 Jahren.

RE: ID of input tag

Junior Member Beiträge: 80 Beitrittsdatum: 27.05.10 Neueste Beiträge
I understand what you want to do. But it doesn't work in this state into my external javascript code.
thumbnail
Gnaniyar Zubair, geändert vor 13 Jahren.

RE: ID of input tag

Liferay Master Beiträge: 722 Beitrittsdatum: 19.12.07 Neueste Beiträge
Hi,

AUI will automatically generate the id with portlet namespace though you dont mention it.

so just try like this:

<portlet:namespace />inputPassword1



HTH.
thumbnail
Kevin Jebel, geändert vor 13 Jahren.

RE: ID of input tag

Junior Member Beiträge: 80 Beitrittsdatum: 27.05.10 Neueste Beiträge
Actually, I don't understand how I have to write it into the external javascript code.
thumbnail
Gnaniyar Zubair, geändert vor 13 Jahren.

RE: ID of input tag

Liferay Master Beiträge: 722 Beitrittsdatum: 19.12.07 Neueste Beiträge
This <portlet:namespace /> tag would not work directly in your JS file. So you can call external javascript passing <portlet:namespace /> from your jsp file.

In your jsp file:

<script src="<your-external-javascript>"></script>

<script type="text/javascript">
 external-javascript-method("<portlet:namespace/>");
</script>


HTH
thumbnail
Kevin Jebel, geändert vor 13 Jahren.

RE: ID of input tag

Junior Member Beiträge: 80 Beitrittsdatum: 27.05.10 Neueste Beiträge
Simplier, how can I access to a AUI input text declared in a jsp file from an external javascript file ?
I still don't understand.

Whatever, thank you for your time.
thumbnail
Gnaniyar Zubair, geändert vor 13 Jahren.

RE: ID of input tag

Liferay Master Beiträge: 722 Beitrittsdatum: 19.12.07 Neueste Beiträge
Hi,

you would get the text box value in external javascript if you call that external js from jsp as follows:

1. jsp file


<aui:input id="inputPassword1" label="password" name="password1" size="24" type="password" value="" onChange="verifierPassword()" />

<script type="text/javascript" language="javascript" src="/html/js/jquery/test.js"></script>

[b]<script>
function verifierPassword() {
	getInput('<portlet:namespace />');
 }
</script>[/b]



2. External js file: ( /html/portlet/...../test.js)


function getInput(ns) {

	var inputPassword1 = document.getElementById(ns+'inputPassword1').value;
	alert(inputPassword1);
	
}


HTH.
thumbnail
Kevin Jebel, geändert vor 13 Jahren.

RE: ID of input tag

Junior Member Beiträge: 80 Beitrittsdatum: 27.05.10 Neueste Beiträge
Thank you very much Gnaniyar, I will try it later.
thumbnail
Kevin Jebel, geändert vor 13 Jahren.

RE: ID of input tag

Junior Member Beiträge: 80 Beitrittsdatum: 27.05.10 Neueste Beiträge
It perfectly works ! Thank you Gnaniyar.