Forum Moderators: open

Message Too Old, No Replies

More Netscape Issues - drop down boxes

How to deal with spaces in the value

         

txbakers

5:38 am on Dec 9, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The onChange method of a drop down box will fire off an event handler in Netscape, but if the goal is a redirect based on the value, make sure there are no spaces in the value.

this routine will eliminate the spaces and replace with the ascii code for space (%20)

var space = /\s/g;
var fundval = drop.options[drop.selectedIndex].replace(space, "%20");
var URL = "listfundraisers.asp?fund=" + fundval;
window.location.href= URL;

joshie76

2:13 pm on Dec 10, 2001 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The best way to do this, as it's not just spaces that cause problems when sending information in a URI, is to use the escape method:

var fundval = document.form.select.options[document.form.select.selectedIndex].value;
var URL = "listfundraisers.asp?fund=" + escape(fundval);
window.location.href= URL;

This will URI encode all the necessary characters (including spaces) in the fundval string.