Current location: Hot Scripts Forums » General Web Coding » JavaScript » Submitting a form that is in a frame


Submitting a form that is in a frame

Reply
  #1 (permalink)  
Old 08-18-06, 01:07 AM
drky drky is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Question Submitting a form that is in a iframe

  • IFRAME (file: sample.php)
    • Form (name: dataForm)
    • Code:
      <form name="dataForm" action="sample.php" method="GET">
       
      	<input type="hidden" name="objectOneData">
       
      	<input type="hidden" name="objectTwoData">
       
      	<input type="hidden" name="objectThreeData">
       
      	<input type="button" value="submit" onclick=' document.dataForm.submit();'>
       
      </form>
  • PARENT
    • iFrame (id: iFrME)
I want to either have a link or button that will submit that form in the iFrame when clicked.

I've been fiddling with this for a day now and can't seem to get it.

Last edited by drky; 08-18-06 at 01:41 AM.
Reply With Quote
  #2 (permalink)  
Old 08-18-06, 02:43 PM
drky drky is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Does something like:
Code:
var objectOneFrame = document.iFrMe.objectOne;
Make sense?

Thank you all in advance!
Reply With Quote
  #3 (permalink)  
Old 08-18-06, 03:00 PM
drky drky is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
I've done some modifying.

samples.php (this is shown in the iFrame on index.html)
Code:
<form name="dataForm" action="sample.php" method="GET">
	<input type="hidden" name="objectOneData">
	<input type="hidden" name="objectTwoData">
	<input type="hidden" name="objectThreeData">
	<input type="button" value="submit" onclick='document.dataForm.objectOneData.value = "left: "+objectOne.style.left+";"; document.dataForm.objectTwoData.value = "left: "+objectTwo.style.left+";"; document.dataForm.objectThreeData.value = "left: "+objectThree.style.left+";"; document.dataForm.submit();'>
</form>
</div>

<script type="text/javascript">
	var objectOne = document.getElementById( "object1" );
	var objectTwo = document.getElementById( "object2" );
	var objectThree = document.getElementById( "object3" );

</script>
What I have tried, and would like to do:
1. Submit this form from index.html that has the above in a frame

2. Hopefully retrieve style information of the above object1, 2 & 3 in realtime?
Reply With Quote
  #4 (permalink)  
Old 08-19-06, 09:33 AM
drky drky is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Hi guys sorry for not making it clear.

The above code is in a file called samples.php

I show samples.php in an iframe in index.html and when I press a button or click a link in index.html I want to submit the form that is in samples.php.
Reply With Quote
  #5 (permalink)  
Old 08-19-06, 03:23 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Give all the input elements and id with the same value as the name, this might help with cross-browser issues later on.

Try
Code:
<iframe src="sample.php" width="100%" height="250" name="iFrME" id="iFrME"></iframe>
<div class="options_page">

<form name="parentForm" action="javascript:void(null)">
	<input type="button" value="submit" onclick="doStuff()">
</form>

<script type="text/javascript">

function doStuff(){
 var theFrame=window.frames['iFrME'].document
 var theForm=theFrame.forms['dataForm']
 var obj=theFrame.getElementById('object1')
 theForm.objectOneData.value="left: "+obj.style.left+"; top: "+obj.style.top+"; height: "+obj.style.height+"; width: "+obj.style.width+";";
 obj=theFrame.getElementById('object2')
 theForm.objectTwoData.value="left: "+obj.style.left+"; top: "+obj.style.top+"; height: "+obj.style.height+"; width: "+obj.style.width+"; text-align: "+obj.style.textAlign+"; background-color: "+obj.style.backgroundColor+";";
 theForm.objectThreeData.value="left: "+obj.style.left+"; top: "+tobj.style.top+"; height: "+obj.style.height+"; width: "+obj.style.width+"; text-align: "+obj.style.textAlign+"; background-color: "+obj.style.backgroundColor+";
 theForm.submit()
}
</script>
}
This should create references to both the iframe and the form from the parent.
Then it should take the style.left values of the object# elements in the iframe and put them in the hidden fields.
Finally, it submits the form.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.

Last edited by TwoD; 08-20-06 at 03:02 PM. Reason: Updated the code
Reply With Quote
  #6 (permalink)  
Old 08-19-06, 04:20 PM
drky drky is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
So I put that in the PARENT and doStuff() onSubmit?

Last edited by TwoD; 08-20-06 at 03:04 PM.
Reply With Quote
  #7 (permalink)  
Old 08-19-06, 08:18 PM
drky drky is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Thank you very much for your help, but it doesn't seem to work :S
http://www.fusion-central.net/files/

Thanks again for all your help!

Last edited by TwoD; 08-20-06 at 03:03 PM.
Reply With Quote
  #8 (permalink)  
Old 08-20-06, 03:08 PM
TwoD TwoD is offline
Community VIP
 
Join Date: Sep 2003
Location: 404
Posts: 1,813
Thanks: 0
Thanked 0 Times in 0 Posts
Sorry, I made a few typos (the name of the frame, and it should have been window instead of document.)

Code above updated.

Btw, there's no need to quote the whole post of the previous poster, especially when not replying to only parts of it. It just clutters up the thread.
There's a Reply button in the lower left corner of each thread, and there's also a "Quick Reply" box (next to "Quote") for each post.
__________________
[W3Schools - learn all about the standards.] [QuirksMode - Browser Quirks] [MS's Online Reference Docs] [DOM in Gecko.]
Please pay attention to stickys, announcements and forum rules, thank you.
Please also remember Code Wrappers and [SOLVED] Marking, this helps everyone.
Reply With Quote
  #9 (permalink)  
Old 08-21-06, 12:41 AM
drky drky is offline
Newbie Coder
 
Join Date: Aug 2006
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Hey TwoD, thanks for all your help. I've tried it out and still no go -- I have been reading stuff up aswell and cannot grasp how exactly to make this one work.

Thanks again TwoD, your help is much appreciated and am excited about hopefully getting this to work!

Hey TwoD, thanks again. I was using the debugger with IE7 and got it ironed out. Thanks alot bro! I appreciate it.

Last edited by drky; 08-21-06 at 12:45 AM.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Submitting form error Tiffany677 PHP 4 05-16-06 04:47 PM
Need Your HelP! Loading Multiple External Text into Multiple Dynamic Text Fields Flash_Boi Flash & ActionScript 2 03-30-06 03:27 PM
Help; Submitting Form Mephistopheles Script Requests 3 03-14-06 05:44 PM
PHP pages - form submitting 1jetsam PHP 4 11-08-04 09:28 PM
formmail problem gscraper Perl 12 08-27-04 03:06 AM


All times are GMT -5. The time now is 11:15 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.