我有表格我需要在下拉列表中按用户选择的值形成动作
<html>
<body>
<form action="city/<?drop_down_value?>/mobile.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<select name="Location" required="required">
<option value="">..</option>
<option value="india">india</option>
<option value="USA">USA</option>
</select>
<input type="submit">
</form>
</body>
</html>
当用户选择表格中的选项时,应在表格中输入值 我该如何做到
答案 0 :(得分:0)
你可以试试这个:
$('select').on('change', function() {
$('form').attr('action', 'city/' + $(this).val() + '/mobile.php');
//alert($('form').attr('action'));
});
工作Fiddle.
答案 1 :(得分:0)
你也可以试试这个......
<form id="frmLoginRegister" action="city/<?drop_down_value?>/mobile.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<select name="Location" required="required" id='Location' onchange="check(this.value)">
<option value="">..</option>
<option value="india">india</option>
<option value="USA">USA</option>
</select>
<input type="submit">
</form>
<script language="javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script language="javascript">
function check(vak)
{
$("#frmLoginRegister").attr("action", "city/"+ vak +"/mobile.php");
}
</script>
或者可以尝试:
<form id="frmLoginRegister" action="city/<?drop_down_value?>/mobile.php" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<select name="Location" required="required" id='Location'>
<option value="">..</option>
<option value="india">india</option>
<option value="USA">USA</option>
</select>
<input type="submit">
</form>
<script language="javascript" src="http://code.jquery.com/jquery-1.11.1.min.js"></script>
<script language="javascript">
$("select").on('change',function() {
$("#frmLoginRegister").attr("action", "city/"+ $(this).val() +"/mobile.php");
});
</script>
答案 2 :(得分:0)
您可以使用Jquery:
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery-1.11.0.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('select[name="Location"]').change(function(){
console.log($(this).val());
$('form[name="form"]').attr('action', 'city/' + $(this).val() + '/mobile.php');
});
});
</script>
</head>
<body>
<form name="form" action="" method="get">
Name: <input type="text" name="name"><br>
E-mail: <input type="text" name="email"><br>
<select name="Location" required="required">
<option value="">..</option>
<option value="india">india</option>
<option value="USA">USA</option>
</select>
<input type="submit">
</form>
</body>
</html>
答案 3 :(得分:0)
您可以使用jquery选择操作
$("#selectid").change(function(){
var goaction = $(this).val();
alert(goaction);
$("#yourform").attr("action",goaction);
});