views:

105

answers:

3

The problem is when the link is clicked. I have a problem ONLY if the third parameter contain space OR/AND character like ê,é,î...

<a href="javascript:arretSuivrePortefeuille('13206','Suivre','Arrêter de suivre');">Suivre</a>

I receive from FireBug :

arretSuivrePortefeuille is not defined javascript:arretSuivrePortefeuille('13206','Suivre','Arr%C3%AAter%20de%20suivre');()

Any idea?

+2  A: 

Mmm, as a first measure remove the href attribute and move the instruction into onclick, this is the more correct way anyway. Don't forget to remove onclick and add a return false if necessary. It might be some URL encoding issue present in href only.

If that doesn't work out:

  • What encoding are you using in the document?
  • What encoding are the special characters in?
Pekka
Or better yet, remove all inline JavaScript and try being unobtrusive! :)
J-P
I need to call this method with parameter, I do not see how to pass stuff to a function outside the file without passing some info. I will try to do what Pekka suggest, but I do not get J-P comment...
Daok
J-P's comment refers to what CMS is demonstrating in the other answer (bind the event programmatically). This is cleaner because it furhter splits presentation and logic.
Pekka
The problem with binding the event programmatically is that both last string in parameter come from the PHP database for the language (website is billingual). How can I do it programmatically in the .JS file when the .PHP require to get those value from the database...
Daok
Changing to onclick solve the problem of encoding... weird..
Daok
You could keep the JS code in the main file, but put it into a script tag in the head section. The markup looks cleaner that way. Anyway, it's not a requirement.
Pekka
+2  A: 

I would recommend you at least to use the onclick attribute instead of using the javascript: pseudo-protocol:

<a onclick="arretSuivrePortefeuille('13206','Suivre','Arrêter de suivre');"
   href="#" >Suivre</a>

Or better, bind the click event programmatically

<a id="linkId" href="#">Suivre</a>


//...
document.getElementById('linkId').onclick = function () {
  arretSuivrePortefeuille('13206','Suivre','Arrêter de suivre');
  return false; // stop link navigation
};
CMS
and if CMS is saying so, then you betta do that :)
Rakesh Juyal
A: 

HTML attributes must have HTML encoding. You might try encoding the special characters in your javascript:

é becomes &eacute;
è becomes &egrave;
etc.

Lookuptables has a table with a lot of these special characters.

Your line of code will become:

<a href="javascript:arretSuivrePortefeuille('13206','Suivre','Arr&ecirc;ter de suivre');">Suivre</a>
Scharrels
Space is a problem too.
Daok