simonkaspers1
simonkaspers1

Reputation: 626

Change value on type=submit

This is a very easy topic, but I don't seem to make any solution on Google work. I am working on a hack-around for a form. I can't add id's or classes. All i have is type=submit. What is the easiest solution to change the text on the button?

$( document ).ready(function() {
    var $input = document.find("input[type=submit]");
    $input.val('OLOLOLOL');
});

OR

$( document ).ready(function() {
        $(':submit').val('OLOLOLOL');
    });

HTML

<input type="submit" value="Submit">

They don't change anything. Is it syntax or something worse? Plain javascript can work too

Upvotes: 1

Views: 65

Answers (4)

Victor
Victor

Reputation: 14573

I would use input[type=submit] selector for the search as in this fiddle:

$("input[type=submit]").val("New value");

As far as I know, jQuery uses the same selectors as CSS does (and many others)!

Upvotes: 2

Bhojendra Rauniyar
Bhojendra Rauniyar

Reputation: 85545

First one works only for input type button but second one works for both input type button as well as button type submit.

So, choice is yours if you want to bind the function anyway if the type is button choose second option.

But I just saw your edited question and would do like this:

$('input[type="submit"]').val("Your Value");

Upvotes: 0

Maurice Perry
Maurice Perry

Reputation: 32831

How about this:

$( document ).ready(function() {
    var $input = $(document).find("input[type=submit]");
    $input.val('OLOLOLOL');
});

Upvotes: 1

Novasol
Novasol

Reputation: 947

i would try this:

$( document ).ready(function() {
    var $input = $(document).find("input[type=submit]");
    $input.val('OLOLOLOL');
});

Upvotes: 2

Related Questions