w3c document.forms[0].fieldname equivalent

前端 未结 5 842
眼角桃花
眼角桃花 2021-01-14 03:35

I\'ve been using

document.forms[0].fieldname.value

to get values in javascript from a form, but I\'d like to use a name to reference the f

5条回答
  •  青春惊慌失措
    2021-01-14 04:18

    Would giving the form a name= value and referring to it in the document.forms 'array' by name work?

    i.e.: (much abbreviated)

    .insert.your.elements.here.with.name.attribute.set.

    and in JS:

    document.forms["form1"]["form_item_name"].value;
    

    I'm a rank amateur so if this is wrong, pls leave me a constructive criticism... :-)

提交回复
热议问题