Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add regular button inside form that does not perform a submit

I have this form declaration:

<form method="post" action="/web_services/buscar_vuelos?method=get">   <div id="addSegment_wrapper">     <button class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" id="addTr" style="display: inline;">       <span class="ui-button-text">Add Segment</span>     </button>   </div>   <input id="web_services_submit" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-          text-only" type="submit" value="Search" name="commit"> </form> 

And, although I didn't specify "addSegment_wrapper" button as a submit one, every time I click on it, it calls the form action. I just want to treat this button as a regular one.

What should I do?

like image 208
content01 Avatar asked Jul 07 '11 21:07

content01


People also ask

How do you add a button in a form without submit?

Set it to type="button" to produce a button that doesn't submit the form. In the words of the HTML Standard: "Does nothing."

How do you make HTML form not submit?

The simplest solution to prevent the form submission is to return false on submit event handler defined using the onsubmit property in the HTML <form> element.

Should buttons be inside form?

Yes, structurally the submit button needs to be inside a form element for the document to be valid X/HTML.

Should button be inside form HTML?

In HTML, <input type="button" /> is used to create buttons in an HTML form. Inside the <button> tag, you can place content like text or images. However, this is not the case with the buttons created with <input> tag. The button element has type=button as default outside the form.


1 Answers

You could do

<button type="button">Add Segment</button> 
like image 186
switz Avatar answered Sep 25 '22 16:09

switz