user692669
user692669

Reputation: 23

How can jquery variables passed?

Please can help. How can the variables passed. I have function for select option

Example jquery:-

var one = '1';
var two = '2';

$(document).ready(function(){  
    $(#).change(function(){
        if(one == '1'){
            var one = 'hello';
        }
    });

    $(#).change(function(){
        if(two == '2'){
            var two = 'world!';
        }
    });

    if (one =='hello' && two =='world!'){
        $(#welcome).hmtl("hello world!")
    }
});

Upvotes: 1

Views: 84

Answers (3)

user692669
user692669

Reputation: 23

Thanks very much for your answers

I have found

my example code:-

$(document).ready(function(){

    var one, two;

    $("#item_select1, #item_select2").change(function(){

        one = $("#item_select1").val();
        two = $("#item_select2").val();

        if (one =='1' && two == '2'){
            $("#welcome").html("hello world!"); 
        }

        if (one =='1' && two == '1'){
            $("#welcome").html(""); 
        }

        if (one =='0' && two == '0'){
            $("#welcome").html("Goodbye!"); 
        }

    });

});

Upvotes: 0

Ghazanfar Mir
Ghazanfar Mir

Reputation: 3543

Use this function:

$(document).ready(function(){ 
  radio = $('.radioid option:selected').val();

  if( radio == 1 )
    alert(1);

  ...
});

Upvotes: 0

Headshota
Headshota

Reputation: 21449

you should declare the variables as globals to be able to access them from everywhere in your code and you should not redeclare them using var keyword:

$(document).ready(function(){

var one, two;
$("selector").change(function(){


if(one == '1'){

    one = 'hello';

}


    });


$("selector").change(function(){


if(two == '2'){

    two = 'world!';

}


    });

if (one =='hello' && two =='world!'){

$(#welcome).hmtl("hello world!")

}

Upvotes: 1

Related Questions