0

There are two selection buttons which need client-side validation. The user must select one of them, and if user chooses one, the other one will be disabled automatically.

This my script:

<html>
   <head>
      <script type="text/javascript">
        function Check()  //this the funciton for diasbled
    {
      var x =document.getElementById("supexp1");
      var y =document.getElementById("supexp2");

      if(x.value != "")
      {
        document.form1.supexp2.disabled=true;
      }
      else if(y.value != "")
      {
        {
        document.form1.supexp1.disabled=true;
      }
      } 
    }

      </script>

   </head>
  <body>
    <form method="POST" action="destination.php" id="form1">
       <select name="SUPEXP" id="supexp1" data-native-menu="false" onChange="Check()">
           <option >Ekspedisi Local1</option>  //this selection 1 
           <option >Ekspedisi Local2</option>  //this selection 1 
           <option >Ekspedisi Local3</option>  //this selection 1

       </select>
    <select name="SUPEXP" id="supexp2" data-native-menu="false" onChange="Check2()">
           <option >Ekspedisi Expor2</option>  //this selection 2
           <option >Ekspedisi Expor2</option>  //this selection 2
           <option >Ekspedisi Expor2</option>  //this selection 2


    </select>
    </form>
  </body>
 </html>

I use the jquerymobile framework and selection connect to the database. That code (JavaScript) is not running.

2

3 Answers 3

3

I hope this is what you trying to do based on your description here is a jsfiddle

   $(document).ready(function() {
      $('#supexp1').change(function() {
      $('#supexp2').attr("disabled" , "disabled")
      });
      $('#supexp2').change(function() {
      $('#supexp1').attr("disabled" , "disabled")
      });    
    });​
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks For u'r answer, it waork if i dont use the Jquery mobile, in js fiddle, if i Check th jqm, its not work too.
2

Try this code

if(x.value != ""){
    document.getElementById("supexp2").disabled=true;
} else if(y.value != "") {
    document.getElementById("supexp1").disabled=true;
}

Comments

1

I guess to get the value of the selected item you need to use some thing like this

  var e = document.getElementById("supexp1");
  var x = e.options[e.selectedIndex].value;

instead of

  var x =document.getElementById("supexp1");

do the same for Y

1 Comment

it dont work, and mybe I have a mistake how to put it on the scipt?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.