How to disable button when checkbox is checked. vbscript?

Html and javascript. checkbox to textbox?

  • So i have to use information from a checkbox and put it in a textbox when a submit button is pressed. And i don't know what function to use. So here's my checkbox. <form action="" name="sport"> <p><strong>What is your favorite sport?</strong></p> Basketball: <input type="checkbox" name="check" value="Basketball" onclick="Basketball" /> Football: <input type="checkbox" name="check" value="Football" onclick="Football"/> Hockey: <input type="checkbox" name="check" value="Hockey" onclick="Hockey" /> Soccer: <input type="checkbox" name="check" value="Soccer" onclick="Soccer" /> </form> And here's the textbox where i need to transfer the information of the checked boxes to. <form action="" name="activity"> <strong>Do you want something to do today?</strong> <input type="submit" value="Yes" onclick="" /> <input type="text" name="answer" /> </form> How do i do this?

  • Answer:

    A LOT depends on whether this is all on the same page or not. you didn't say. it would be awfully useless if it was. <head> <script type="text/javascript"> function doit() { var s=""; if ( document.forms[0].Basketball.checked ) { s=s+"Basketball "; } if ( document.forms[0].Football.checked ) { s=s+"Football "; } if ( document.forms[0].Hockey.checked ) { s=s+"Hockey "; } if ( document.forms[0].Soccer.checked ) { s=s+"Soccer "; } document.forms[1].answer.value=s; </script> </head> your onclick is written wrong - there is no javascript function named Basketball(), etc. so eliminate it. you might want to try onchange instead of onclick, either might work, but both work differently. change all the onclick functions to onclick="doit()" there is a 50% chance of the code working. the javascript code must be executed after the document has loaded for the form elements to be valid so you can access them in js.

Nonyabus... at Yahoo! Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.