1

I have a problem adding bootstrap class to button with a function. I want to add the disable class to #eng.

My code:

<li>
  <div class="btnLang">
      <form id="formLang1">
          <button id="slo" class="btn btn-mini disabled">slo</button>
      </form>

      <form id="formLang2" onsubmit='return eng_clicked()'>
          <button id="eng" class="btn btn-mini">eng</button>
       </form>
  </div>
</li>

<script type="text/javascript">
function eng_clicked(){
    $('#eng').addClass("disabled");
}
</script>
6
  • How do you send the form?, because with the button "eng" it doesnt, so the function eng_clicked is never fired and the class never added Commented Jul 4, 2013 at 21:16
  • I tried to fire the alert in my function and did worked but it doesn't when i am adding class. Commented Jul 4, 2013 at 21:20
  • Do you get any errors in Firebug/Web Inspector? I guess $ is not defined. Commented Jul 4, 2013 at 21:23
  • Are you sure it worked? the "eng_clicked" function it will be only fired if you have a submit input inside the form. Commented Jul 4, 2013 at 21:27
  • Nope. i don't get any. Commented Jul 4, 2013 at 21:28

2 Answers 2

2

you forgot the script tag

<script type="Text/javascript">
//scripts
</script>

Anyway I have better solution for you using jQuery, just remove "onsubmit='return eng_clicked()'" and and replace the codes below instead of your codes:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.0/jquery.min.js"></script>
<script type="text/javascript">
$("#formLang2").click(function() {
  $('#eng').addClass("disabled");
});
</script>
Sign up to request clarification or add additional context in comments.

Comments

0

have you add the script tag?

<script type="text/javascript">
function eng_clicked(){
    $('#eng').addClass("disabled");
}
</script>

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.