I used
document.forms[0].fieldname.value
to get the values in javascript from the form, but I would like to use the name to refer to the field, not 0, what would be the equivalent these days as it <form name="formname">doesn't match?
<form name="formname">
The easiest way is to add an identifier to the input: <input id="fieldname" />and specify a value from JavaScript as follows:
<input id="fieldname" />
document.getElementById('fieldname').value
or if you use jQuery
$('#fieldname').val();
the collection of forms is standard DOM 1, there is nothing wrong with using it.
document.forms.formId.elements.field
name= document.forms ' ?
i.e.: ()
<form name="form1">.insert.your.elements.here.with.name.attribute.set.</form>
JS:
document.forms["form1"]["form_item_name"].value;
, , , pls ...: -)
id getElementById:
var value = document.getElementById('idofelement').value;
(document.forms - , .)
document.forms
a id document.getElementById.
id
document.getElementById
<input type="text" name="fooName" id="fooId" /> ... document.getElementById("fooId").value;
id, document.getElementsByName, , .
document.getElementsByName
document.getElementsByName("fooName")[0].value;
Source: https://habr.com/ru/post/1744927/More articles:https://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1744922/wcf-data-services-consuming-data-from-ef-based-repository&usg=ALkJrhga6t4zRdbzbQd8AnzzW4a_v35myghttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1744923/count-the-no-of-li-then-add-class-to-parent-ul&usg=ALkJrhiuH91EoDuDkwjHQ7V5ikwbiKgcGAHow to apply paging to a dataset? - .netPython 3.1 twitter with library installed - jsonJquery.each(): найти элементы, содержащие входные данные - javascripthow to send email when maxretries reached at nservicebus MSMQ - .netShowing a long string in a spinner without cutting - androidhow to check if there is any consumer in the queue for Ibm Mq - ibm-mqHow to execute a Linq2Sql query in the following dataset - c #В Visual Studio 2010 вы можете автоматически генерировать обработчик событий так же, как С#, используя Visual Basic? - vb.netAll Articles