Trying to change the border color on an onClick event.
If a particular radio button, such as 'Other' is checked, and the user tries to save, I wanted to change the border color to red to let the user know they must enter a value in the input.
$('#nextsales3Btn').on('click', function() {
var ratestructure = $('input[name="ratestructure"]:checked').val(); // radio button
var otherstructure = $('#otherratein').val();
if(ratestructure == "Other" && otherstructure == "")
{
$('#otherratein').css('border', 'red');
console.log('here');
return false;
}
else
{
console.log('all good');
}
});
The above logic works. I can see 'here' in the console when the radio button is checked and the input is empty, but I cannot seem to change the border color of the input.
I tried to use the following to no avail:
$('#otherratein').css('border-color', 'red');
No success there.
How can I make this work?
* EDIT *
Here is how the HTML looks:
<div class="form-row">
<div class="col-md-12">
<div class="form-group">
<label id="ratestructureLabel">Required Rate Structure:</label>
<br/>
<div class="form-check">
<input class="form-check-input" type="radio" name="ratestructure" id="allin" value="all-in">
<label class="form-check-label" for="yesebiz">All-In</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="ratestructure" id="allindest" value="all-inD">
<label class="form-check-label" for="allindest">All-In, subject to Destinations</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="ratestructure" id="allinori" value="all-inO">
<label class="form-check-label" for="allinori">All-In, subject to Origins</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="ratestructure" id="boforindest" value="bofOD">
<label class="form-check-label" for="boforindest">BOF, subject to Origins & Destination</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="ratestructure" id="pernote2" value="pernote2">
<label class="form-check-label" for="pernote2">Per Note 2</label>
</div>
<div class="form-check">
<input class="form-check-input" type="radio" name="ratestructure" id="surcharges" value="surcharges">
<label class="form-check-label" for="surcharges">Surcharges per tariff</label>
</div>
<div class="form-check form-check-inline">
<input class="form-check-input" type="radio" name="ratestructure" id="otherrate" value="Other Rate">
<label class="form-check-label" for="otherrate">Other:</label>
<input type="text" class="form-control ml-2" name="otherstructure" id="otherrateIn" placeholder="">
</div>
</div>
</div>
</div>
'border-color'should be fine.$('#otherrate').css('border-color', 'red');and$('#otherrate')is a radio button:<input class="form-check-input" type="radio" name="ratestructure" id="otherrate" value="Other Rate">