Answered by:
Conditionally change the value of text box

Question
-
User-1355965324 posted
Here my code , I want to change textbox value AmtCallOut set to '0.00' if the value of IsCallout = 0. Please help me how can I set the value if the value of Iscallout = 0
<div class="col-sm-2"> <select class="form-control" asp-for="IsCallOut" data-role="select" selected="selected"
data-parsley-errors-container="#errId7" id='IsCallout"> <option value="0">No</option> <option value="1">Yes</option> </select><span asp-validation-for="IsCallOut" class="text-danger"></span> </div> <label for="lblTJS" class="control-label col-sm-1">Callout charge</label> <div class="col-sm-2"> <input type="text" class="form-control" asp-for="AmtCallOut" id="AmtCallOut"> </div>Thursday, August 1, 2019 6:01 AM
Answers
-
User665608656 posted
Hi polachan,
When I change the Iscallout dropdown from 1 to 0 [Y to N] still no change in the CalloutchargeBecause the code you're using now only judges when the page is loaded, and doesn't judge the event of dropdownlist switching options.
To achieve this function, you need to add dropdownlist change event in jquery, you can refer to the following code:
<script type="text/javascript"> $(function(){ if( $('#IsCallout').val() == 0) { $('#AmtCallOut').val('0.00'); } $("#IsCallout").change(function(){ if($(this).val()== "0") { $("#AmtCallOut").val("0.00"); }else{ $("#AmtCallOut").val("");// you can change what you want value when select value is 1 } }); }); </script>
The result of this work demo:
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 1, 2019 8:22 AM
All replies
-
User-578610739 posted
You are not written that via jquery or Javascript you need the solution.
via Jquery (Add javascript reference first) - Check the links - https://stackoverflow.com/questions/8743975/jquery-how-to-select-dropdown-item-based-on-value
$(document).ready(function () {
if( $('#IsCallout').val() == 0)
$('#
AmtCallOut').val('0.00');
})via Javascript - https://stackoverflow.com/questions/8140862/how-to-select-a-value-in-dropdown-javascript
<script>
if(document.getElementById("IsCallout").selectedIndex = "0")
document.getElementById("AmtCallOut").value= "0"
<script>Thursday, August 1, 2019 7:31 AM -
User-1355965324 posted
I did this code , but still not working. When I change the Iscallout dropdown from 1 to 0 [Y to N] still no change in the Calloutcharge
<script type="text/javascript"> $(document).ready(function () { $("#DateInvoicedPicker").datepicker({ format: 'dd/mm/yyyy', date: new Date(1900, 01, 01), autoclose: true, todayBtn: 'linked' }); $("#DateWorkCarridPicker").datepicker({ format: 'dd/mm/yyyy', date: new Date(1900, 01, 01), autoclose: true, todayBtn: 'linked' }) if ($('#IsCallout').val() == 0) $('#AmtCallOut').val('0.00'); });
Thursday, August 1, 2019 7:57 AM -
User665608656 posted
Hi polachan,
When I change the Iscallout dropdown from 1 to 0 [Y to N] still no change in the CalloutchargeBecause the code you're using now only judges when the page is loaded, and doesn't judge the event of dropdownlist switching options.
To achieve this function, you need to add dropdownlist change event in jquery, you can refer to the following code:
<script type="text/javascript"> $(function(){ if( $('#IsCallout').val() == 0) { $('#AmtCallOut').val('0.00'); } $("#IsCallout").change(function(){ if($(this).val()== "0") { $("#AmtCallOut").val("0.00"); }else{ $("#AmtCallOut").val("");// you can change what you want value when select value is 1 } }); }); </script>
The result of this work demo:
Best Regards,
YongQing.
- Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
Thursday, August 1, 2019 8:22 AM