admin管理员组

文章数量:1332345

I need to change the value of this submit button from "Send" to "MyString":

<input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" wtx-context="A7CF2DEB-43B6-43C4-8572-9624A3E7F524">

This code snippet was created in WordPress using Contact Form 7, and I cannot alter it, so unfortunately I can't use getelementbyid.

I tried this but it doesn't work:

<script>
document.getElementsByClassName("wpcf7-submit").value = 'MyString';
</script>

Help!

I need to change the value of this submit button from "Send" to "MyString":

<input type="submit" value="Send" class="wpcf7-form-control wpcf7-submit" wtx-context="A7CF2DEB-43B6-43C4-8572-9624A3E7F524">

This code snippet was created in WordPress using Contact Form 7, and I cannot alter it, so unfortunately I can't use getelementbyid.

I tried this but it doesn't work:

<script>
document.getElementsByClassName("wpcf7-submit").value = 'MyString';
</script>

Help!

Share Improve this question edited Sep 10, 2018 at 11:45 AbyxDev 1,58519 silver badges33 bronze badges asked Jun 30, 2018 at 16:00 sanitychecksanitycheck 2983 silver badges17 bronze badges 2
  • "Doesn't work" is not a clear problem statement (see minimal reproducible example). Do you have errors in the console? Where do you run this - in the header, or the footer? (It may be that the form doesn't exist when the script runs). Lastly, getElementByClassName returns an array of elements, so at a minimum you'd need to do: document.getElementsByClassName("wpcf7-submit")[0].value = 'MyString'; – random_user_name Commented Jun 30, 2018 at 16:02
  • Sorry for not being precise enough. My code did not produce the required change in the submit button text. The text did not change at all. You'll note below that I found Contact Form 7's intended method for producing the change successfully. – sanitycheck Commented Jul 1, 2018 at 23:39
Add a ment  | 

3 Answers 3

Reset to default 3

Never mind ... it was absurdly simple.

In the Contact Form 7 editor, I change:

[submit "Send"] to [submit "MyString"]

You were very close! Since document.getElementsByClassName("wpcf7-submit") returns an object, you have to use:

document.getElementsByClassName('wpcf7-submit')[0].value = 'MyString';

It returns an object, because there could be multiple elements which also include the same class. So in this case with [0] you would select the first element with the class wpcf7-submit.

Also if some one still having issue with submit button text like me after seeing the sanitycheck.

then must be using submit butto like this.

[submit "Submit" class:submit-button]

so, simply use it this way will work.

[submit class:submitBtn "Submit"]

not the diff is put the "Submit" text at the end will make it work.

本文标签: javascriptChange Value of Submit Button in WordPress Contact Form 7Stack Overflow