Reputation: 3858
I speak spanish, so I am using a lot the accent mark (á,é..). Whenever I need to write them, I use á
é
and so on.
Now I have a problem because I want to compare if two sentences are different, in order to continue with my function but it doesnt work.
Here is an explanation of what I am trying to do.
There is an input which has a given value explaining to the user what he needs to write in that input. When the user clicks on the input, the given value will dissapear, so the user writes the new value. Now, I have a function which takes the new value and do some stuff with it (not relevant). I want the function to do so, only if the value is different of the value given at first, making sure that the function works only when the user has written something. My problem is that the given value has an Accent mark so when i do the comparison, it always do the rest of the function.
Here is some code to make myself clear.
<input type="text" id="proyecto" value="Área donde operó el proyecto" />
<script type="text/javascript">
function proyecto(){
var proyecto = document.getElementById("proyecto").value;
var aux1 = "Área donde operó el proyecto";
var aux2 = "Áreas donde operó el proyecto";
if (proyecto != aux1)
alert("DO THE REST OF THE FUNCTION");
if (proyecto != aux2)
alert("DO THE REST OF THE FUNCTION");
}
</script>
I use a function that then the user clicks on the input, it clears the input putting it blank. If the user do not write anything, value will appear again.
I hope i made myself clear.
thanks a lot!
Upvotes: 0
Views: 502
Reputation: 18359
You can use a regular expression. Like this:
<script type="text/javascript">
function proyecto(){
var proyecto = document.getElementById("proyecto").value;
var aux = /[AÁ]reas donde oper[oó] el proyecto/i;
if (!aux.test(proyecto))
alert("DO THE REST OF THE FUNCTION");
}
</script>
See: http://www.w3schools.com/jsref/jsref_obj_regexp.asp
Upvotes: 1