You are viewing limited content. For full access, please sign in.

Question

Question

How to desactivate a button with onclick?

asked on March 12, 2018

Hi all,

 

I'm trying to desactivate a button using html and javascript.

 

This is my html

 

And this is my javascript

 

When I'm clicking on, from the server, the form is submitted and loaded one more time.

From another computer, I have this error

 

What's going on?

 

Thanks in advance.

Regards

 

 

0 0

Answer

SELECTED ANSWER
replied on March 14, 2018 Show version history

Hi Karina,

 

Thank you for your help.

I added the type but I have no result. My button doesnt disabled.

 

This is what I did.

HTML

<button id="myBtn2" type="button">Chercher</button>

 

Javascript

$('#myBtn2').click(function ()
    {
      ..action
    })

 

And now it's working. Thank you very much

1 0

Replies

replied on March 12, 2018

You should add the type="button" to the HTML. In your case:
 

<button onclick="myFunction()" id="myBtn2" type="button">Chercher</button>

 

1 0
SELECTED ANSWER
replied on March 14, 2018 Show version history

Hi Karina,

 

Thank you for your help.

I added the type but I have no result. My button doesnt disabled.

 

This is what I did.

HTML

<button id="myBtn2" type="button">Chercher</button>

 

Javascript

$('#myBtn2').click(function ()
    {
      ..action
    })

 

And now it's working. Thank you very much

1 0
replied on March 14, 2018

Glad it is working! My previous comments were meant to address the error you were receiving in Forms. When writing buttons in Forms, the type="button" should be added to avoid errors. Alternately, you can style other elements (e.g. links) to look and act like buttons.

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.