View Full Version : & converting to & setAttribute, HELP!

04-12-2007, 12:55 AM
I'm about ready to eat a box of poison. I'm dynamically creating images through the DOM with createElement, and when I get to the src attribute i need to set it to a url with a querystring attached (example someurl.aspx?item1=yes&item2=yes - the aspx page sends back an image). When the code is appended to the container div- the source is always &item2=yes. Its taking the "&" and converting to &.

I then tried to use createTextNode, and while the & was in tact for a bit- as soon as I setAttribute, it's converted. I even tried setting an Id to the image, then after the fact grabbing the id with getElementById() and changing the src.

innerHTML does the same thing, whatever i pass in, encodeURI() or otherwise, is always converted. Anyone have any idea at all what I might be able to do? The only thing i can think of that would work is document.write(), but I don't even know if i can specifically target a div with that.

anyone out there feel like talking me off the roof?

04-12-2007, 12:58 AM
Don't use encodeURI(). This is converting your ampersands to &. If that still doesn't world, no clue.

Hope this helps, nonetheless.

04-12-2007, 01:03 AM
i dunno about JS...
but PHP, easily accomplished.

<? $string = "some stuff, mixed & and &amp;";
$string = str_replace("&amp;","&",$string); //turns &amp; into & so you dont end up with &amp;amp;
$string = str_replace("&","&amp;",$string); //turns & into &amp;
echo $string; ?>
Echos out: some stuff, mixed &amp; and &amp;

if there isn't a JS function, you can use this...

04-12-2007, 01:06 AM
i wish i was using php :)

But yeah I tried with and without encodeURI as well, as far as I know its supposed to convert all entities but certain url specific ones- like "&", either way though i tried it both ways.

[edit: Maybe i'm wrong about that encodeURI thing, who knows i'm getting tired. I removed it completely and still the same results)

04-12-2007, 03:28 AM
i think i may have figured it out- it may actually BE working, and the entity conversion is a result of using "view generated source" in the firefox web developer extension. good lord i hope i'm right.

04-12-2007, 05:47 PM