1

i am trying to change text of a span using onclick of javascript but its not working . Its very simple stuff but i am not sure why its not working

<div class="subscribe_block">
   <h3><span>Stay Connected</span></h3>
   <form method="post" action="" name="subscribeForm">
    <span id="message"></span>
    <p><input type="text" id="name" placeholder="Your Name" /></p>
    <p><input type="text" id="email" placeholder="Email Id" /></p>
    <p><input type="submit" value="subscribe" onClick='document.getElementById("message").value = "Thank you for subscribing";return false;' /></p>
   </form>
  </div>
2
  • js code is in onclick Commented Mar 20, 2014 at 11:23
  • i tried that as well but it dint work Commented Mar 20, 2014 at 11:24

4 Answers 4

1
    <div class="subscribe_block">
   <h3><span>Stay Connected</span></h3>
   <form method="post" action="" name="subscribeForm">
    <span id="message"></span>
    <p><input type="text" id="name" placeholder="Your Name" /></p>
    <p><input type="text" id="email" placeholder="Email Id" /></p>
    <p><input type="submit" value="subscribe" onClick='document.getElementById("message").innerHTML = "Thank you for subscribing";return false;' /></p>
   </form>
  </div>

Use 'innerHTML' instead of 'value'.

Sign up to request clarification or add additional context in comments.

Comments

1

On the onclick function, try changing,

'document.getElementById("message").value = "Thank you for subscribing";return false;'

to

 'document.getElementById("message").innerHTML = "Thank you for subscribing";return false;'

Comments

0

using InnerHtml will set your Span text but as it will post back so you will be unable to see anything. Remove form tag then you will be able to see it.

<div class="subscribe_block">

Stay Connected

<span id="message"></span>
<p><input type="text" id="name" placeholder="Your Name" /></p>
<p><input type="text" id="email" placeholder="Email Id" /></p>
<p><input type="submit" value="subscribe"  onClick='document.getElementById("message").innerHTML= "Thank you for subscribing";return false;'  /></p>

Comments

0

Just change value to innerHTML as

<div class="subscribe_block">
    <h3><span>Stay Connected</span></h3>
    <form method="post" action="" name="subscribeForm">
        <span id="message"></span>
        <p><input type="text" id="name" placeholder="Your Name" /></p>
        <p><input type="text" id="email" placeholder="Email Id" /></p>
        <p><input type="submit" value="subscribe" onClick='document.getElementById("message").innerHTML = "Thank you for subscribing";return false;' /></p>
    </form>
</div>

Comments

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.