JavaScript Question

by "Ben Bradley UK" <bradley(at)mudmail.co.uk>

 Date:  Sat, 23 Sep 2000 16:27:05 +0100
 To:  "HWG" <hwg-basics(at)hwg.org>
  todo: View Thread, Original
Now there is something I've been trying to achieve using JavaScript as a
learner's project.
I have a form called domForm
And a checkbox input called portHost
Now, I want another input (more when I get just one working) to change class
if portHost is checked. At the moment I have 2 classes in my external style
sheet for this task - enabled and disabled (disabled not meaning the
disabled property that can be applied to form inputs).

Here's what I've got in <head at the moment
----------
<script type="text/JavaScript" language="JavaScript">
<!--
  function dnsMods() {
    if (document.domForm.portHost.checked) {
      document.domForm.ip2.className = disabled;
    } else {
      document.domForm.ip2.className = enabled;
    }
  }
// -->
</script>
------------
So, I've got an onClick event performing dnsmods() on the portHost checkbox.
So, If portHost is checked, then I want the textbox ip2 to be disabled. But
if it is not checked, i'd like ip2 to use the enabled class.

I got the idea for the need for a script that did this because I found out
how to disable a form input using almost the above method (apart from
instead of className, with disabled = true; at the end) but when you disable
a form input, the data from that input is not sent to the action="" (be it
CGI or by email). So what I did, I made a class called disabled in CSS which
still greys out the text but still allows users to change it - hopefully
they won't try.

Hope one of you guys can see what I'm getting at and how I've batched it up
as I don't even know where to begin.


Ben Bradley UK
Creative Director
http://www.thenetzone.co.uk

HTML: hwg-basics mailing list archives, maintained by Webmasters @ IWA