https://jsfiddle.net/vxLurdyb/1/
When the user selects YES in the membership dropdown, the value of the input should change from "service_######" to "membership##_####" which I have been trying to do with replace(), as well as make the change clearly visible to the user, but it stays the same both visually and when the form is sent.
<div class="col">
<div class="form-group col-md-6">
<label class="" for="membership">¿Membership?</label>
<select name="membership" id="membership" class="form-control input-sm">
<option value="0">NO</option>
<option value="1">YES</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="exampleInputEmail1" class="light-label">ID</label>
<input type="text" class="form-control" name="invoice_id" id="invoice_id" value="service_id_19_0022" readonly>
</div>
</div>
$('#membership').change(function(e){
if( $(e.target).val() == 1 ){
changeServiceId();
}
});
function changeServiceId(){
$('#invoice_id').prop('readonly',false);
var invoiceid = $('#invoice_id').val();
console.log(invoiceid);
var invoiceid = invoiceid.replace(/service/, 'membership');
$('#invoice_id').attr('value').replace(/service/, 'membership');
console.log(invoiceid);
$('#invoice_id').prop('readonly',true);
}
As you can see I tried both attr('value') as well as value() but it seems Im doing something wrong