-5

I have a button on my cover page and I need to assign to it 1 line of javascript code (namely javascript:languageClicked(0); to work with this neat addon: Multilingualizer) .

So the button should execute that line of code and do its usual job, namely to send the user to my main webpage.

thx in advance

Community
  • 1
  • 1
Benjamin
  • 10,603
  • 3
  • 16
  • 28
  • I am sorry, but please re-state your question. Absolutely no idea what you mean. When you say assign, do you mean using a `BUTTONCODEHERE` type of assignment, or do you mean code like a variable, etc... – NiCk Newman May 05 '15 at 18:38
  • Hi,sorry, I am not a javascript expert so I might not use common language here at all. What I want is simple: have that button do its usual job of directing users to a specific webpage AND execute this line of javascript code. Does that make sense? – Benjamin May 05 '15 at 18:39
  • Yeah, but which button exactly? I see a lot. – NiCk Newman May 05 '15 at 18:41
  • thx Nick, the big beast saying "Enter". I dont mean the social media buttons... – Benjamin May 05 '15 at 18:42
  • 1
    I am getting `Uncaught ReferenceError: languageClicked is not defined` when running that line in the console. Are you sure you have the appropriate Javascript dependencies loaded within your site? – NiCk Newman May 05 '15 at 18:45
  • hm, you might be right that the language stuff is not initialized at that point... I will try to inject it to that cover page... – Benjamin May 05 '15 at 18:47
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/77034/discussion-between-nick-newman-and-benjamin). – NiCk Newman May 05 '15 at 19:02

2 Answers2

2

Is the languageClicked function code from Multilingualizer? If so, maybe that addon isn't enabled correctly on your page or something and the js files for it are not being loaded.

But, once they are loaded. You can replace your button with this code:

<a href="javascript:languageClicked(0);window.location='/expnew';" id="yui_3_17_2_1_1430851625668_627">ENTER</a>

Screenshot

Since you want the user to be redirected to /expnew after activating languageClicked.

Hope this helps! Also, there is one catch though; don't change this unless you know for sure you have those JS libraries loaded. ^_^

NiCk Newman
  • 1,716
  • 7
  • 23
  • 48
  • Thanks a lot Nick. One last awefully stupid last question: How can I add that code of yours using the squarespace environment? – Benjamin May 05 '15 at 19:30
  • I can take a look at it through chat if you want. There should be some type of panel where you can edit HTML inside the squarespace interface, correct? – NiCk Newman May 05 '15 at 19:32
1

Without some HTML snippets and the name of the button you are working with, it is hard to know exactly how to help. However, I can share some general knowledge that may provide the answer for you.

The two most common ways that JavaScript triggers are implemented are:

1. <a> "link buttons":

Your code might look something like:

<a href="javascript:languageClicked(0)">Click me!</a>

2. <input>/<button>/any element onclick events:

Your code might look something like:

<button onclick="javascript:languageClicked(0)">Click me!</button>
sfarbota
  • 2,619
  • 1
  • 22
  • 30