Sign in to follow this  
Followers 0

HTML/JS encoding question


4 posts in this topic

Posted

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 &gt; single quotes to &#39; 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]

now the problem arises when i have for example a submit button with value "J'accept". When clicking it , its value becomes J&#39;accepte.

What function in javascript should i add so the display is not modified?

thank you in advance.

Share this post


Link to post
Share on other sites

Posted

anybody??

Share this post


Link to post
Share on other sites

Posted

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>

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;

}

This should work :p

1 person likes this

Share this post


Link to post
Share on other sites

Posted

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 < 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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0

  • Recently Browsing   0 members

    No registered users viewing this page.