문제

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 ?

도움이 되었습니까?

해결책

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top