• 0

HTML/JS encoding question


Question

Hello,

I need to ask a small question about character encoding in HTML.

When submitting a form, i am doing a client side validation that will read all data from the form and "Escape" it in a way to transform < into > single quotes to ' etc .


function verufymyform(form){


var str = '';
var elem = form.elements;
for(var i = 0; i < elem.length; i++)
{
str = characterEncodingFunction(elem[i].value); //here is the function i am calling
elem[i].value = str; //I think i should add a JS function here??[/size]
[size=3] }
return false;
}[/size]
[size=3][/CODE]

[/size]

[size=3][font=arial, helvetica, sans-serif]now the problem arises when i have for example a submit button with value "J'accept". When clicking it , its value becomes J'accepte.[/font]

[font=arial, helvetica, sans-serif]What function in javascript should i add so the display is not modified?[/font]

[font=arial, helvetica, sans-serif]thank you in advance.[/font][/size]

Link to comment
Share on other sites

3 answers to this question

Recommended Posts

  • 0

so your js applies to everything inside the 'form' element but you want to make a exception of the submit button?

you can try:


<form>
<div id="form">
<input blabla />
<input blabla />
<input blabla />
</div>
<input type="submit" value="J'accept" />
</form>
[/CODE]

[CODE]function verufymyform(form){


var str = '';
var elem = document.getElementById('form').elements;
for(var i = 0; i < elem.length; i++)
{
str = characterEncodingFunction(elem[i].value); //here is the function i am calling
elem[i].value = str; //I think i should add a JS function here??
}
return false;
}
[/CODE]

This should work :p

Link to comment
Share on other sites

  • 0

That would work. To avoid having another div, and to allow the parameter of the JavaScript function to actually continue to do something, this should work:

function verufymyform(form){
  var elem = form.elements;
  for(var i = 0; i &lt; elem.length; i++)
  {
    if(elem[i].type != "sumbit")
      elem[i].value = characterEncodingFunction(elem[i].value);
  }
  return false;
}

I also removed the references to str since this was unnecessary.

Link to comment
Share on other sites

This topic is now closed to further replies.