Domanda

I have 2 input text fields in my form using one is autocomplete fields(liferay) and other is normal text fields.

Now I want to check the value of autocomplete field onchange(as in aui library we have only to events onSelect and onChange) of other normal text field.

I am trying in thsi way but still not getting any value.

<form   action="<liferay-portlet:actionURL name="saveForm"  />"
     id="<portlet:namespace />sampleForm"
    method="post"  enctype="multipart/form-data"  name="<portlet:namespace />sampleForm">
<aui:input name="firstName"  />      /* this is autocomplete field*/

<aui:input name="lastName"  onChange="myFunction()"/>
.
.
.
.

</form>

<script type="text/javascript" language="javascript">

function myFunction(){
   alert("in----------");
   alert(document.getElementByName("firstName").value());
} 

</script>

Can anybody show me a best way to get value of autocomplete field ?

È stato utile?

Soluzione

The way you're going...

Give your elements an id as well (it can be the same as the name).

And use getElementById() instead.

Also remove () from .value()

<form   action="<liferay-portlet:actionURL name="saveForm"  />"
     id="<portlet:namespace />sampleForm"
    method="post"  enctype="multipart/form-data"  name="<portlet:namespace />sampleForm">
<aui:input name="firstName" id="firstName" />      /* this is autocomplete field*/

<aui:input name="lastName" id="lastName"  onChange="myFunction()"/>
.
.
.
.

</form>

<script type="text/javascript" language="javascript">

function myFunction(){
   alert("in----------");
   alert(document.getElementById("firstName").value);
} 

</script>
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top