Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Nov 2003
    Location
    nowhere
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question how to pass var inside iframe to hidden element ?

    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):
    Code:
    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 ???
    Never end on learning~

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    The code seems fine.
    Did any error msg occur?
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New Coder
    Join Date
    Nov 2003
    Location
    nowhere
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    it is funny... that form can get data but we cant see the changes by browsing the source file. really get confused...
    Never end on learning~

  • #4
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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)
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #5
    New Coder
    Join Date
    Nov 2003
    Location
    nowhere
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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 ?
    Never end on learning~

  • #6
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    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.
    Last edited by glenngv; 02-06-2004 at 09:45 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #7
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for that Glenn

    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


  •  

    Posting Permissions

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