Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to call jQuery Function from Html

<script>
function go() 
{
window.location=document.getElementById("menu").value;
}
</script>

<body>
<form>
<select id="menu" onchange="go()">
  <option>--Select a page--</option>
  <option value="http://www.1.com">1</option>
  <option value="http://www.2.com">2</option>
  <option value="http://www.3.com">3</option>
</select>
</form>
</body>

this works perfectly, but I cant call the function from External File

$(document).ready(function() {
    function go(){
window.location=document.getElementById("menu").value;
}});
like image 635
Faizan Avatar asked May 15 '26 16:05

Faizan


1 Answers

By putting function go(){}" inside of "$(document).ready(function() { you enclosing the the go function within the scope of $(document).ready(function() {}

Use document.ready() to call a function, not to declare it.

like image 51
Michael Ford Avatar answered May 17 '26 05:05

Michael Ford