AA11oAKas
AA11oAKas

Reputation: 819

Javascript if select box is disabled no error

currently im working with a form that on submit uses javascript to validate all of the forms input fields and throws errors if a field is incomplete. I have an option though, that when checked will disabled a few of the inputs, and im looking to stop the errors from being thrown if the textbox is disabled.

relevant code includes:

html:

                <select name="os" id="os">
                    <option>-Select-</option> 
                    <option value="A">Android</option> 
                    <option value="I">iOS</option>
                     <option value="W">Windows Mobile</option> 
                 </select> <font color="#CC0000">*</font>

js

if (document.FrontPage_Form1.Action[0].checked==true) 
    {
        var dropvalue = document.getElementById("os");
        var dropText = dropvalue.options[dropvalue.selectedIndex].text;


            if (dropText=="-Select-") && (dropvalue.disabled=false)
            {
                document.getElementById("OS_Msg").style.display='';
                document.getElementById("OS_Err").style.display='';

                valid==false;
            }

    }

jQuery disable

<p><input type="checkbox" name="noPhone" id="noPhone">: My Device does not have a phone number.</p>

<script type="text/javascript">

            $("#noPhone").click(onCheckChange).change(onCheckChange);

                        function onCheckChange() {
                          if ($("#noPhone").is(':checked'))
                          {
                            $("select.focusDrop").attr('disabled', 'disabled');
                            $(":text").attr('disabled', 'disabled');
                          }
                          else
                          {
                            $("select.focusDrop").removeAttr('disabled');
                            $(":text").removeAttr('disabled');
                          } 
                        }

            </script>

Upvotes: 1

Views: 1221

Answers (1)

j08691
j08691

Reputation: 207901

Aside from missing a set of parenthesis wrapping around (dropText=="-Select-") && (dropvalue.disabled=false), you're setting a value instead of comparing it with

dropvalue.disabled=false

It should be

dropvalue.disabled==false

And as pointed out by Guffa, valid==false; should be valid=false;

Upvotes: 1

Related Questions