获取另一个文本字段(Liferay aui)的文本字段的值

get value of a textfield onchage of another textfield (liferay aui )

本文关键字:字段 文本 aui 另一个 获取 Liferay      更新时间:2023-09-26

我的表单中有 2 个输入文本字段,其中一个是自动完成字段(liferay),另一个是普通文本字段。

现在我想检查其他普通文本字段的自动完成字段onchange的值(就像在aui库中一样,我们只有事件onSelect和onChange)。

我正在以这种方式尝试,但仍然没有得到任何价值。

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

任何人都可以告诉我获取自动完成字段值的最佳方法吗?

你要走的路...

也给你的元素一个id(它可以与名称相同)。

并改用getElementById()。

同时从 .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>