SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,293
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    addition of image with appendChild stops ajax submission in safari

    i've got a form with a text field and a submit button. with js i'm taking the text field's value, doing an ajax kind of submission rather than a normal form submission.

    generally all's fine apart from in safari when i add an activity image indicator to the page after the button has been clicked. the addition of the code which makes the image appear causes safari to treat the submit button click as a normal form submission rather than an ajax one. without the adding an image bit of code safari uses the ajax way of submitting the form.

    right at the top of the code i have:
    Code:
     
    activityImage = null;
    in a on load handler function i have:
    Code:
     
    	activityImage = new Image(); 
    	activityImage.setAttribute("width","36"); 
    	activityImage.setAttribute("height","36"); 
    	activityImage.src = "load.gif";
    then near the start of the function which gets called to do the HTTP request:
    Code:
     
        var div = document.getElementById("thediv"); 
    	div.appendChild(activityImage);
    without the div.appendChild(activityImage); line safari does the HTTP requst ok, with it, it goes into normal submission mode. why does that line have that effect? how to stop it having that effect?

    whole thing on a page: http://vm.ooh.uk.com/howfar/testy.php
    all the javascript: http://vm.ooh.uk.com/howfar/test.js
    (at the moment it's not sorted out for IE fully)

    thanks.

  2. #2
    SitePoint Wizard
    Join Date
    Apr 2002
    Posts
    2,293
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    aha! here's the answer:
    Code:
    activityImage = document.createElement('IMG');
    instead of
    Code:
    activityImage = new Image();
    that's been driving me potty for some time!


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
  •