user2597016
user2597016

Reputation: 43

JS - Issue doing a function

i have case like this :

if nilai.value meet 7, i want to doing function like $("#bt1").click(function(). i try using this code, but failed. How to doing that?

<script type="text/javascript">
jQuery(document).ready(function($) {
 var ps = $('.z');
  $("#bt1").click(function(){
    var el1 = $("#pos7");
    var el2 = $("#neg7");
    ps.not(el1).slideUp()
    ps.not(el2).slideUp()
    el1.slideToggle();
    el2.slideToggle();
  });
  $('#slider').slider()
  .on('slide', function(ev){
  var nilai = document.getElementById('bar'); 
    if (nilai.value == 7)
    var el1 = $("#pos7");
    var el2 = $("#neg7");
    ps.not(el1).slideUp()
    ps.not(el2).slideUp()
        el1.slideToggle();
        el2.slideToggle();  
else if(nilai.value == 6)
          document.getElementById('amount').value ='sabtu';
         $('#bar').val(ev.value);
      });
    });
    </script>

sorry i am new in programming. in my mindset of case like above is just moving the code.

Thanks for the help.

Upvotes: 1

Views: 51

Answers (2)

Teemu
Teemu

Reputation: 23396

You need a block of statements, if you want to execute several statements when the condition in the if comes true. Something like this:

if (true) {
    statement1;
    statement2;
} else {
   stement1;
   statement2;
}

As its current form, your code executes all statements before else and then throws an error: Else without if.

When you get this fixed, you can move $("#bt1").click(function(){...} into that block.

Upvotes: 2

Mike
Mike

Reputation: 1999

Try to correct your if else statements. They should look like this:

if () {
};
else if () {
};
else {};

Upvotes: 0

Related Questions