html - Including a javascript file? -


i'm having little trouble including javascript file. have following code block on page, , want move separate file called cart.js. problem is, whenever move script file stops working on page. have tried wrapping entire code block on document ready didn't work. i'm loss on how include this.

edit: found error advice of looking @ console. turns out, leaving call jquery in cart.js causing issue.

current_fin = "none"; current_mat = "pine"; current_col = "red"; current_size = "36"; jquery(document).ready(function($) {   $("#dropdownthree").hide(); });  // pass current selection variable use. function getmaterial() {// function checks material , if plastic hides/shows boxes   var mat = document.getelementbyid("dropdownone");   current_mat = mat.options[mat.selectedindex].text;   if (current_mat == "plastic") {     var col = document.getelementbyid("dropdownthree");     current_fin = col.options[col.selectedindex].text;     $("#dropdowntwo").hide();     $("#dropdownthree").show();   } else {     var fin = document.getelementbyid("dropdowntwo");     current_fin = fin.options[fin.selectedindex].text;     $("#dropdownthree").hide();     $("#dropdowntwo").show();   }   $.post('php/productajaxtemp.php', {     ourmaterial: current_mat,     ourfinish: current_fin,     oursize: current_size   }, function (data) {     $("#price").html(data).show();   }); }  function getfinish() {   var fin = document.getelementbyid("dropdowntwo");   current_fin = fin.options[fin.selectedindex].text;   $.post('php/productajaxtemp.php', {     ourmaterial: current_mat,     ourfinish: current_fin,     oursize: current_size   }, function (data) {     $("#price").html(data).show();   }); }  function getcolor() {   var col = document.getelementbyid("dropdownthree");   current_col = col.options[col.selectedindex].text;   $.post('php/productajaxtemp.php', {     ourmaterial: current_mat,     ourfinish: current_col,     oursize: current_size   }, function (data) {     $("#price").html(data).show();   }); }  function getsize() {   var sz = document.getelementbyid("dropdownsize");   current_size = sz.options[sz.selectedindex].text;   $.post('php/productajaxtemp.php', {     ourmaterial: current_mat,     ourfinish: current_col,     oursize: current_size   }, function (data) {     $("#price").html(data).show();   });   getmaterial(); } 

the associated html is

<script type="text/javascript" src="jquery.js"></script> <script type="text/javascript" src="js/cart.js"></script>  <form action="cart.php" id="form" method="post">   <select name="size" id="dropdownsize" onchange="getsize()">     <option>36</option>     <option>48</option>     <option>60</option>     <option>72</option>   </select>   <select name="material" id="dropdownone" onchange="getmaterial()">     <option>pine</option>     <option>oak</option>     <option>walnut</option>     <option>plastic</option>   </select>   <select name="finish" id="dropdowntwo" onchange="getfinish()">     <option>none</option>     <option>finished</option>   </select>   <select name="color" id="dropdownthree" onchange="getcolor()">     <option>painted red</option>     <option>painted green</option>     <option>painted blue</option>     <option>painted yellow</option>     <option>painted white</option>     <option>primer white</option>   </select>   <input type="submit" value="add cart"> </form> 

depending js script using, can't copy paste js code in file.

try include js code inside anonymous function in file :

(function() {     //your js })(); 

by way, js code executed after file loading , usable.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -