I have this code that generates an item code when the combo-boxes
are selected.
For example, if Computer Equipment
and Printer
is selected, the script would generate the code CEPR000001
and display it on the textbox. It was working last March but now it suddenly stopped working. Can someone help me with this?
Script:
function pad(num, size) {
var s = num+"";
while (s.length < size) s = "0" + s;
return s;
}
function getAssetCode() {
document.getElementById("code2").value = $('#class').find(":selected").data('value') + 1;
var x = document.getElementById("cat").value;
var y = document.getElementById("class").value;
var z = document.getElementById("code2").value;
var result = pad(z, 6);
var xyz = x.concat(y,result);
$('#code').value(xyz);
}
HTML:
<select class="form-control" name="assetcategory" id="cat" required>
<option value="CE">Computer Equipment</option>
<option value="OP">Other Properties</option>
</select>
<select class="form-control" name="assetclass" id="class" onchange="getAssetCode()" required>
<option value="PR" data-value="1">Printer</option>
<option value="CP" data-value="2">Mobile Phone</option>
</select>
<input type="text" class="form-control" name="assetcode1" id="code" disabled>
<input type="text" class="form-control" name="assetcode2" id="code2" hidden>
Firstly you need to include jQuery in your question, not sure if this is already done but add the following line to head
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
Secondly, you need to change :
$('#code').value(xyz);
to
$('#code').val(xyz);
Working fiddle https://jsfiddle.net/fcozp36v/
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments