Jump to content

HTML5 Form - Input name=


careyd
 Share

Recommended Posts

Inside of a <form>, is the input name=( fieldname1 ) able to be addressed in JavaScript as a variable? such as {fieldname1 == fieldname2}

Link to comment
Share on other sites

You have to access the element using DOM methods. The easiest way is to give the element an ID. Once you have the element, you have to use the value property to get the user's input.

 

HTML

<input id="form-input" type="text" name="field-name">

Javascript

// Get the elementvar element = document.getElementById("form-input");// Get its valuevar value = element.value;// Do something with the value, for example:if(value == "something") {    // Do something}
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...