0

I have a form like this:

<form action="#contact-form" method="post" class="th_contact-form" id="id-59907491">

<div class="form_line">
        <label for="widget-2-your-email" class="th-field-label email" style="display:none;">Your Email<span>(required)</span></label>
        <input type="text" name="widget-2-your-email" id="widget-2-your-email" placeholder="Your Email" class="email">
</div>
<div class="th_contact-submit">
        <input type="submit" value="submit" class="th_button">
</div>

I want to change the value="submit" to say value="click here"

How do I do that using javascript? I do not have the liberty of changing the form code as it is auto-generated via a theme in wordpress, and they don't have the option of changing the button text.

2 Answers 2

4

Fastest way: document.querySelector("#id-59907491 [type=submit]").value = "click here";

Most stable way:

var frm = document.getElementById('id-59907491'),
    inp = frm.getElementsByTagName('input'),
    l = inp.length, i;
for(i=0;i<l;i++) {
    if( inp[i].type == "submit") {
        inp[i].value = "click here";
        break;
    }
}
Sign up to request clarification or add additional context in comments.

Comments

2

Assuming there is only one button with the th_button class:

window.onload = function () {

    var button = document.getElementsByClassName( 'th_button' )[0];
    button.value = "Click Here";

};

1 Comment

Unsupported in IE8 and below.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.