Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

change type attribute from submit to button?

How to change the type attribute from submit to button using JavaScript or jQuery? I use an input element like <input type="submit" name="submitform"/>.

like image 231
av1000 Avatar asked Apr 26 '13 07:04

av1000


People also ask

Can a button be of type submit?

The <button> tag with a type="submit" attribute creates a submit button.

How do I change the submit button text?

The value attribute can be used to change the text of the form submit button. Use value attribute within <input> of type="submit" to rename the button.

What is button type attribute?

The type attribute specifies the type of button. Tip: Always specify the type attribute for the <button> element. Different browsers may use different default types for the <button> element.


2 Answers

Change the property of the native DOM node:

document.getElementsByName("submitform")[0].type = "button";

Do it with jQuery:

$("input[name='submitform']").prop("type", "button");

But remember that you cannot change input types in Internet Explorer 8 and below.

like image 86
James Allardice Avatar answered Oct 17 '22 15:10

James Allardice


You can use setAttribute property something like this in javascript

document.getElementsByName("submitform").setAttribute('type', 'button');

for jQuery

$('input[name="submitform"]').attr("type", "button");
like image 4
chandresh_cool Avatar answered Oct 17 '22 16:10

chandresh_cool