Hi, when we write the code in html that
Username: <input type = "text" name = "Username" value = "VBFORUMS">
Please assist me that what is name attribute and what is value attribute and what is purpose to write and what happens if we don't write it?
Printable View
Hi, when we write the code in html that
Username: <input type = "text" name = "Username" value = "VBFORUMS">
Please assist me that what is name attribute and what is value attribute and what is purpose to write and what happens if we don't write it?
Well Samba, I studied these links but its still not completely clear to me that what is name and value attribute?
I tried akhileshbc, but still not clear to me, that where exactly we need to use?
Name is the attribute to identify that particular element.
And value is the attribute to display a value inside it.
In your example,
the above code will display a text box and it's name is "Username" and inside it, it will display "VBFORUMS".Code:<input type = "text" name = "Username" value = "VBFORUMS">
When you submit a form to a serverside page(eg: PHP, JSP, ASP, etc..), the submitted data would contain the "name" and "value". So, if you want to access the value entered by user in the textbox for "Username", you can use the name attribute to access it.
In PHP, an example would look like this:
So, when you use it like above, the variable "$username" will hold the value entered by the user(eg: "VBFORUMS")PHP Code:$username = $_POST['Username'];
// Above code is for forms submitted via POST method and below is for GET method
$username = $_GET['Username'];
That is the case of server side!
In client side also, this is useful. Say, if you want to validate the username entered by an user. So, via JavaScript, you could access the textbox named "Username" and get its value and check it.
Consider this simple example: in a class there are several students. If those students don't have a name, teacher can't call them and ask them questions(this is an example, so don't ask me whether the teacher could point out some one and ask questions :p)
So, if teacher knows his students names, he could easily call them and ask questions.
So, consider the name of the student as the "Name" attribute and the answer from the student as the "Value" attribute. :)
I hope you understand the idea. :)
:wave: