4
Hello, I have a field on a form that receives the id: "teste"
, how can I catch via javascript
this value and put in a variable??
I found the following on the internet
var str = document.getElementById("teste").value;
But it brings me value undefined
, there is some other way?
My form:
<div class="divFormulario">
@(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("teste").Width("70px").OnKeyPress("key_press").OnEnterKey("enter"));
})
.FormData(Model)
)
</div>
<script>
function enter() {
str = document.getElementById("teste").value;
}
</script>
Inspected page:
Post your HTML file
– Pedro Paulo
Post your HTML and what you tried with Javascript
– Jonathan de Toni
I don’t know what DOM is, my html is there
– Help Me
In javascript I just want to put in a variable the value, that’s all
– Help Me
All right, that was it?
– Help Me
Sorry, I posted the wrong version, I used
.value
msm– Help Me
It will inspect browser elements and see how the field’s HTML looks.
– Sam
Ready, posted in photo because it is easier to understand
– Help Me
@Sam in answer of user139742 I show what I return when I do
innerHTML
, is easier to understand– Help Me