javascript - how to check if period sign(.) is removed from the word in textbox in jQuery? -
i want know if possible hit event if period sign .
removed textbox. example have textbox#quantity
takes numeric values input period sign
and have drop down control#unitvalue
have 3 option
i had hit event on period sign .
key press follows
$("#quantity").keypress(function(e) { if(e.which == 46) { //successfully disabled gram in unit } });
now want enable "gram" option in drop down if period sign .
removed textbox. have idea don't if right so. idea is:- on key press add each letter array, on backspace key press, check if letter on array index period sign .
or not if .
sign enable "gram"
any appreciated
thank you
js fiddle - updated -using .prop()
instead
// attach functionality on multi events $('#inpt').on('keypress input change', function() { var gram = $('#slct').children('[value="1"]'); // if indexof "." > -1, there's dot if ($(this).val().indexof('.') > -1) { // disable gram option gram.prop('disabled', true); // ====================== part added @sarathchandra // reset drop down if gram option selected if ($('#slct').val() === "1" || $('#slct').val() === null) { $('#slct').val("0"); } // ====================== @sarathchandra thank improvement } else { // if dot removed, set disabled prop false gram.prop('disabled', false); } });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <input id="inpt" type="text"> <select id="slct"> <option value="0">- select -</option> <option value="1">gram</option> <option value="2">kilo</option> <option value="3">quntal</option> </select>
edit: @sarathchandra added these couple lines:
if($('#slct').val() == "1" || $('#slct').val() == null){ $('#slct').val("0"); }
to fix when entered value doesn't contain .
, , gram selected then period add, resets dropdown.
Comments
Post a Comment