如何通过选择单选按钮选项更改文本表单字段



我有两个选项1-假期2-长期现在我想要的是当我从单选按钮中选择这些选项时,表单将被填充,并且表单具有以下字段:

1-季节2-日期3-每天4-每周5-每月

现在我想要的是,当我选择长期值时,我想从弹出表单中只显示每月字段,如果我选择假期,所有字段都应该显示。

我的html,这些选项是:

<div class="m-b-10 m-t-10">
<label class="radio-inline">
<input type="radio" id="inlineCheckbox1" value="is_vacation" name="property_type" checked> Vacation
</label>
<label class="radio-inline">
<input type="radio" id="inlineCheckbox2" value="is_long_term" name="property_type"> Long Term
</label>
</div>

和我的控制器

if ($search == "vacationRental") {
// $properties = Property::where('is_vacation', '=', 1)->get();
$properties = Property::where('status', '=', 1)->where('is_vacation', '=', 1)->get();
return view('admin.property.index')
->with('properties', $properties)
->with('seasons', $seasons);
} elseif ($search == "longTerm") {
// $properties = Property::where('is_long_term', '=', 1)->get();
$properties = Property::where('status', '=', 1)->where('is_long_term', '=', 1)->get();
return view('admin.property.index')
->with('properties', $properties)
->with('seasons', $seasons);
}

我需要为此创建一个新的视图吗?或者可以用JS来完成。我认为可以用JS完成,但我不知道如何做到这一点。需要你的帮助

我们将非常感谢您的帮助!

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery Show Hide Elements Using Radio Buttons</title>
<style type="text/css">
.box{
color: #fff;
padding: 20px;
display: none;
margin-top: 20px;
}
.red{ background: #ff0000; }
.green{ background: #228B22; }
.blue{ background: #0000ff; }
label{ margin-right: 15px; }
</style>
<script src="https://code.jquery.com/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('input[type="radio"]').click(function(){
var inputValue = $(this).attr("value");
var targetBox = $("." + inputValue);
$(".box").not(targetBox).hide();
$(targetBox).show();
});
});
</script>
</head>
<body>
<div>
<label><input type="radio" name="colorRadio" value="red"> red</label>
<label><input type="radio" name="colorRadio" value="green"> green</label>
<label><input type="radio" name="colorRadio" value="blue"> blue</label>
</div>
<div class="red box">You have selected <strong>red radio button</strong> so i am here</div>
<div class="green box">You have selected <strong>green radio button</strong> so i am here</div>
<div class="blue box">You have selected <strong>blue radio button</strong> so i am here</div>
</body>
</html>

这是一个示例,你可以参考

最新更新