Back to Top
The nuts and bolts for
Creative web development

Disable button when none selected

Q:

How can i disable a button within a form untill a selection is made, for example when using a poll form ?

A:

Use this piece of JavaScript to initially disable (true) the button and when a visitor makes a selection it enables (false) the button with an OnClick event.

Example code:

<form name="Poll" method="post" action="">
  <table>
    <tr>
      <td>
        <input type="radio" name="radiobutton" value="radiobutton" onClick="document.Poll.Submit.disabled=false">
      </td>
      <td>1</td>
    </tr>
    <tr>
      <td>
        <input type="radio" name="radiobutton" value="radiobutton" onClick="document.Poll.Submit.disabled=false">
      </td>
      <td>2</td>
    </tr>
    <tr>
      <td>
        <input type="radio" name="radiobutton" value="radiobutton" onClick="document.Poll.Submit.disabled=false">
      </td>
      <td>3</td>
    </tr>
    <tr>
      <td>
        <input type="radio" name="radiobutton" value="radiobutton" onClick="document.Poll.Submit.disabled=false">
      </td>
      <td>4</td>
    </tr>
    <tr>
      <td>
        <input type="radio" name="radiobutton" value="radiobutton" onClick="document.Poll.Submit.disabled=false">
      </td>
      <td>5</td>
    </tr>
    <tr>
      <td> 
    <input type="submit" name="Submit" value="Submit">
      </td>
<SCRIPT language="JavaScript">
document.Poll.Submit.disabled=true;
</SCRIPT>
    </tr>
  </table>
</form>

Example output:

Marcellino Bommezijn

Marcellino BommezijnMarcellino Bommezijn is one of the managers at dmxzone.com. He is a contributor on the tutorials section.

Owner of Senzes Media (http://www.activecontent.nl) which provides professional services and web applications for mid-sized companies.

ActiveContent CMS is the ASP.NET Content Management solution that is used for building professional and rich-featured websites.

See All Postings From Marcellino Bommezijn >>

Share this Article