[SOLVED] # anchor causes problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

# anchor causes problems

Post by gurjit »

hi all,

i have a url string i pass through as follows:

http://www.mydomain.com/page.php?id=1&w ... &adr2=king road&city=london

the # in adr1 variable causes the page to stop printing adr2,city.

any variable after adr1 will not print on the page.

how can i stop this from happening?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

urlencode the #.. it's a url hash marking.

%23 = #
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

I have a javascript that creates the string to pass through. how can i do this in the javascript?

Code: Select all

<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--

function passall () &#123;


makestring = "a=a" 
for (i=0;i<document.form1.elements.length;i++) &#123;
	
	if (document.form1.elements&#1111;i].type == "radio" || document.form1.elements&#1111;i].type == "checkbox") &#123;
		if (document.form1.elements&#1111;i].checked == true) &#123;
			makestring = makestring + "&" + document.form1.elements&#1111;i].name + "=" + document.form1.elements&#1111;i].value
		&#125;
	&#125; 
	else 
	&#123;
	makestring = makestring + "&" + document.form1.elements&#1111;i].name + "=" + document.form1.elements&#1111;i].value
	&#125;
&#125;
document.location.href = "principal_user_edit.php?stop=stop&" + makestring

&#125;

//-->
</SCRIPT>

feyd | please use the forum's tags!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Javascript has a lovely little function called 'escape' that does it.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

I don't know JavaScript very well, but i think you could use escape function.
User avatar
gurjit
Forum Contributor
Posts: 314
Joined: Thu May 15, 2003 11:53 am
Location: UK

Post by gurjit »

you were right...the escape function around the value part worked great.

thanks all...
Post Reply