Javascript onclick not working - What should I do?

237    Asked by ricsla_2198 in Java , Asked on Oct 13, 2022

I have a Sharepoint2010 site and am trying to execute a Javascript code to create some drop down selection menus with a GO button at the end. The GO button is supposed to run a function that does a URL redirect via the [removed] command based on the choices in the dropdown. I have this saved in a TXT file then called within a CEWP.

The snippet of code that I believe is having issues is with the function or the button itself.

This is what I have at the moment in a simplified form:

function submitGo(){

[removed] = "www.google.com"

}

<button onclick="submitGo()">Go</button>

But when I load my page and click the GO button it just reloads my sharepoint page and does not perform the redirect. I have tried replacing the function in the command with the [removed] command directly and it does the same thing. I am at a complete loss as to why this is not working.


Answered by Rishabh Dwivedi

In the case of javascript onclick not working -


Try

[removed] = "http://www.google.com";

You should also learn to take advantage of the web developer tools for javascript debugging. For example, in IE, press F12. If you then click the 'Console' tab, you have a REPL console where you can interactively enter javascript in the context of the current page. For example, you can type....

alert("Hello World")

.....and it will execute that command. Extending that example, you can type....

 [removed] = "www.google.com"

..... and see that it doesn't work.

Using this interactive console to fine-tune jQuery selectors saves me TONS of time



Your Answer

Interviews

Parent Categories