我有一个页面,我需要将ASP变量分配到javascript变量中,然后在单击复选框时使用复制表单字段(使用ASP在上一页上提交的地址信息)。 javascript变量确实具有从ASP Request.Form设置的值,因为我已在此表单所在页面的视图源中验证了这一点。
<script language="JavaScript" type="text/JavaScript">
<!--
function CheckBillingAddress()
{
var theForm = document.form1;
var Address = "<%=Request.Form("Corp_Address1")%>";
var Address2 = "<%=Request.Form("Corp_Address2")%>";
var City = "<%=Request.Form("Corp_City")%>";
var Prov = "<%=Request.Form("Corp_Province")%>";
var Postal = "<%=Request.Form("Corp_Postal")%>";
if (theForm.BillingAddOption.checked == true)
{
theForm.BillingAddress1.value = Address.value;
theForm.BillingAddress2.value = theForm.Address2.value;
theForm.BillingCity.value = theForm.City.Value;
theForm.BillingProv.value = theForm.Prov.value;
theForm.BillingPostalCode.value = theForm.Postal.value;
}
if (theForm.BillingAddOption.checked == false)
{
theForm.BillingAddress1.value = ''
theForm.BillingAddress2.value = '';
theForm.BillingCity.value = '';
theForm.BillingProv.value = '';
theForm.BillingPostalCode.value = '';
}
}
//-->
</script>
我的HTML表单是:
<form name="form1" method="post" action="#" onsubmit="return(ProcessSubmit(this));" enctype="application/x-www-form-urlencoded">
<table width="80%" align="center" cellpadding="2" cellspacing="1" class="formtable2">
<tr valign="baseline" align="center">
<td colspan="2" valign="middle" class="FormSubHdr"><h3><b>
BILLING & SHIPPING INFORMATION </b></h3></td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right" width="45%"><b>*
First Name:
</b></td>
<td width="55%" align="left" valign="middle" >
<input type="text" class="GrFormBG" name="FirstName" size="30" maxlength="50">
</td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right" width="45%"><b>*
Last Name: </b></td>
<td width="55%" align="left" valign="middle" >
<input type="text" class="GrFormBG" name="LastName" size="30" maxlength="60"> </td>
</tr>
<tr valign="baseline" >
<td valign="middle" align="right" width="45%" >
<p><b>Email
Address: </b></p>
</td>
<td width="55%" align="left" valign="middle" >
<%=Request.Form("Email")%> </td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right"><b>Also send emails to this address: </b></td>
<td align="left" valign="middle" ><input name="Email2" type="text" class="GrFormBG" id="Email2" size="25" maxlength="60"></td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right"><strong>*Billing Address:</strong></td>
<td align="left" valign="middle" ><input name="BillingAddOption" type="checkbox" id="BillingAddOption" value="Same as Corporate Address" onclick="CheckBillingAddress()"> Same as Corporate Address</td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right" width="45%"><b>
*
Billing Address Street:
</b></td>
<td width="55%" align="left" valign="middle" >
<input type="text" class="GrFormBG" name="BillingAddress1" size="30" maxlength="80">
</td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right" width="45%"><b>Billing
Address 2: </b></td>
<td width="55%" align="left" valign="middle" >
<input type="text" class="GrFormBG" name="BillingAddress2" size="30" maxlength="50">
</td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right" width="45%"><b>*
Billing City:
</b></td>
<td width="55%" align="left" valign="middle" >
<input type="text" class="GrFormBG" name="BillingCity" size="30" maxlength="50">
</td>
</tr><tr valign="baseline">
<td valign="middle" align="right" width="45%"><b>*
Billing Province:
</b></td>
<td width="55%" align="left" valign="middle"><select name="BillingProv" id="BillingProv">
<option value="">select State or Province (Canada/US Only)</option>
<option value="ZZ">Outside US or Canada</option>
<optgroup label="United States">
<option id="USA-AL" value="AL">Alabama (AL)</option>
<option id="USA-AK" value="AK">Alaska (AK)</option>
<option id="USA-AZ" value="AZ">Arizona (AZ)</option>
<option id="USA-AR" value="AR">Arkansas (AR)</option>
<option id="USA-CA" value="CA">California (CA)</option>
<option id="USA-CO" value="CO">Colorado (CO)</option>
<option id="USA-CT" value="CT">Connecticut (CT)</option>
<option id="USA-DE" value="DE">Delaware (DE)</option>
<option id="USA-DC" value="DC">District of Columbia (DC)</option>
<option id="USA-FL" value="FL">Florida (FL)</option>
<option id="USA-GA" value="GA">Georgia (GA)</option>
<option id="USA-GU" value="GU">Guam (GU)</option>
<option id="USA-HI" value="HI">Hawaii (HI)</option>
<option id="USA-ID" value="ID">Idaho (ID)</option>
<option id="USA-IL" value="IL">Illinois (IL)</option>
<option id="USA-IN" value="IN">Indiana (IN)</option>
<option id="USA-IA" value="IA">Iowa (IA)</option>
<option id="USA-KS" value="KS">Kansas (KS)</option>
<option id="USA-KY" value="KY">Kentucky (KY)</option>
<option id="USA-LA" value="LA">Louisiana (LA)</option>
<option id="USA-ME" value="ME">Maine (ME)</option>
<option id="USA-MD" value="MD">Maryland (MD)</option>
<option id="USA-MA" value="MA">Massachusetts (MA)</option>
<option id="USA-MI" value="MI">Michigan (MI)</option>
<option id="USA-MN" value="MN">Minnesota (MN)</option>
<option id="USA-MS" value="MS">Mississippi (MS)</option>
<option id="USA-MO" value="MO">Missouri (MO)</option>
<option id="USA-MT" value="MT">Montana (MT)</option>
<option id="USA-NE" value="NE">Nebraska (NE)</option>
<option id="USA-NV" value="NV">Nevada (NV)</option>
<option id="USA-NH" value="NH">New Hampshire (NH)</option>
<option id="USA-NJ" value="NJ">New Jersey (NJ)</option>
<option id="USA-NM" value="NM">New Mexico (NM)</option>
<option id="USA-NY" value="NY">New York (NY)</option>
<option id="USA-NC" value="NC">North Carolina (NC)</option>
<option id="USA-ND" value="ND">North Dakota (ND)</option>
<option id="USA-OH" value="OH">Ohio (OH)</option>
<option id="USA-OK" value="OK">Oklahoma (OK)</option>
<option id="USA-OR" value="OR">Oregon (OR)</option>
<option id="USA-PA" value="PA">Pennsylvania (PA)</option>
<option id="USA-PR" value="PR">Puerto Rico (PR)</option>
<option id="USA-RI" value="RI">Rhode Island (RI)</option>
<option id="USA-SC" value="SC">South Carolina (SC)</option>
<option id="USA-SD" value="SD">South Dakota (SD)</option>
<option id="USA-TN" value="TN">Tennessee (TN)</option>
<option id="USA-TX" value="TX">Texas (TX)</option>
<option id="USA-UT" value="UT">Utah (UT)</option>
<option id="USA-VT" value="VT">Vermont (VT)</option>
<option id="USA-VA" value="VA">Virginia (VA)</option>
<option id="USA-VI" value="VI">Virgin Islands (VI)</option>
<option id="USA-WA" value="WA">Washington (WA)</option>
<option id="USA-WV" value="WV">West Virginia (WV)</option>
<option id="USA-WI" value="WI">Wisconsin (WI)</option>
<option id="USA-WY" value="WY">Wyoming (WY)</option>
</optgroup>
<optgroup label="Canada">
<option id="CAN-AB" value="AB">Alberta (AB)</option>
<option id="CAN-BC" value="BC">British Columbia (BC)</option>
<option id="CAN-MB" value="MB">Manitoba (MB)</option>
<option id="CAN-NB" value="NB">New Brunswick (NB)</option>
<option id="CAN-NL" value="NL">Newfoundland and Labrador (NL)</option>
<option id="CAN-NT" value="NT">Northwest Territories (NT)</option>
<option id="CAN-NS" value="NS">Nova Scotia (NS)</option>
<option id="CAN-NU" value="NU">Nunavut (NU)</option>
<option id="CAN-PE" value="PE">Prince Edward Island (PE)</option>
<option id="CAN-SK" value="SK">Saskatchewan (SK)</option>
<option value="ON" selected id="CAN-ON">Ontario (ON)</option>
<option id="CAN-QC" value="QC">Quebec (QC)</option>
<option id="CAN-YT" value="YT">Yukon (YT)</option>
</optgroup>
</select></td>
</tr>
<tr valign="baseline">
<td valign="middle" align="right" width="45%"><b>*
Billing Postal
Code: </b></td>
<td width="55%" align="left" valign="middle">
<input name="BillingPostalCode" type="text" class="GrFormBG" size="7" maxlength="7"/>
<br> <input type="submit" name="submit" value="submit">
</td>
</tr>
</table>