hi everyone:

i have a set of pages that let users upload images. Rather than letting some poor user upload a huge image file only to find that it already exists, i set up some PHP and javascript that lets users click BROWSE to locate a file and then the javascript and PHP cooperate to see if a file with that name has already been uploaded. when they select a file, i run some javascript that reloads a PHP script into an iframe with the selected image as query string. That PHP script receives the pathname via GET and checks to make sure the user hasn't already uploaded a picture with the same name.

My problem is that I need to URLENCODE the selected image's path with my javascript function for it to work properly. does anyone know the javascript equivalent of URLENCODE?

    Hi there!. There is not an equivalent to urlencode in javascript, at least I don´t know one, but you can use a combination of escape js function and RegExp to get what you are looking for, something like

    function doUrlEncode(str)
    {
    	regular = new RegExp("/","g");
    	val = escape(str);
    	val = val.replace(regular,"%2F");
    	return val;
    }
    

    and you just call it with your urls as the argument.

      Write a Reply...