JavaScript - How To Pass Value To Iframe Src Attribute
I just stucked somewhere in js, i know its simple task but i don't know what's wrong but i believe i just need little guidance to get my result.
Here is my problem Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>sample</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <script language="JavaScript" type="text/javascript"> function OfferTwo(){ var Name = document.getElementById("txtName").value; var Email = document.getElementById("txtEmail").value; var sUrl = document.getElementById('offer2').src; document.getElementById('offer2').src = 'http://www.getmyname.com?info.php?dp=0&l=0&p=0&Name='+Name+'&email='+Email; alert(document.getElementById('offer2').src); } </script> </head> <body> <form name="myFrom" method="get" action=""> <p>Name <input name="txtName" type="text" id="txtName"> </p> <p>Email <input name="txtEmail" type="text" id="txtEmail"> </p> <p>Yes <input type="radio" name="rb" value="radiobutton" onClick="OfferTwo();"> No <input type="radio" name="rb" value="radiobutton"> </p> </form> <iframe name="offer2" id="offer2" src="" height="500px" width="100%" frameborder="0" scrolling="no">Your Browser not supporting</iframe> </body> </html> what i am trying to do on radio click 'YES' option i pass the value into querystring. Till now i got sucess to pass values but now problem is that how i pass this value into iframe src element. I tried alot did lot of googling but didn't get anything yet. Please help me, i know its very basic thing but i didn't trace my mistake. Thanks i n advance Similar TutorialsI need to copy input (checkbox) values from a form inside my iframe to the form in my parent frame using javascript and I'm not sure how to modify my current code to accomplish this! I'm using cold fusion to display the values from a database inside the iframe. Once all the values are loaded into the iframe, I need to be able to select as many as necessary and then submit the form from the parent frame which then runs a report that utilizes those values, but I can't do that because my code is written so that the values load in the iframe form and the action to run the report that requires those values is executed from the form in my parent frame. Here are the code snipits: Quote: Main "Parent" Frame Code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <cfparam name="WordFlag" default="0"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> <script language="javascript" type="text/javascript"> checked=false; function checkedAll (frm2) { var aa= window.document.ActivityFrame.document.getElementById('frm2'); if (checked == false) { checked = true } else { checked = true } for (var i =0; i < aa.elements.length; i++) { aa.elements[i].checked = checked; } } checked=true; function uncheckedAll (frm2) { var aa= window.document.ActivityFrame.document.getElementById('frm2'); if (checked == true) { checked = false } else { checked = false } for (var i =0; i < aa.elements.length; i++) { aa.elements[i].checked = checked; } } function checkVal (frm2) { var chks = window.document.ActivityFrame.document.getElementsByName('ActivityList'); var hasChecked = false; for (var i = 0; i < chks.length; i++) { if (chks[i].checked) { hasChecked = true; break; } } if (hasChecked == false) { alert("Please select at least one activity!"); return false; } return true; } </script> </head> <body> <table> <tr> <td><CFOUTPUT><H1>#lblReportName#</H1></CFOUTPUT></td> </tr> <tr> <td><CFOUTPUT><H1>#cookie.strProjectName#</H1></CFOUTPUT></td> </tr> </table> <form id="frm1" name="frmPMSelection" method="post" action="../report_manager/index.cfm?fuseaction=ProjectMediaAudit&lblReportName=#URLEncodedFormat(lblReportName)#&WordFlag=#WordFlag#" target="_self"> <table> <tr> <td align="left"><CFOUTPUT>#lblSelectPMAActivities#</CFOUTPUT><br /><br /></td> </tr> <tr> <td> <table> <tr> <td align="right"> <cfoutput> <a href="javascript:checkedAll()"><img src="../graphics_interface/buttons/select_all_#cookie.numLanguagePref#.gif" alt="#Request.lblSelectAll#" title="#Request.lblSelectAll#" align="absmiddle" border="0" /></a> <a href="javascript:uncheckedAll()"><img src="../graphics_interface/buttons/select_none_#cookie.numLanguagePref#.gif" alt="#Request.lblSelectNone#" title="#Request.lblSelectNone#" align="absmiddle" border="0" /></a> </cfoutput> <CFSCRIPT>Request.cshelp.showHelp(str_contentType="screen",str_contentID="",str_helpText=Request.str_lang_cshelp);</CFSCRIPT> </td> </tr> <tr> <td class="TABLEDATA"> <cfoutput> <iframe name="ActivityFrame" scrolling="auto" width="480" height="360" src="./index.cfm?fuseaction=ProjectMediaAuditFrame"></iframe> </cfoutput> </td> </tr> <tr> <td> <cfoutput> <input type="image" src="../graphics_interface/buttons/submit_#cookie.numLanguagePref#.gif" alt="#Request.lblSubmit#" title="#Request.lblSubmit#" align="absmiddle" border="0" onclick="return checkVal()" /> <a href="javascript:void(0);"><img src="../graphics_interface/buttons/cancel_#cookie.numLanguagePref#.gif" alt="#Request.lblCancel#" title="#Request.lblCancel#" align="absmiddle" border="0" onclick="self.location='../report_manager/index.cfm'" /></a> </cfoutput> </td> </tr> </table> </td> </tr> </table> </form> </body> </html> Quote: iFrame Code Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title></title> </head> <body> <table> <tr> <td> <form id="frm2"> <CFOUTPUT QUERY="qryLODetails"> <input type="checkbox" value="#lo_code#" name="ActivityList" />#lo_name#<br /> </CFOUTPUT> </form> </td> </tr> </table> </body> </html> I'm thinking that loading the values into some sort of hidden comma delimited string structure in the parent frame would do the trick, any ideas, and if I'm on the right track, how would I go about doing that? Also, you shouldn't need to see the query or the report page code to help me with the javascript I require, but if you do need anything else please let me know!! Hi all, I hope you can help I have some code which: 1) Opens a URL (e.g. google.com) in a hidden iframe, then 2) Redirects the visitor to a different URL (e.g. yahoo.com) after it has loaded... This works exactly as I need. What I'd like to do is the following: 1) Open a URL (e.g. google.com) in a hidden iframe, then 2) Redirect the visitor to a different URL (e.g. yahoo.com) in a full-screen iframe 3) The address bar of the full-screen iframe should be my domain (obviously!) Here's what I have so far... Hidden iframe -> New URL Code: Code: <html> <body> <script type="text/javascript"> var page_body = document.getElementsByTagName('body'); var myframe = document.createElement('iframe'); var id = Math.random(); myframe.setAttribute('id', 'myFrame'+id); myframe.src = 'http://google.com'; //First open Google in hidden iframe myframe.setAttribute('frameborder', '0') myframe.setAttribute('width', '0'); myframe.setAttribute('height', '0'); if (myframe.attachEvent) { myframe.attachEvent('onload', function() { top.location = 'http://yahoo.com'; //Once loaded redirect to Yahoo -- but the address bar shows yahoo.com -- I want the address bar to display mydomain.com/page.html }); } else if (myframe.addEventListener) { myframe.addEventListener('load', function() { top.location = ('http://yahoo.com'); }, false); } page_body[0].appendChild(myframe); </script> </body> </html> I have an example of some code which displays the full screen iframe, but my problem is... ...I can't figure out how to redirect to this after the hidden iframe has loaded Here's an example of how I want the redirect to display -- after the initial hidden iframe has loaded: Code: <html> <head> <script type="text/javascript"> function sendParams() { document.body.style.overflow = "hidden"; } </script> </head> <body> <!--Open Yahoo.com in a full screen iframe, and disable extra scrollbar --> <iframe height="100%" width="100%" frameBorder="no" onload="sendParams()" src="http://yahoo.com"></iframe> </body> </html> I've been beating my head against the wall today trying to figure this out, and I'm fresh out of ideas. If you can help, you'll have some serious gratitude and good karma thrown your way! Best wishes, and thanks in advance, Paul Hi there everybody, I've got this problem which I can't solve myself... I've got a website which has 3 colums and is hosted on domain1.com. in the right column I've got an Iframe which loads content from domain2.com . this content are some textboxes and a datepicker tool. if I press the 'search'-button in this Iframe I would like to refresh the mainpage (from domain1.com) so that another Iframe appears in the middle column. in this column i would like to load a new form from domain2.com which contains the values that I've put in in the form from the right Iframe. Unfortunally I can't get this to work... Will somebody please help me? Is there a way to resize an iframe dynamically so that you never get the scroll bar and essentially hide that there is an iframe? Better integration really. Basically I want to iframe a forum into my site so that the design down the sides and top which my friend does using iweb are not messed with. We have a central area which can be longer or shorter depending on the forum. I have used iframes for my site and found various javascripts so when a person clicks on say the audio page he http://www.krillmeed.com/index.html it takes them to the audio page but will load it into the index.html page. The problem is, especially with search engines, to point to that page, this is what the URL looks like to send someone to that page: http://www.krillmeed.com/?frame=0&sr...m%2Faudio.html which is not very clean at all, this is the javascript that i found that at least works: Child iframe script: Code: <script type="text/javascript"> (function(){ var qstr = '?frame=0&src=' + encodeURIComponent(location.href), lre = new RegExp('^' + location.protocol + '//' + location.hostname + '(()|(/)|(/index.html)|(/index.php))(()|(\\' + qstr + '))$'); if (!lre.test(parent.location.href)){ top.location.href = '/' + qstr; } })(); </script> Parent iframe Script: Code: <script type="text/javascript"> (function(){ function getQval(n) { if(typeof n !== 'string'){ return null; } var r = new RegExp('[?&;]' + n + '=([^&;#]*)'), m = location.search; return (m = r.exec(m))? unescape(m[1]) : null; } var f = getQval('frame'), s = getQval('src'); if(f && frames[f] && s && s.indexOf(location.protocol + '//' + location.hostname + '/') === 0){ frames[f].location.href = s; } })(); </script> Is there a "cleaner" way of doing this? This was an old code, i have yet to find a more modern one. Thank you in advance. I am aiming to change a couple of items on a CSS definition using JavaScript, so the servicer only needs to update one JS variable. I am so a novice at this... I would like to be able to set the "top" and "height" attributes of my graphbar ID element after the percent in the JS script is changed. Here's the js and CSS that is pertinent: Code: var btmrtx= 380; var btmrty= 280; var tplftx= 40; var tplfty= 20; var totalheight= (btmrty)-(tplfty); <!---- Here is the number or percentage of surveys done as a decimal. This you enter into this script for every update! --> var pctdone= .34; var barpixels= totalheight*pctdone; var newtoplfty = btmrty - barpixels; Code: #graphbar { background:#dd6000; position:relative; float:left; width: 20px; height: 36px; left: 40px; top: 244px; } I don't even know where to begin on a function. Thanks for help! Hi, I'm using JavaScript to check (or leave empty) a checkbox based on stored data. Code: for (var q=0;q<document.Simple.Subject.length;q++) { if (document.Simple.Subject[q].value == document.Restored.Subject.value) { document.Simple.Subject[q].checked = true; break; } It works perfectly, but I've discovered that it adds a simple "checked" to the form: Code: <input type="checkbox" name="Subject" value="Math" checked /> ... I thought I read that checked is not proper... it the attribute should really be checked="checked" . Is there a way to tweak this with JavaScript? Thanks. ~Wayne Hi, The following doesn't work: Code: <!DOCTYPE HTML> <title>Sample flash</title> <embed id="foo" src="http://www.w3schools.com/media/bookmark.swf" width="400" height="40" type="application/x-shockwave-flash" /> <script type="text/javascript"> document.getElementById("foo").setAttribute("bgcolor", "#00FF00"); </script> But if you change setAttribute to ("width", "800"), it works with no problem! What am I missing? Any help is appreciated! Mike ok guys, i am not very saavy with javascript and I dont know if this is an easy fix or something difficult, but here is my plan. I would like to have 4 divs with content in each and set each to occupy the same web space through absolute positioning. The .js would be for me to have three divs with a display:none and one to have display:block. and then at a set interval, have the divs switch role so that one that was display none is then block and the others are hidden. I dont want to have a page reload and I dont want to work in flash or anything like that, I just need an example of a script that will alternate through a set array of div ids (i.e. "<<div id="ad1"></div> div id="ad2"></div> <div id="ad3"></div> <div id="ad4"></div>, and change the display attribute every 10 seconds or so. Any help would be greatly appreciated thanks so much Hi, Not sure if I worded that question right. I have a web page which will display another web page in an iframe. But the content inside the iframe may change while the user interacts with it so I need to be able to resize the iframe height from code on the page inside the iframe. Any tips on how I can do that? I am using php and javascript. Thanks. When overlay(url) is fired theAgree.href is not being updated with theURL. theURL is being passed correctly, but in IE8 and below it never updates the ID "agree" with the URL. So when you click the "agree" link it just opens a new window using what's in the href which is #. In all other browsers the JS below will rewrite the "agree" URL with the URL that's sent to overlay(). But of course, not in IE8 and below. Code: function overlay(url) { var theURL = url; var theAgree = document.getElementById('agree'); theAgree.href = theURL; var theOverlay = document.getElementById('overlay'); theOverlay.style.visibility = (theOverlay.style.visibility == "visible") ? "hidden" : "visible"; } function overlay_close() { var theOverlayClose = document.getElementById("overlay"); theOverlayClose.style.visibility = "hidden"; theOverlayClose.style.display = "none"; } Code: <map name="Map" id="Map"> <area shape="rect" coords="382,1,573,237" onclick="overlay('http://site3.com'); return false;" href="#" /> <area shape="rect" coords="192,0,383,236" onclick="overlay('http://site3.com'); return false;" href="#" /> area shape="rect" coords="2,1,193,237" onclick="overlay('http://site3.com); return false;" href="#" /> </map> Code: <a name="agree" id="agree" href="#" onclick="overlay_close()" target="_blank" class="button"> Page: http://www.libertyvillesavingsbank.c...c-studio-card/ Hello, I believe this is something simple that I'm missing. I'm still fairly new to both js and php (and this may be a better question for the php forum - hopefully it makes sense though). What I have is a js function which uses the date/time to generate a 'unique' number onLoad, and places this number in the HTML as text in a <td></td>. This works fine. I'm also doing the same thing with the value attribute of a <input type="hidden"> element, which also works fine. The problem is, when I submit my form, php refuses to echo the value (but reports no errors). Here is all the relevant code: The HTML: Code: <td class='dandt' id='iquotenum' colspan='2'></td> The Javascript: Code: function loaded() { var d = new Date(); var vqtnum = document.getElementById("quotenumber"); var iqtnum2 = document.getElementById("iquotenum"); var vqtdat = document.getElementById("quotedate"); vqtnum.innerHTML = "" + (d.getMonth()+1) + d.getDate() + d.getFullYear() + "-" + d.getSeconds(); iqtnum2.innerHTML = "<input type='text' name='iqtnum' id='iqtnum' value='" + (d.getMonth()+1) + d.getDate() + d.getFullYear() + "-" + d.getSeconds() + "'></input>"; vqtdat.innerHTML = "" + (d.getMonth()+1) + "/" + d.getDate() + "/" + d.getFullYear(); } The PHP: Code: <?php $iqtnum = $_GET['iqtnum']; echo "<tr><td>Quote Number: </td><td>" . $iqtnum . "</td></tr>"; ?> I've verified by using Chrome's inspect element tool that the value attribute is being set correctly by my script, and I've got a few other php echos that get the user's input from other text boxes which use the same method*, and which work fine. Also while debugging I changed the type from hidden to text so I can see it easier. *Except that the value in this case is typed into the box, rather than generated by js. Thanks in advance. edit: I forgot to mention that I also have in the body tag of the HTML onLoad="loaded()". I am trying to get my script working in FF, IE and Opera but the getAttribute isn't working for me. The domain name isn't getting picked up I have tried this: var dom_name = document.getElementById('dom_nm').getAttribute("value",2); and this: var dom_name = document.getElementById('dom_nm').getAttribute('value'); After this I use the domain name like this: Code: if (per2 == 0) { item_desc = "Domain Name and DNS set up. Domain: "+dom_name+" Period: "+per1+"year"+" No Privacy."; } if (per2 > 0){ item_desc = "Domain Name and DNS set up. Domain: "+dom_name+" Period: "+per1+"year"+" Including: Privacy: "+per2+"year."; } document.getElementById('item_pay').setAttribute("value","item_desc"); ( I also tried: Code: document.getElementById('item_pay').setAttribute('value') = item_desc; but that didn't seem to work either ) The HTML is like this: Code: <div style="margin: 5px auto;"> <table> <th>Your New Domain Name Order</th> <tr><td>Product</td><td>Cost</td><td>Years (max. 10)</td><td style="text-align: right;">Total Cost</td></tr> <tr><td id="dom_nm" value="John.Doe"><?php echo "Domain: $N_dom.$N_tld" ?></td><td id="price" value = '<?php echo "$priceN" ?>' ><?php echo $priceN ?></td><td><input style="background-color: yellow; font-weight: bold;" type='TEXT' id="per_1" size = '10' value = '<?php echo "$period_1" ?>' ></td><td><input type='TEXT' id="total_1" style="text-align: right;" value = '<?php echo "$total_1" ?>'></td></tr> <tr><td>Domain Privacy</td><td>8.70</td><td><input style="background-color: yellow; font-weight: bold;" type='TEXT' id="per_2" size = '10' value = '<?php echo "$period_2" ?>'></td><td><input type='TEXT' id="total_2" style="text-align: right;" value = '<?php echo "$total_2" ?>'></td></tr> <tr><td>Total Order.</td><td> --- </td><td> --- </td><td><input type='TEXT' id="total_3" style="text-align: right; font-weight: bold;" value = '<?php echo "$total_3" ?>'></td></tr> </table> </div> The result is that I get a zero ( 0 ) where the domain should be. Like this: Domain Name and DNS set up. Domain: 0 Period: 2year Including: Privacy: 2year. Plus Free Blog Install. Any ideas what I am doing wrong ? Thanks I have tried to manipulate attributes in a specific class & am successful by using jquery. Now for the purpose of learning I want coders to look at my simple snippet & tell me how can I use functions namely getElementsByTagName & For loop instead of each. http://jsfiddle.net/defencedog/Zz7cX/ [My snippet adds 'fullscreen' functionality to youtube vids, which unfortunately isn't present in default phpBB3 forum engine] regards;; How would you access information about various attributes of an element with javascript?
Hi all, I have the following code: Code: <html> <head> <title>Page Title</title> <script type='text/javascript'> mymusic=[]; tracks=[]; mymusic=[{title:"a",artist:"b",artwork:"c",tracks:[{tracktitle:"d",trackmp3:"e"},{tracktitle:"x",trackmp3:"z"}]},{title:"f",artist:"g",artwork:"h",tracks:[{tracktitle:"i",trackmp3:"j"}]}]; function nowplaying(trackindex,albumindex){ q+="<html><head></head><body><p>Song:</p>"; q+="<p>"+mymusic[albumindex].tracks[trackindex].tracktitle+"</p>"; q+="<p>from Album:</p>"; q+="<p>"+mymusic[albumindex].title+"</p>"; q+="<img src=\""+mymusic[albumindex].artwork+"\">"; with(document.getElementById('nowplays').contentDocument){ open(); write(p); close(); } } function anything(i){ p=""; p+="<html><head></head><body><form><select onchange='parent.nowplaying(this.selectedIndex,i);' size='"; p+=mymusic[i].tracks.length+1+"'>"; p+="<option>Choose a song...</option>"; for(j=0;j<mymusic[i].tracks.length;j++){ p+="<option>"+mymusic[i].tracks[j].tracktitle+"</option>"}; p+="</select></form></body></html>"; with(document.getElementById('songs').contentDocument){ open(); write(p); close(); } } function showinitial(){ s=""; s+="<html><head></head><body><form><select onchange='parent.anything(this.selectedIndex-1);' size='"; s+=mymusic.length+1+"'>"; s+="<option>Choose an artist...</option>"; for(i=0;i<mymusic.length;i++){ s+="<option>"+mymusic[i].title+"</option>"}; s+="</select></form></body></html>"; alert(s); with(document.getElementById('albums').contentDocument){ open(); write(s); close(); } } </script> </head> <body onload="showinitial();"> <style type='text/css'> div { padding:0;margin:0; } .container { position:relative; width:100%; height:100%; } .topcontainer { height:65%; } .box { float:left; width:32%; height:90%; padding:5px; border:1px solid black; overflow:scroll; } .bottom { height:35%; border:1px solid black; } </style> <div class="container"> <div class="topcontainer"> <div class="box"><p>Albums:</p><iframe id='albums'>hi </iframe></div> <div class="box"><p>Songs:</p><iframe id='songs'></iframe></div> <div class="box"><p>Now Playing:</p><iframe id='nowplays'></iframe></div> </div> <div class="bottom"></div> </div> </body> </html> which, as you will see if you run it, creates an iframe-based media player based on a collection of albums, and songs within these albums (I just used letters to define these albums and songs in the mymusic array, for simplicity). Focusing on the top 3 iframes, the way I have set out the user interaction is to generate the HTML for forms of available albums and songs using Javascript, and write them to the iframes in the body. This nearly works fine: if you run it and make a selection in the 'Albums' menu, you will see that the options this causes to display in the 'Songs' menu correspond with the mymusic array, so this works. However, when I choose a song, the function "nowplaying(trackindex,albumindex)" should be called using an onchange event in the 'Songs' form, in the exact same way as in the form generated using "showinitial()"...but the function isn't called. I have ruled out the coding of "nowplaying" itself as a cause, because even when I change "nowplaying" to sth simple like alert("hello"), with no variables or anything being passed in, it still doesn't call. So this leads me to think the problem is with the onchange attribute in "anything", but I can't see what the problem is. The way I coded it is no different to before, and that worked fine, so why won't this work? Any help would be much appreciated! how can i get the number values from style atrributes. currently i have test_tree.style.top which would return 50px instead of 50, is there anyway i can take just the 50 as an integer
Which of these is the correct way to set the className attribute, or are they both okay? option 1: Code: var t = document.createElement("p"); t.className = "myclass"; option 2: Code: var t = document.createElement("p"); t.setAttribute("class","myclass"); I got this code Code: Div= document.createElement("div"); Table= document.createElement("table"); Table.setAttribute("style","width:100px;height:100px;background-color : #708090;"); Table.setAttribute("bgColor","#708090"); tr=document.createElement("tr"); td=document.createElement("td"); text=document.createTextNode(aText); myTableBody = document.createElement("TBODY") td.appendChild(text); tr.appendChild(td); myTableBody.appendChild(tr); Table.appendChild(myTableBody); Div.appendChild(Table); document.getElementsByTagName('body').item(0).appendChild(Div); Now it all works fine with the exception of the Code: Table.setAttribute("style","width:100px;height:100px;background-color : #708090;"); so I was wondering how do I set the style attribute in the table node? |