JavaScript to enable the submit button (doesn't work)

I need the submit button to be disabled if JavaScript is not enabled.

I tried:

1.

<input onLoad="this.disabled=false" id="post-comment" type="submit" 
value="Post Your Comment" disabled="disabled"/>

2.

<input onLoad="this.removeAttribute('disabled');" id="post-comment" type="submit"
value="Post Your Comment" disabled="disabled"/>

3.

<input onLoad="document.getElementById('post-comment').removeAttribute('disabled');"
id="post-comment" type="submit" value="Post Your Comment" disabled="disabled"/>

Does not work. I am new to JavaScript but cannot find the answer online.

+3
source share
7 answers

The problem is that input elements do not have an "onload" event. The specification shows the available events as:

  onfocus     %Script;       #IMPLIED  -- the element got the focus --
  onblur      %Script;       #IMPLIED  -- the element lost the focus --
  onselect    %Script;       #IMPLIED  -- some text was selected --
  onchange    %Script;       #IMPLIED  -- the element value was changed --
  onclick     %Script;       #IMPLIED  -- a pointer button was clicked --
  ondblclick  %Script;       #IMPLIED  -- a pointer button was double clicked--
  onmousedown %Script;       #IMPLIED  -- a pointer button was pressed down --
  onmouseup   %Script;       #IMPLIED  -- a pointer button was released --
  onmouseover %Script;       #IMPLIED  -- a pointer was moved onto --
  onmousemove %Script;       #IMPLIED  -- a pointer was moved within --
  onmouseout  %Script;       #IMPLIED  -- a pointer was moved away --
  onkeypress  %Script;       #IMPLIED  -- a key was pressed and released --
  onkeydown   %Script;       #IMPLIED  -- a key was pressed down --
  onkeyup     %Script;       #IMPLIED  -- a key was released --

Since this does not seem like any of them will help you, it is probably best for you to add the event to the loading of the body element (or using more reliable means such as the jQuery ready document function). Here is a quick way to hack:

<body onload="document.getElementById('post-comment').disabled=false">
+4
source

Do you want to:

<input id="post-comment" type="submit" value="Post Your Comment" disabled="disabled"/>
<script type="text/javascript">
document.getElementById("post-comment").disabled = false;
</script>

: onload?

+2

:

<script> 
function enableInput(){
    document.getElementById('post-content').disabled=false;
}
</script>
<body onload="enableInput();">
...
<input id="post-comment" type="submit" 
    value="Post Your Comment" disabled="true"/>

javascript, - (, , javascript.

+1

<input id="post-comment" type="submit" value="Post Your Comment" disabled="disabled" />

javascript

<script type="text/javascript">
   window.onload = function() {
     document.getElementById('post-comment').disabled=false;
   }

   //OR using JQuery
   $(document).ready(function() {
      document.getElementById('post-comment').disabled=false;
   });
</script>

//That it really.

, .

+1

" javascript ", , , JS ?

, . JS-, (<! - β†’ ). <noscript> , , JS .

+1

, javascript, .

0

onload submit Javascript. , Javascript, .

:

, , greyed out. - :

<img onLoad="enableSubmit()" .../>

onLoad , Javascript. enableSubmit() ( ) img input type="submit".

0

Source: https://habr.com/ru/post/1737441/


All Articles