To disable/enable a button submit in a form

2019-09-06 15:58发布

I have a form (in a JSP file) with:

  • A textarea named textarea1.

  • A button type submit.

I do this:

... // My form.
String text=request.getParameter("textarea1"); 
if(text!=null){
  ... // ???? 
  ... // Code.
  ... // ????
}

I need to disable my button submit and enable it after (see the comments '????'). Another valid option for me (I think) is blocking and unblocking all my form (textarea and button). How can I do these (disable/enable the button and block/unblock the form)?

2条回答
甜甜的少女心
2楼-- · 2019-09-06 16:52

Solved: :-)

I've got this link:

In a line:

<INPUT TYPE="submit" VALUE="Run" name="1" id="Run"
style="visibility:hidden" 
onClick="this.disabled=true;this.value='Running...";this.form.submit()" 
onmouseover="window.status='INFO: Run.'" onmouseout="window.status=''">

My style is necessary (initially this button has to be hidden).

My sequence:

  1. Button initially hidden (0 characters in my textarea).

  2. I write a character in my textarea.

  3. It appears the button 'Executar' (in English, 'Run').

  4. I click 'Run'. With a single click (always)...

  5. This button (disabled) tells me 'Running...'.

  6. When the execution finishes the button 'Run' disappears, and it reappears if I want to modify the textarea (has some character).

It works with:

  • IE 6 and 9.

  • Mozilla Firefox 9.0.1 and 37.0.

  • Chrome 41.0.

查看更多
冷血范
3楼-- · 2019-09-06 17:03

try this you can use this code for enable and disable button call myfunction() and myfunction1() where you want to enable and disable button.

<!DOCTYPE html>
<html>
<body>

<input type="submit" id="Submit">

<div>Click the enable and disable buttom </Div>

<button onclick="myFunction()">Disable</button>
<button onclick="myFunction1()">Enable</button>

<script>
function myFunction() {
document.getElementById("Submit").disabled = true;
}
function myFunction1() {
document.getElementById("Submit").disabled = false;
}
</script>

</body>
</html>
查看更多
登录 后发表回答