0

So I have this function called redireccionar()

function redireccionar(){
            alert("activaste la funcion");
        }

gyazo

and redireccionar() gets called by this:

<button class="btn btn-default" onclick="redireccionar()" type="button">Go!</button>

gyazo

But I do click and nothing happens, its because I render them? How can I fix it? Why it doesnt work? Thanks.

3
  • 1
    what do you mean by its because I render them??? Commented Jan 31, 2015 at 23:21
  • 3
    You have somehow mixed your own Javascript with that of including jQuery (first screenshot), put it in its own <script> Commented Jan 31, 2015 at 23:22
  • 2
    Perhaps you have other JavaScript errors interfering with the execution of the function. Have you debugged your code or examined the browser's console for errors? Commented Jan 31, 2015 at 23:23

3 Answers 3

4

You need to make a separate <script> tag for your custom JS, your first screenshot (http://gyazo.com/c86b48f3f96137bba0e32e1ae72c0daf) shows you have a script tag pulling in bootstrap and within that tag you are specifying your code.

Example solution:

<script src='/path/to/bootstrap/cdn'></script>
<script>
function redireccionar(){
    alert("activaste la funcion");
}
</script>

See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script#attr-src

Sign up to request clarification or add additional context in comments.

5 Comments

I wasn't aware self-closing script tags even worked; what spec are you operating under?
still not working, as i said, it may be cause i render them? : gyazo.com/4eae72e08ef33415c38f904c01a9c915
@RubenSaez I'm not familiar with that syntax, what framework are you using that uses that $:render syntax? Make sure that the final output HTML file contains the scripts you are expecting.
@DavidHughes Everything I'm reading is suggesting your answer is wrong from the fact that the script tag does not self-close; enlighten me as to this? I still have yet to vote on your answer.
@Daedalus Apologies that was a typo, the tag isn't self closing - rectified this in my answer. The point I was illustrating however was that you should not have code inside a script tag if you are wanting to use the src attribute to load external scripts.
3

Oh! I just checked your picture and found something like this:

<script src="......bootstrap.min.js">
//your code here
</script>

You shouldn't include your script within that bootstrap framework. Do like this:

<script src="path-of-boostrap.min.js"></script>
<script>
//your code here
</script>

1 Comment

Hi m8, can you help me with one little thing?
0

¡Hola Ruben! Your first screenshot shows the problem. Your function has to be surrounded by separate <script></script> tags, not inside of the linked bootstrap js file. Everything else should be fine so far.

3 Comments

1+ for Bhojendra from me, for the faster and better explained answer :-)
Hi ddlab, can you help me with 1 little thing? Im new here and i dont know how this works, i dont know how to send a PM if it's possible
con placer :-) how can I help you ?

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.