Results 1 to 6 of 6

Thread: & converting to & setAttribute, HELP!

  1. #1
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default & converting to & setAttribute, HELP!

    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?

  2. #2
    Join Date
    Sep 2006
    Location
    St. George, UT
    Posts
    2,769
    Thanks
    3
    Thanked 157 Times in 155 Posts

    Default

    Don't use encodeURI(). This is converting your ampersands to &. If that still doesn't world, no clue.

    Hope this helps, nonetheless.
    "Computer games don't affect kids; I mean if Pac-Man affected us as kids, we'd all be running around in darkened rooms, munching magic pills and listening to repetitive electronic music." - Kristian Wilson, Nintendo, Inc, 1989
    TheUnlimitedHost | The Testing Site | Southern Utah Web Hosting and Design

  3. #3
    Join Date
    Jun 2006
    Location
    Acton Ontario Canada.
    Posts
    677
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default

    i dunno about JS...
    but PHP, easily accomplished.

    PHP Code:
    <? $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...
    - Ryan "Boxxertrumps" Trumpa
    Come back once it validates: HTML, CSS, JS.

  4. #4
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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)
    Last edited by egrissom; 04-12-2007 at 01:14 AM.

  5. #5
    Join Date
    Apr 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    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.

  6. #6
    Join Date
    Feb 2007
    Location
    England
    Posts
    254
    Thanks
    0
    Thanked 5 Times in 5 Posts

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •