0

I am beginner to ruby on rails what I want to do in my application is call java script function from script define inside view file like in following manner

//code inside js file ...
$(document).ready(function() {
    alert("outside the function");
function abc()
{
    alert("inside function");
}
});

//code in side view file 
<div> creating view here </div>
<script type="text/javascript" language="javascript">
    abc();
</script>

But It not giving require output. It shows one alert i.e. outside the function. But not showing other one that mean not calling that function. I want to call that function ... How to do this? Any solution? Need help ... Thank you ....

1 Answer 1

3

Try this, you need to move your function abc() outside the jQuery ready wrapper function.

$(document).ready(function() {
    alert("outside the function");

});

function abc(){
    alert("inside function");
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.