SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Need help with DOM and IE

    Hi,

    So I'm doing some DOM stuff that works great in Firefox but not so well in IE. I have two separate issues but I think the problem in both cases is the same.

    I'll just go with the more urgent one.

    I have a form in a popup, when I submit that form, I want the resulting page to be in the parent window. So here is the solution I came up with (btw... if there is an easier way to do this, I would like to know)

    Code:
      function submitForm() {
      	var form = getObject('choiceForm');
      	
      	var action = null;
      	
      	var existing = getObject('existingXml');
      	var upload = getObject('existingXmlUpload');
      	var blank = getObject('blankXml');		
      	
      	var choice = getObject('choice');
      	
      	if (choice.value == 'existing' || choice.value == 'blank') {
      		action = 'facultyEdit.php';
      	} else {
      		// TODO - implement this! I'll do it later
      		noFeature();
      		return;
      	}
      
      	// update action attribute
      	setElementAttribute(form, 'action', action);
      	
      	// change ID for the form we're about to inject
      	setElementAttribute(form, 'id', 'openerForm');	
      
      	// get the parent (opener) window
      	if (opener && !opener.closed) {
      		
      		var doc = opener.document;
      		
      		// obtain the body tag
      		var body = doc.getElementsByTagName('body').item(0);
      
      		// create a new hidden layer to inject the form into
      		var hiddenDiv = createHiddenDiv('hiddenForm', null, null, null);
      
      		hiddenDiv.appendChild(form);
      
      		body.appendChild(hiddenDiv);
      
      		// null the action on the popup form
      		var oldForm = getObject('choiceForm');
      		setElementAttribute(oldForm, 'action', 'javascript: return;');
      
      		// submit the injected form
      		form.submit();
      				
      		self.close();
      		
      	} else {
      		alert('An error occured while submitting this form. Please be sure to not close the parent window.');
      	}
      }
    This works fine in Firefox, in IE, the popup just becomes a blank page. Any suggestions on this?

    Thanks

    I also just noticed there are a few custom function definitions, particularly:

    Code:
     function getObject(objectId) {
     	return document.getElementById(objectId);
     }
     function setElementAttribute(element, name, value) {
     
     	if((element != null) && (name != null) && (value != null)) {
     		element.setAttribute(name, value);
     	}
     }

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What do you want your popup to do after you've submitted? Disappear? Show Another page?

  3. #3
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want the form on popup to be posted to another page in the parent window for processing.

    I tried something along the lines of

    <form action="opener.location='somePage.php' .....

    but this does not carry the post information through.

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    151
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ithought I saw something like this before. Here's a page from expertsexchange that should solve your problem (answers are near the bottom):

    http://www.experts-exchange.com/Web/..._21067228.html

    Hope that helps.

  5. #5
    SitePoint Wizard rozner's Avatar
    Join Date
    Oct 2002
    Location
    Paris
    Posts
    1,058
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok I found the solution from that link, thanks

    I had to modify it slightly, but it is a lot easier than trying to inject the form into the other DOM.

    I had to do this to get it to work
    Code:
    	opener.name = 'parent';
    
    	form.target = 'parent';
    	form.submit();


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
  •