0

I am using the code below to submit values to my db.

<input id="btn_'.$temp['id'].'" value="Confirm" style="background: #409940; border-radius: 10px; color: white;" type="button" onclick="validaLink(\''.$temp['id'].'\');"> 

Problem:

with in 2 secs , multiple clicks are submitted with the same value, till the div fads out.

What I have done:
I tried to disabled the form button after submit. but i guess 2 onclick events does not work.

suggestions / code corrections please

6
  • Consider looking into using sessions and tokens phpro.org/tutorials/Preventing-Multiple-Submits.html as a server-side method, in conjunction with the other comments below. Commented Sep 18, 2014 at 19:05
  • 4
    onclick="javascript:window.open(\''.$temp['shorten'].'\'); this.disabled = true;" Commented Sep 18, 2014 at 19:06
  • 2
    Maybe add this.disabled=true; after your window.open(\''.$temp['shorten'].'\'); Commented Sep 18, 2014 at 19:06
  • This answers your question :) Commented Sep 18, 2014 at 19:07
  • 1
    The comment and link from Nischaal does not answer this question. Joao Paulo's answer is most appropriate for this question. Commented Sep 18, 2014 at 19:17

2 Answers 2

3

Try this

onclick="javascript:validaLink(\''.$temp['id'].'\'); this.disabled = true;" 
Sign up to request clarification or add additional context in comments.

1 Comment

please check the new code .. earlier i copied the wrong line here
0

The following code will disable the onclick event handler for the button after the first click, and also disable the button itself.

onclick="this.onclick=null;this.disabled = true;validaLink(\''.$temp['id'].'\');" 

2 Comments

the problem that i am facing .. is ,, if i make 20 clicks , before the button disappears. 20 records will be added to the db
please check the new code .. earlier i copied the wrong line here –

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.