开发者

submit button grayed out

I have a submit button on a form that is quite important. I do not want users clicking it more than once. Is there a way to make it unclickable or grayed out after they click it. (maybe an on click event?). My simp开发者_开发问答le code is below

<form method='POST'  action='index.php'>
<input type='text' name='text' id='text'>
<input type ='submit' value='submit' name='submit'>
</form>


You can use an onclick event to grab the button and set its disabled property to true.

<input type ='submit' value='submit'
       id="my_submit_button"  name='submit' 
       onclick="document.getElementById('my_submit_button').disabled = 'disabled'">

The syntax of the disabled attribute is pretty stupid, why it's not boolean I don't know but it is what it is:

http://www.w3schools.com/tags/att_input_disabled.asp


Just add the following onClick attribute to your button:

<input type="submit" value="submit" name="submit" 
onclick="
  if(!submitted) {
    this.value = 'Please wait...';
    this.disabled = true;
    submitted = true;
    return true;
  } else {
    return false;
  }
">
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜