if select option select fixed value then input field type rupees value support only 20 digit with rupees symbol. if select percentage then replace rupees symbol with percentage of symbol and value type only 2 digit input value with percentage symbol without click a button
my this code working properly but i am facing two small problem
.1 if my webpage load default value set fixed (but input value and rupees symbol not working
.2 if change value then working both condition but value not reset automatically changing state. and if user select percentage single then not change percent value again please check anyone of my code
here is the similar my code
<!DOCTYPE html>
<html>
<head>
<title>Input Field</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
$('#dropdown').change(function() {
var selectedOption = $(this).val();
if (selectedOption === 'fixed') {
$('#inputField').attr('maxlength', '20');
$('#inputField').on('input', function() {
var value = $(this).val();
var formattedValue = '₹' + value.replace(/\D/g, '').replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1,');
$(this).val(formattedValue);
});
} else if (selectedOption === 'percentage') {
$('#inputField').attr('maxlength', '2');
$('#inputField').on('input', function() {
var value = $(this).val();
var formattedValue = value.replace(/\D/g, '') + '%';
$(this).val(formattedValue);
});
}
});
});
</script>
</head>
<body>
<select id="dropdown">
<option value="fixed">Fixed Value</option>
<option value="percentage">Percentage</option>
</select>
<input type="text" id="inputField">
</body>
</html>