Hi i have a form with some dropdowns and text fields .If i am selecting a value from dropdown the text field value should be changed. In dropdown if i am selecting the value as YES then it should display " Not Applicable" value in text field for ( previous_employment ). If selected NO then it should display the blank text field where user can add their own data.
$(document).on("change", "#full_part_time", function() {
var full_part_time = $(this).val();
if (full_part_time == "yes") {
$(".dropdownselection").addClass("hidden");
$("#full_part_time_details").removeClass("hidden");
} else {
$(".dropdownselection").removeClass("hidden");
$("#full_part_time_details").addClass("hidden");
}
});
$(document).ready(function() {
var full_part_time = $("#full_part_time").val();
if (full_part_time == "yes") {
$(".dropdownselection").addClass("hidden");
$("#full_part_time_details").removeClass("hidden");
} else {
$(".dropdownselection").removeClass("hidden");
$("#full_part_time_details").addClass("hidden");
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="form-group">
<label for="full_part_time" class="col-sm-12 control-label" style="text-align:left;">49. I do hereby declare that I am not in full/Part time employment/service not Engaged in any trade/business or profession either previous or at present. </label>
<div class="col-sm-12">
<select name="full_part_time" id="full_part_time">
<option value="no">no</option>
<option value="yes">yes</option>
</select>
<input type="text" class="hidden" id="full_part_time_details" value=" NOT EMPLOYED ANYWHERE " readonly/>
<div class="dropdownselection ">
<p>After my retirement, I am not in full or part time employment or Service not engaged in any trade or business or profession till today.</p>
<p>Service Candidates shall upload following documents along with service Affidavit. </p>
<ul style="list-style:none;">
<li>1. Retirement Order / Service Certificate.</li>
<li>2. Permission Letter from Employer</li>
<li>3. Proof of working during study period of LAW</li>
<li>4. Law T.C.</li>
</ul>
</div>
</div>
</div>
<div class="form-group">
<label for="previous_employment" class="col-sm-12 control-label" style="text-align:left;">50. Give Particulars of your previous employment or service or trade or business or Profession as under ( enclose necessary proof).</label>
<div class="col-sm-12">
<input type="text" value="Not Applied" name="previous_employment" id="previous_employment" placeholder="Enter your previous employment details">
</div>
</div>
My Answer:
"Text field value changed to YES" in the text field, and if I select NO, it should display "Text field value changed to NO" in the text field.
Here is an example code using jQuery to achieve this functionality:
html
In this code, we are using jQuery to listen for the change event on the dropdown element with id "dropdown". When the dropdown value changes, we get the selected value and based on that value, we set the text field value accordingly.
© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog | Privacy Policy | Terms & Conditions | Contact Us
Create blog | Privacy Policy | Terms & Conditions | Contact Us
Rate this post
3 of 5 based on 6084 votesComments