I was learning how to code an HTML form and I have few questions regarding the example I came across.
What is the difference between value and name in layman terms?
Why the value in the first two label's input left as an empty string?
Why the the third label's select is given a name but not a value, while the following 3 options were given values only?
In the 5th label input there is an S attribute after value, what does it mean?
Why the 6th label's input was given both name and value?
Why the name of the 6th input was "facilities[]", does this has anything to do with arrays?
Again, why the 8th label's input has name and value but it's button has class and name?
I really need answers specific to each label, as I am still a beginner in web development.
Here is my code:
<form id="registration_form" method="POST">
<!-- 1st-->
<label>Full name*:</label>
<br>
<input type="text" name="full_name" placeholder="FirstName LastName" autofocus="autofocus" value="">
<br>
<!-- 2nd-->
<label>Email address*:</label>
<br>
<!-- value leaves input box empty-->
<input type="text" name="email_addr" value="" placeholder="[email protected]">
<br>
<!-- 3rd-->
<label>Select Tour Package* :</label>
<br>
<select name="package">
<option value="Goa">Goa</option>
<option value="Kashmir">Kashmir</option>
<option value="Rajasthan">Rajasthan</option>
</select>
<br>
<!-- 4th-->
<label>Arrival date*:</label>
<br>
<input type="text" name="arv_dt" placeholder="m/d/y" value="">
<br>
<!--5th -->
<label>Number of persons*:</label>
<br>
<input type="text" name="persons" value="" s>
<br>
<!-- 6th-->
<label>What would you want to avail?*</label>
<br>Boarding
<input type="checkbox" name="facilities[]" value="boarding">
<br>Fooding
<input type="checkbox" name="facilities[]" value="fooding">
<br>Sight seeing
<input type="checkbox" name="facilities[]" value="sightseeing">
<br>
<!-- 7th-->
<label>Discout Coupon code:</label>
<br>
<input type="text" name="dis_code" value="">
<br>
<!-- 8th-->
<label>Terms and conditions*</label>
<br>
<input type="radio" name="tnc" value="agree" checked>I agree
<input type="radio" name="tnc" value="disagree">I disagree
<br>
<button type="submit" class="btn btn-large btn-primary" name="submit">Complete reservation</button>
</form>
The name attribute is the name of the element. For example, it can be used by the server to identify the fields in form submits. In a case like
facilities[], it will put all input values with that name into a single array when received by the server.The value attribute is a default value which will be displayed in the element on page load. This value will also be posted to the server and associated back to the name.
Classes are often times just used for CSS properties or JavaScript and aren't really relevant to anything else in your question.
For the
Sattribute in your case, it likely means nothing and was just a typo. It can have some meaning if you were using something like Angular's directives