...

View Full Version : how to pass var inside iframe to hidden element ?



black
02-06-2004, 04:26 AM
howdy~

now i want to control the value of hidden element of main form from an iframe, the procedure is very simple: build a variable within iframe -- change hidden element with this var

my code is just like this(code lives inside iframe of course):


var picPath = "test.jpg";
parent.document.form1.pic.value = picPath;


seems sensible but it didnt work... :(

form1 is the name of main form, and pic is the name of hidden ele within main form. any help ??? :rolleyes:

glenngv
02-06-2004, 07:41 AM
The code seems fine.
Did any error msg occur?

black
02-06-2004, 08:59 AM
it is funny... that form can get data but we cant see the changes by browsing the source file. really get confused...

glenngv
02-06-2004, 09:10 AM
You can't really see the changes in the page source. It only contains the source when the page is loaded. What you can do is alert the values to check if the change took effect.

var picPath = "test.jpg";
parent.document.form1.pic.value = picPath;
alert(parent.document.form1.pic.value)

black
02-06-2004, 09:20 AM
Originally posted by glenngv
You can't really see the changes in the page source. It only contains the source when the page is loaded. What you can do is alert the values to check if the change took effect.

var picPath = "test.jpg";
parent.document.form1.pic.value = picPath;
alert(parent.document.form1.pic.value)

oh thanx for mentioning that man~ and any way we can see the whole source aftering changes ? :rolleyes:

glenngv
02-06-2004, 09:43 AM
I'm using this view source bookmarklet. I got it somewhere but I modified it to have the ability to specify target frame/iframe name.

Copy these links and save it in your Favorites folder.

For IE:
javascript&#58;ans=prompt('Specify name of target window/frame/iframe. Empty or non-existing name will mean current topmost window.','');win=window[ans];if(!win)win=top;myWin=window.open('','','width=800,height=600,scrollbars,resizable,menubar');myStr= win.document.documentElement.outerHTML;myStr=myStr.replace(/\</g,'&lt;').replace(/\>/g,'&gt;');myWin.document.open();myWin.document.write('<pre>'+myStr+'</pre>');myWin.document.close();

For NS6/Mozilla:
javascript&#58;ans=prompt('Specify name of target window/frame/iframe. Empty or non-existing name will mean current topmost window.','');win=window[ans];if(!win)win=top;myWin=window.open('','','width=800,height=600,scrollbars,resizable,menubar');myWin. document.write('<pre>' + unescape((new XMLSerializer()).serializeToString(win.document).replace(/</g, '&lt;')) + '</pre>');myWin.document.close()

Make the code in one line and remove the space in window. open spot. This forum just messed them up.

After you have saved it as bookmark, just click it when the target page is loaded.

Willy Duitt
02-06-2004, 04:29 PM
Thanks for that Glenn :thumbsup:

I like Bookmarklets. I have over a 100 on my toolbar.
Here's one which shows the hidden form fields....

javascript:(function(){var i,f,j,e,div,label,ne; for(i=0;f=document.forms[i];++i)for(j=0;e=f[j];++j)if(e.type=="hidden"){ D=document; function C(t){return D.createElement(t);} function A(a,b){a.appendChild(b);} div=C("div"); label=C("label"); A(div, label); A(label, D.createTextNode(e.name + ": ")); e.parentNode.insertBefore(div, e); e.parentNode.removeChild(e); ne=C("input");/*for ie*/ ne.type="text"; ne.value=e.value; A(label, ne); label.style.MozOpacity=".6"; --j;/*for moz*/}})()

Again, must all be on one line with no breaks.

.....Willy



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum