Jump to content

Which Of These Are Valid Html 5 Button Code ?


2020

Recommended Posts

Hi Folks,

 

Which html button do you use out of these ? Which one is html5 and which ones are old timers ?

1.

	<button type="submit">Search</button>
	

 

Shouldn't this be:

	<button type="search">Search</button>
	

Or it is still "type='submit' because it submits search request to db ?

 

2.

https://www.w3schools.com/tags/att_button_type.asp

	<button type="submit" value="submit">Search</button>
	

 

3.

https://www.htmlquick.com/reference/tags/input-submit.html

	<input type="submit" value="Send Data">
	

 

I am spoilt for choice. Which one should I stick to ?

Or, you got a better simpler one that works with all types of html 5 and php ?

Not interested in complicated css buttons as of now.

Link to comment
Share on other sites

Folks,


Look at these 3 buttons:

	<button type="submit">Submit</button>
<button type="submit" value="submit">Search</button>
<input type="submit" value="Send Data">
	

Look at number 3:

value="Send Data"


That means, the "value=" represents the button label.


Now, look at number 2:

value="submit">Search</button>


Definitely, the "value=" does not represent the button label.

As this represents the button label:

>Search</button>

Q1. Why "value=" means 2 different things on 2 different buttons ?

Usually, on input fields, the "value=" represents the user's input.

So, what does the "value=" represent on button number 2 since it doesn't represent the button label ? Certainly not a user's input since user cannot type anything onto a search/submit button!

Just what is going on here ? I am confused, like hell! Who'd like to enlighten me ?


Thanks

Edited by 2020
Link to comment
Share on other sites

5 minutes ago, 2020 said:

Usually, on input fields, the "value=" represents the user's input.

The user doesn't input the value on checkboxes or radio buttons

<button>s are just another type of html element which allow the programmer to set a value independent of its label.

In the example below, the value of the clicked button would be sent in $_POST['gender']

<button name='gender' value='M'>Male</button>
<button name='gender' value='F'>Female</button>

 

  • Like 1
Link to comment
Share on other sites

2 hours ago, Barand said:

The user doesn't input the value on checkboxes or radio buttons

<button>s are just another type of html element which allow the programmer to set a value independent of its label.

In the example below, the value of the clicked button would be sent in $_POST['gender']


<button name='gender' value='M'>Male</button>
<button name='gender' value='F'>Female</button>

 

Thanks! That was a very good example. Things clear now!

I am going to make use of this button code now. use the buttons similar to drop down options!

Edited by 2020
Link to comment
Share on other sites

Only the last button works for me on my following thread. I got the button suggested to me on another forum.

	<button type="submit">Submit</button>
<button type="submit" value="submit">Submit</button>
<input type="submit" value="submit">
<button name=submit value=" ">Submit</button>
	

https://forums.phpfreaks.com/topic/311105-why-insert-fails-with-prepared-statement/?tab=comments#comment-1579730

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.