[Javascript] Changing dom values from HTML clicks

Mike Dougherty mdougherty at pbp.com
Thu Jun 5 20:51:22 CDT 2008


On Thu, Jun 5, 2008 at 9:22 PM, Skip Evans <skip at bigskypenguin.com> wrote:

> Okay, I've actually cut out the call to the JS
> file altogether, and now just have this in the
> HTML form with the color selector.
>
> <a href="#"
>
> onclick="document.getElementById('leftcontent').style.background=theme_form.color.value;">
> Left Block Background</a>
>
> So with this it looks like I can simply have one
> link with the onclick call for each style element
> I want the user to be able to change.
>
> Does this look like a sound strategy?
>

I suppose you might have something like this in markup:
<form method="post" action="myformhandler">
  <label for="LeftContentColor">Left Content Color</label>
  <select id="LeftContentColor" name="LeftContentColor"><!-- optionlist here
--></select>
  <input type="submit" value="Update My Scheme"
</form>

This will send the value of the selected option to the server as
"LeftContentColor" when the user activates the submit function.  There is no
need for a non-functional "link" to launch javascript.  If the intention is
to change the
 background color of an element named LeftContent, you could attach an event
listener to either the 'change' or 'blur' methods of the select to enhance
the behavior of that element.  Even without this javascript enhancement,
however, the user would still be able to submit the form.  Assuming the
server-side script is updating the stylesheet for the page, the user would
be able to see their change on the next display of the form.

I have been trying to minimize the duration of my best-practice rants, so if
you would like more dialog; do ask.  (as in "You asked for it!")



More information about the Javascript mailing list