I have a contact form like this
<form action="" method="POST">
<div>
<fieldset>
<p dir="rtl">
<label>case1</label>
<select id="Color" required="required">
<option value="">please select</option>
<option value="redd">sell</option>
<option value="greenn">rent</option>
</select>
</p>
</fieldset>
</div>
<div class="redd box">
<input dir="rtl" type="text" name="pricerange" required />
<input dir="rtl" type="text" name="room" />
</div>
<div class="greenn box">
<input dir="rtl" type="text" name="rentrange" required />
<input dir="rtl" type="text" name="morgage" />
</div>
<p dir="rtl"><input name="submit" type="submit" value="submit" /></p>
</form>
As you see I show or hide two div box "redd box" and "greenn box" based on the value which user select from drop down list in the beginning of the form. as you see I have required input and optional input in this div boxes. but when I select one of these divs I have to fill both required and optional fields otherwise I can not submit my form. any idea?Thanks
$(document).ready(function(){
$("#Color").change(function () {
$(this).find("option:selected").each(function(){
if($(this).attr("value")=="redd"){
$(".box").not(".redd").hide().find("input").prop("required", false);
$(".redd").show().find("input").prop("required", true);
}
else if($(this).attr("value")=="greenn"){
$(".box").not(".greenn").hide().find("input").prop("required", false);
$(".greenn").show().find("input").prop("required", true);
}
else{
$(".box").hide();
}
});
}).change();
});