这是我正在使用的代码。它提交给我需要它的两个地方的方式很好。我需要做的是:
按原样提交表格到第一个帖子位置。那显然没问题,哈哈。这就是问题....我想修改提交到第二个帖子位置的表单字段名称。
示例:字段名称为:“Administrator”。发布到第二个帖子位置的地方,例如:“Some_Text_Administrator”
这甚至可能吗?在此先感谢这个优秀的社区!!
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
<meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
<title>Register</title>
<link rel="STYLESHEET" type="text/css" href="style.css">
<script type='text/javascript' src='gen_validatorv31.js'></script>
</head>
<body onload='hideResultDiv();'>
<div id='allcontainer'>
<div id='formcontainer'>
<!-- Form Code Start -->
<form id='contactus' action='' method='post' class="xxxx" name="xxxx">
<fieldset >
<legend>Title Here</legend>
<tr>
<td>
<font size=2 face=arial color=#333333>
<b>Account Administrator</b>
</font>
</td>
<td>
<input type=text size=40 name=Administrator>
</td>
</tr>
<tr>
<td>
<font size=2 face=arial color=#333333>
<b>Administrator Email</b>
</font>
</td>
<td>
<input type=text size=40 name=email>
</td>
</tr>
<tr>
<td>
<font size=2 face=arial color=#333333>
<b>State</b>
</font>
</td>
<td>
<select name=State_Location1>
<option></option>
<option>AL</option>
<option>AK</option>
<option>AZ</option>
<option>AR</option>
<option>CA</option>
<option>CO</option>
<option>CT</option>
<option>DC</option>
<option>DE</option>
<option>FL</option>
<option>GA</option>
<option>HI</option>
<option>ID</option>
<option>IL</option>
<option>IN</option>
<option>IA</option>
<option>KS</option>
<option>KY</option>
<option>LA</option>
<option>ME</option>
<option>MD</option>
<option>MA</option>
<option>MI</option>
<option>MN</option>
<option>MS</option>
<option>MO</option>
<option>MT</option>
<option>NE</option>
<option>NV</option>
<option>NH</option>
<option>NJ</option>
<option>NM</option>
<option>NY</option>
<option>NC</option>
<option>ND</option>
<option>OH</option>
<option>OK</option>
<option>OR</option>
<option>PA</option>
<option>RI</option>
<option>SC</option>
<option>SD</option>
<option>TN</option>
<option>TX</option>
<option>UT</option>
<option>VT</option>
<option>VA</option>
<option>WA</option>
<option>WV</option>
<option>WI</option>
<option>WY</option>
</select>
</td>
</tr>
<tr>
<td>
<font size=2 face=arial color=#333333>
<b>Zip Code</b>
</font>
</td>
<td>
<input type=text size=20 name=Zip_Code_Location1>
</td>
</tr>
<tr>
<td>
<font size=2 face=arial color=#333333>
Category 1
</font>
</td>
<td>
<select name=Category1>
<option></option>
<option>Cat 1</option>
<option>Cat 2</option>
<option>Cat 3</option>
</select>
</td>
</tr>
</table>
<div class='container'>
<input type='button' name='Submit' value='Submit' onclick='javascript: return SubmitForm()' />
</div>
</fieldset>
</form>
<script type='text/javascript'>
// <![CDATA[
var frmvalidator = new Validator("contactus");
frmvalidator.EnableOnPageErrorDisplay();
frmvalidator.EnableMsgsTogether();
frmvalidator.addValidation("name","req","Please provide your name");
frmvalidator.addValidation("email","req","Please provide your email address");
frmvalidator.addValidation("email","email","Please provide a valid email address");
frmvalidator.addValidation("message","maxlen=2048","The message is too long!(more than 2KB!)");
// ]]>
</script>
<script type='text/javascript'>
function SubmitForm()
{
if(document.forms['contactus'].onsubmit())
{
showResultDiv();
document.forms['contactus'].action='xxxx1';
document.forms['contactus'].target='frame_result1';
document.forms['contactus'].submit();
document.forms['contactus'].action='xxxx2';
document.forms['contactus'].target='frame_result2';
document.forms['contactus'].submit();
}
return true;
}
function showResultDiv()
{
var result_div = document.getElementById('resultcontainer');
result_div.style.display="";
}
function hideResultDiv()
{
var result_div = document.getElementById('resultcontainer');
result_div.style.display='none';
}
</script>
<!--
Form Code End
-->
</div >
<div id='resultcontainer'>
There are three iframes below, that
shows results from each of the action scripts.
<div class='iframe_container'>
<iframe name='frame_result1' width='400px' height='400px' frameborder='0'></iframe>
</div>
<div class='iframe_container'>
<iframe name='frame_result2' width='400px' height='400px' frameborder='0'></iframe>
</div>
</div >
</div>
</body>
</html>
答案 0 :(得分:0)
您需要做的第一件事是将id
添加到您希望更改名称的输入中。这将使您在选择这些输入时更轻松。
因此,第一个输入将是:<input id="input_administrator" type="text" size="40" name="Administrator">
然后,在执行提交的函数中,在第一次提交后,您只需更改输入的名称,然后按其ID并更改其名称属性:
function SubmitForm()
{
if(document.forms['contactus'].onsubmit())
{
showResultDiv();
document.forms['contactus'].action='xxxx1';
document.forms['contactus'].target='frame_result1';
document.forms['contactus'].submit();
// Changing the name of the inputs, to submit to location 2
document.getElementById("input_administrator").name = "Second_Name_Administrator";
document.forms['contactus'].action='xxxx2';
document.forms['contactus'].target='frame_result2';
document.forms['contactus'].submit();
}
return true;
}
在这个示例中,我只使用了输入管理员,您应该为每个输入
执行此操作