我有一个包含select标签的表单,我想在点击上一页的按钮后预填充该标签。我怎样才能做到这一点? 这是表单代码:
<form method="post" name="registration" action="http://esafe.urdemo.net/user/login/signup" onsubmit="return checkform2();">
<input type="text" class="textbox" placeholder="Enter First Name" name="first_name" />
<input type="text" class="textbox" placeholder="Enter Middle Name" name="middle_name" />
<input type="text" class="textbox" placeholder="Enter Last Name" name="last_name" />
<input type="text" class="textbox" placeholder="Select Date dd/mm/yyyy" name="Date1" onblur="return checkdob(this);"/>
<input type="text" class="textbox" placeholder="Enter Email Id" name="email" />
<input type="text" class="textbox" placeholder="Enter Mobile No." name="mobile" />
<select name="plan" class="form-control" style="width:90%">
<option value="" selected="selected">Please Select</option>
<option value="1">Pro</option>
<option value="2">Premium</option>
<option value="3">Elite</option>
<option value="4">Magna</option>
</select>
<div class="signinStrip">
<span class="forgot"> <a href="#" id="resend_password_link"></a> </span>
<input class="signin_submit" value="Submit" type="submit" />
</div>
</form>
这里是按钮的代码
<tr>
<td class="title"> </td>
<td><p class="bottom"><a class="btn btn-primary" href="#" >Buy Now</a></p></td>
<td><p class="bottom"><a class="btn btn-primary" href="#" >Buy Now</a></p></td>
<td><p class="bottom"><a class="btn btn-primary" href="#" >Buy Now</a></p></td>
<td><p class="bottom"><a class="btn btn-primary" href="#" >Buy Now</a></p></td>
</tr>
答案 0 :(得分:0)
如果要根据上一页点击的按钮选择特定选项,则必须通过某个服务器端变量或通过地址URL参数发送该值。例如。你的第二页网址必须是“http://yourdomain.com/page2?selected_value=temp”
然后在下一页javascript中你必须提取这个参数
function getParam(paramName) {
return decodeURI(
(RegExp(paramName + '=' + '(.+?)(&|$)').exec(location.search)||[,null])[1]
);
}
var selectedVal = getParam("elected_value");
document.getElementById(<your select box id>).value = selectedVal;