我想動態地傳遞表單名稱。但是這個腳本顯示錯誤。如何動態地將表單名稱傳遞給javascript方法?
「document.formName is undefined」。如何解決這個問題。提前致謝。
<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>
爲什麼不只是使用表單名稱而不是'this'?另外,看看jQuery。這會幫助你很多。看看這裏:http://docs.jquery.com,http://docs.jquery.com/API/1.1/Events/Form – Steven 2010-07-23 09:12:11