0
I have a problem, I need to get the value typed in a field, I thought to use OnKeyPress
calling the function key_press
as follows:
var str;
var keycode;
function key_press(e) {
var event = e.event, keyCode = event.key || String.fromCharCode(event.which);
if (keyCode != "Enter") {
event = e.event, str = event.key || String.fromCharCode(event.which);
if (/^[\.\,e]$/.test(str))
event.preventDefault();
}
}
So far everything ok, he performs it the right way, I added the .OnEnterKey("enter")
for it to perform the following function :
function enter() {
for (var i = 0; i < parseInt(str); i++) {
$("#gridContainer2").dxDataGrid("addRow");
}
}
What’s wrong with my job key_press
it takes the value that is passed every time a number is typed, ie if I type 1 it picks up normal, if I type 8 too, but when I step 2 numbers this is no longer right, because the var str
now receives the second digit I put; ex: I typed 23 and gave Enter
to var str
receives only the 3, because executed the function key_press
and received 3, how can I get all the value of the field?? ex: typed 15, I want that str
receive 15
and run the 0 to 14, I’ve been researching and told to use the following : document.getElementById("ID DO ELEMENTO").value
, but every time I use it, I get value undefined
My field on the form:
@(Html.DevExtreme().Form<FormaPagamentoViewModel>
()
.ID("formularioCadastro")
.ShowValidationSummary(false)
.Items(items =>
{
items.AddGroup()
.Items(groupItems =>
{
groupItems.AddSimpleFor(m => m.Fpg_quantidade)
.Editor(e => e.NumberBox().ID("qua").Width("70px").OnKeyPress("key_press").OnEnterKey("enter")); //esse campo que estou usando
});
})
.FormData(Model)
)
stores and concatenates what you type into an auxiliary var, then, in enter, you go to auxiliary. Understood?
– cpll
The ideal would be to call the function in the Blur, Leave or even leave a range in the keyUp to identify which user stopped typing and whether the value is valid
– Leandro Angelo
@cpll, it’s a good idea, but I don’t know how to put in an auxiliary variable the values
– Jeff Henrique
@Leandroangelo I don’t know how to do the things you said
– Jeff Henrique