admin管理员组文章数量:1326012
I am trying to pass form name dynamically. But this script is showing an error.
"document.formName is undefined". How to solve this. Thanks in advance.
<script language="javascript">
function showAll(form,fieldName) {
var formName = form.name;
alert(formName);
document.formName.search_mode.value = "";
document.formName.fieldName.value="";
document.formName.submit();
}
</script>
<form name = "dealsManagement" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="search_mode" value="<?php echo $_REQUEST['search_mode'];?>" >
<table border="0" cellpadding="0" cellspacing="0" align="center" width="400" style="padding:2px; border:#ccc solid 1px; margin:15px auto 15px auto;">
<tr>
<td colspan="2" class="text3" align="center" height="35" bgcolor="#cccccc">Search</td>
</tr>
<tr>
<td width="153" height="35" align="right" class="text2" style="padding-right:10px;">Search By City:</td>
<td width="245"><input type="text" name="city" value= "<?php echo $_POST['city']; ?>" size="24" ></input></td>
</tr>
<tr>
<td height="30"> </td>
<td><input name="button" type="button" class="btn" onClick="javascript:dealSearchCity()" value="Search" />
<input name="btnShowAll" type="button" class="btn"value="Show All" onClick="javascript:showAll(this.form,'city');" /></td>
</tr>
</table>
</form>
I am trying to pass form name dynamically. But this script is showing an error.
"document.formName is undefined". How to solve this. Thanks in advance.
<script language="javascript">
function showAll(form,fieldName) {
var formName = form.name;
alert(formName);
document.formName.search_mode.value = "";
document.formName.fieldName.value="";
document.formName.submit();
}
</script>
<form name = "dealsManagement" method="post" action="<?=$_SERVER['PHP_SELF']?>">
<input type="hidden" name="search_mode" value="<?php echo $_REQUEST['search_mode'];?>" >
<table border="0" cellpadding="0" cellspacing="0" align="center" width="400" style="padding:2px; border:#ccc solid 1px; margin:15px auto 15px auto;">
<tr>
<td colspan="2" class="text3" align="center" height="35" bgcolor="#cccccc">Search</td>
</tr>
<tr>
<td width="153" height="35" align="right" class="text2" style="padding-right:10px;">Search By City:</td>
<td width="245"><input type="text" name="city" value= "<?php echo $_POST['city']; ?>" size="24" ></input></td>
</tr>
<tr>
<td height="30"> </td>
<td><input name="button" type="button" class="btn" onClick="javascript:dealSearchCity()" value="Search" />
<input name="btnShowAll" type="button" class="btn"value="Show All" onClick="javascript:showAll(this.form,'city');" /></td>
</tr>
</table>
</form>
Share
edited Jul 23, 2010 at 9:08
Oded
499k102 gold badges893 silver badges1k bronze badges
asked Jul 23, 2010 at 9:06
FeroFero
13.3k46 gold badges118 silver badges159 bronze badges
1
-
why not just use the form name instead of
this
? Also, have a look at jQuery. That will help you a lot. Have a look here: docs.jquery. , docs.jquery./API/1.1/Events/Form – Steven Commented Jul 23, 2010 at 9:12
2 Answers
Reset to default 3What you are doing is not necessary. You can use form
directly:
function showAll(form,fieldName) {
var formName = form.name;
alert(formName);
form.elements.search_mode.value = "";
form.elements[fieldName].value="";
form.submit();
}
two sidenotes:
The language
attribute is deprecated, better use
<script type="text/javascript">
and you don't need to prefix event handlers with javascript:
.
If you want to use a string rather than a literal property name, you have to use square bracket notation.
本文标签: htmlHow to pass form name dynamically in to a javascript methodStack Overflow
版权声明:本文标题:html - How to pass form name dynamically in to a javascript method? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742142760a2422655.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论