how to replace & or special characters in javascript?

//if  value of catnm=’art & jewllery‘;

//then i want need to replace “&“.

//because when i will try to post data using jquery then jquery know this is query string…..so i want to need  to replace “&”  using “URL ENCODED CHARACTERS

//so,see below example

var catnm=document.getElementById(‘catnm’).value;

var cat_re=catnm.replace(‘&’,’%26′);

OUTPUT 

In Javascript alert box  : art %26 jewllery

In html format(in web browser )  : art & jewllery

Please refer below website for URL Encode Characters

http://www.degraeve.com/reference/urlencoding.php

http://www.w3schools.com/tags/ref_urlencode.asp


Comments

Leave a Reply

Your email address will not be published. Required fields are marked *