Is there a way to do this with basic JS DOM?

Posted by Thomas on Stack Overflow See other posts from Stack Overflow or by Thomas
Published on 2010-04-20T14:43:12Z Indexed on 2010/04/20 14:53 UTC
Read the original article Hit count: 199

Filed under:
|
|

I need to apply/remove to an input field according to a user's selection in a separate drop down form - but I can't figure out how to target the input's class.

I need to add/remove the 'pageRequired' class from this input:

<input  type="text" title="Company Required" name="customfields-tf-2-tf" class="inputclass pageRequired textInput" id="customfields-tf-2-tf" />

When the user selects one of two options from a drop down field. For example:

<select class="dropdown" name="customfields-s-1-s" id="customfields-s-1-s" >
<option value="Owner"<?php if(in_array("Owner",$temp_values)) { ?> selected='selected'<?php } ?>> Owner</option>
<option value="Broker"<?php if(in_array("Broker",$temp_values)) { ?> selected='selected'<?php } ?>> Broker</option>
</select>

If the user selects broker than I want to add the pageRequired class to the first input field and remove it if the user selects Owner.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about forms