Jquery call var from another function

D. Ronald

How can I access the maxdata variable if it is in the .on change function does someone knows how I can use it in .click function I want to use it in a if statement to alert something.

If someone knows how to do this can you please tell me I have tried var window.maxdata and than tried to call it from the .click function but still doesn't work for me.

<script type="text/javascript">
$(document).ready(function()
{ 
     $("#vakgebied").on('change', function()
    { 
            var current = $(this).find("option:selected").html();
            //alert(current);
             var maxdata = $(this).find("option:selected").attr('data-max');
            //alert(maxdata);
            $("#maxwoorden").text("MaxWoordenPerDag: "+ maxdata);


     }); 

    $("#berekenen").click(function() 
    {
        var brontaal= $("#bron-taal option:selected").val();
        var doeltaal= $("#doel-taal option:selected").val();
        if(brontaal==doeltaal)
            {alert("De gewenste talen moeten verschillend zijn")}
        var vg= $("#vakgebied option:selected").val();
        var aantal=$("#aantal").val();
        var taal = brontaal+"-"+doeltaal;

        //var prijzen= {"NL-DE":0.15,"DE-NL":0.20};
        var prijzen= <?php echo json_encode($prijs);?>;
        var vakgebied= <?php echo json_encode($vak);?>;
         if(aantal > maxdata)
                {
                 alert("Het aantal woorden die u heeft ingetypt is over de maximum");   

                }
        else
        {
            var totaal= prijzen[taal][vg] * aantal;
            var totaal = totaal.toFixed(2); 
            $("#resultaat").text("De prijs van "+aantal+" woorden "+"met "+vg+"      Als vakgebied is "+totaal+" euro's").hide().fadeIn(900);

        }
        //document.getElementById('resultaat').innerHTML=
        //alert(); 

    });  


});            
</script>  
T J

You can access it like

$(document).ready(function(){ 
  var maxdata;
  $("#vakgebied").on('change', function(){ 
        var current = $(this).find("option:selected").html();
        //alert(current);
        maxdata = $(this).find("option:selected").attr('data-max');
        //alert(maxdata);
        $("#maxwoorden").text("MaxWoordenPerDag: "+ maxdata);
  }); 

  $("#berekenen").click(function() {
    //code
     if(aantal > maxdata){
       alert("Het aantal woorden die u heeft ingetypt is over de maximum");
     }
     else{ // code}
  });  
});            

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Jquery call var from another function

From Dev

how to call a function from another function in Jquery

From Dev

Call function from another function in jQuery OOP

From Dev

jquery how to call datepicker from another function?

From Dev

Call another function with jQuery

From Dev

How to call a function of a parent class from another function in jquery

From Dev

Get var from another function?

From Dev

jquery + php - Call Function From Another Javascript Wrapper

From Dev

Using jquery how to call a function and call another function from the previous when function execution is completed

From Dev

call jquery function onload and var to php

From Dev

React - call handler from var in render function

From Java

Call a function from another file?

From Dev

Call function from another script

From Dev

Call a function from another thread

From Dev

Call a function from an another class

From Dev

Call an anonymous function from another

From Dev

Call a jquery function from a jquery function

From Dev

Call function from another function Mysql

From Dev

Call a __init__ function from another function

From Dev

How to call a number from another function into a function?

From Dev

How to call from function to another function

From Dev

Call a function from within another function

From Dev

How to call a function from within another function?

From Dev

How jquery can call a function in the 'end' of another?

From Dev

jQuery - How to call a function in another scope

From Dev

Call the Click function by another click in jquery? is it possible

From Dev

How jquery can call a function in the 'end' of another?

From Dev

PHP - Call function from after call to another function in the class

From Dev

Call another function from another function C#

Related Related

  1. 1

    Jquery call var from another function

  2. 2

    how to call a function from another function in Jquery

  3. 3

    Call function from another function in jQuery OOP

  4. 4

    jquery how to call datepicker from another function?

  5. 5

    Call another function with jQuery

  6. 6

    How to call a function of a parent class from another function in jquery

  7. 7

    Get var from another function?

  8. 8

    jquery + php - Call Function From Another Javascript Wrapper

  9. 9

    Using jquery how to call a function and call another function from the previous when function execution is completed

  10. 10

    call jquery function onload and var to php

  11. 11

    React - call handler from var in render function

  12. 12

    Call a function from another file?

  13. 13

    Call function from another script

  14. 14

    Call a function from another thread

  15. 15

    Call a function from an another class

  16. 16

    Call an anonymous function from another

  17. 17

    Call a jquery function from a jquery function

  18. 18

    Call function from another function Mysql

  19. 19

    Call a __init__ function from another function

  20. 20

    How to call a number from another function into a function?

  21. 21

    How to call from function to another function

  22. 22

    Call a function from within another function

  23. 23

    How to call a function from within another function?

  24. 24

    How jquery can call a function in the 'end' of another?

  25. 25

    jQuery - How to call a function in another scope

  26. 26

    Call the Click function by another click in jquery? is it possible

  27. 27

    How jquery can call a function in the 'end' of another?

  28. 28

    PHP - Call function from after call to another function in the class

  29. 29

    Call another function from another function C#

HotTag

Archive