Foren

Home » Liferay Portal » English » 3. Development

Kombinierte Ansicht Flache Ansicht Baumansicht
Threads [ Zurück | Nächste ]
toggle
Kevin Gebel
ID of input tag
14. Januar 2011 02:20
Antwort

Kevin Gebel

Rang: Junior Member

Nachrichten: 80

Eintrittsdatum: 27. Mai 2010

Neue 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 :
1
2<aui:input id="inputPassword1" label="password" name="password1" size="24" type="password" value="" onChange="verifierPassword()" />


Javascript :
1
2var 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
RE: ID of input tag
14. Januar 2011 02:31
Antwort

Sébastien Meunier

Rang: Junior Member

Nachrichten: 35

Eintrittsdatum: 26. Januar 2010

Neue 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 :
1var inputPassword1 = document.getElementById('<portlet:namespace/>inputPassword1');
Kowbathullah Gnaniyar
RE: ID of input tag
14. Januar 2011 02:34
Antwort

Kowbathullah Gnaniyar

Rang: Liferay Master

Nachrichten: 608

Eintrittsdatum: 19. Dezember 2007

Neue Beiträge

Hi,

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

so just try like this:

1<portlet:namespace />inputPassword1



HTH.
Kevin Gebel
RE: ID of input tag
14. Januar 2011 02:47
Antwort

Kevin Gebel

Rang: Junior Member

Nachrichten: 80

Eintrittsdatum: 27. Mai 2010

Neue Beiträge

I understand what you want to do. But it doesn't work in this state into my external javascript code.
Kevin Gebel
RE: ID of input tag
14. Januar 2011 02:52
Antwort

Kevin Gebel

Rang: Junior Member

Nachrichten: 80

Eintrittsdatum: 27. Mai 2010

Neue Beiträge

Actually, I don't understand how I have to write it into the external javascript code.
Kowbathullah Gnaniyar
RE: ID of input tag
14. Januar 2011 03:15
Antwort

Kowbathullah Gnaniyar

Rang: Liferay Master

Nachrichten: 608

Eintrittsdatum: 19. Dezember 2007

Neue 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:

1<script src="<your-external-javascript>"/></script>
2
3<script type="text/javascript">
4 external-javascript-method("<portlet:namespace/>");
5</script>


HTH
Kevin Gebel
RE: ID of input tag
14. Januar 2011 05:16
Antwort

Kevin Gebel

Rang: Junior Member

Nachrichten: 80

Eintrittsdatum: 27. Mai 2010

Neue 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.
Kowbathullah Gnaniyar
RE: ID of input tag
14. Januar 2011 11:25
Antwort

Kowbathullah Gnaniyar

Rang: Liferay Master

Nachrichten: 608

Eintrittsdatum: 19. Dezember 2007

Neue 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


 1<aui:input id="inputPassword1" label="password" name="password1" size="24" type="password" value="" onChange="verifierPassword()" />
 2
 3<script type="text/javascript" language="javascript" src="/html/js/jquery/test.js"></script>
 4
 5[b]<script>
 6function verifierPassword() {
 7    getInput('<portlet:namespace />');
 8 }
 9</script>[/b]


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


1function getInput(ns) {
2
3    var inputPassword1 = document.getElementById(ns+'inputPassword1').value;
4    alert(inputPassword1);
5   
6}


HTH.
Kevin Gebel
RE: ID of input tag
15. Januar 2011 03:50
Antwort

Kevin Gebel

Rang: Junior Member

Nachrichten: 80

Eintrittsdatum: 27. Mai 2010

Neue Beiträge

Thank you very much Gnaniyar, I will try it later.
Kevin Gebel
RE: ID of input tag
16. Januar 2011 23:22
Antwort

Kevin Gebel

Rang: Junior Member

Nachrichten: 80

Eintrittsdatum: 27. Mai 2010

Neue Beiträge

It perfectly works ! Thank you Gnaniyar.