JavaScript - Javascript Functions Across Frames Desperation!
Hey guys,
I'm using javascript in a menu to change the colour scheme of a page with frames and wondered how I could make this Javascript work across frames. The top frame is the colour picker with the Javascript and the bottom frame is the html template that will be changing colour scheme. JS: Code: var cols = { red: [ { el: '.headertitle', color: '#FF0000' }, { el: '#wrapper #maincontent #leftpanel ul.leftnavigation li a.current', bgcolor: '#FF0000', color: '#FFFFFF' }, { el: '#wrapper #maincontent #leftpanel', border: '#FF0000' }, { el: '#wrapper #maincontent #leftpanel ul.leftoffers li div.titlebody a', color: '#FF0000' }, { el: '#wrapper #maincontent #editable h2', color: '#FF0000' }, { el: '#wrapper #maincontent #rightpanel', border: '#FF0000' }, { el: '#wrapper #footer', bgcolor: '#FF0000' }, { el: '#wrapper #maincontent #leftpanel ul.leftoffers li', bgcolor: '#F6D9D9'}, { el: '.choosecolour', border: '#fff' }, { el: '#cbred', border: '#000' } ], orange: [ { el: '#header', bgcolor: '#ff8c10', color: '#ffffff' }, { el: '#nav li a', bgcolor: '#d63b18', color: '#ffffff', hoverbgcolor: '#fc6827', hovercolor: '#ffffff' }, { el: '.primaryBgCol', bgcolor: '#ff8c10', color: '#ffffff' }, { el: '.secondaryBgCol', bgcolor: '#f8a955', color: '#ffffff' }, { el: '.footerBgCol', bgcolor: '#f2441c' }, { el: '.footerTextCol', color: '#ffffff' }, { el: '.borderCol', border: '#ff8c10' }, { el: '#logo', src: 'images/logo_orange.gif'}, { el: '.choosecolour', border: '#fff' }, { el: '#cborange', border: '#000' } ] }; function changeColour(col) { $A(cols[col]).each(function(i) { $$(i.el).each(function(j) { if (i.bgcolor) j.setStyle({ backgroundColor: i.bgcolor }); if (i.color) j.setStyle({ color: i.color }); if (i.border) j.setStyle({ borderColor: i.border }); if (i.src) j.writeAttribute('src', i.src); // hover colours if (i.hovercolor || i.hoverbgcolor) { j.onmouseover = function() { this.setStyle({ backgroundColor: i.hoverbgcolor, color: i.hovercolor }); }; j.onmouseout = function() { this.setStyle({ backgroundColor: i.bgcolor, color: i.color }); }; } }); }); } JS picker HTML code: Code: <div class="colours"> <div class="choosecolour" id="cbred" style="background-color: #c90c12;" onclick="changeColour('red');"></div> <div class="choosecolour" id="cborange" style="background-color: #ff8c10;" onclick="changeColour('orange');"></div> </div> Anyone know how I can make the colour scheme of page in lower frame change when colour is picked in top page frame? Similar TutorialsWhat's Up? OK, So I've been trying to add text to a <textarea> and text field tag inside of a frame via JavaScript, I did find a tutorial and using off-line html's it worked, But when I try to use a online frame, It doesn't work. OK, So one html opens two frames which are. Left.html Code: <HTML> <HEAD> <TITLE>JavaScript Example 13</TITLE> </HEAD> <BODY> <INPUT type="button" value="Button" onClick=""> </FORM> </BODY> </HTML> right.html Code: <form action="posting.php" method="post" name="post" onsubmit="return checkForm(this)"> <table width="100%" cellspacing="2" cellpadding="2" border="0"> <input class="post" type="text" value="" tabindex="2" style="width: 450px;" maxlength="60" size="45" name="subject"/> <textarea onkeyup="storeCaret(this);" onclick="storeCaret(this);" onselect="storeCaret(this);" class="post" tabindex="3" style="width: 450px;" cols="35" rows="15" name="message"/></textarea> <input type="submit" value="Submit" class="mainoption" name="post" tabindex="6" accesskey="s"/> Anyone Know What To Do? Thanks Bye. Hi, I will appreciate if someone could help me with this Case Problem. For some reason that I don't understand, it seems to be working in Firefox, but not IE. Well, most of it is working. The problem is to create a "Demo" which has three frames in rows. The first frame at the top is the title bar with "Submit Code", "show only code", "show only preview", and "show code and preview" buttons. The middle frame has 2 textarea boxes. The html code goes in the left box, and the css styles go in the right box. Once you enter any code in their respected boxes, and press "submit code", it should be rendered as a web page in the third frame below the boxes (which is just an empty document). I have attached a screenshot of how it should look like, and I am posting my entire code below. Everything is working except for the rendering of the web page in the third frame. When I click on submit, I get no errors, nothing happens. Any help or suggestions would be greatly appreciated. Thank you. Code: function showPreview(){ parent.document.getElementById("demo").rows="100,1,*"; } function showCode(){ parent.document.getElementById("demo").rows="100,*,1"; parent.frames[1].document.getElementById("inputhtml").style.height="300px"; parent.frames[2].document.getElementById("inputcss").style.height="300px"; } function showBoth(){ parent.document.getElementById("demo").rows="100,210,*"; parent.frames[1].document.getElementById("inputhtml").style.height="150px"; parent.frames[2].document.getElementById("inputcss").style.height="150px"; } function sendCode(){ var previewFrame=parent.frames[3]; var htmlCode=parent.frames[1].document.getElementById("inputhtml").value; var cssCode=parent.frames[2].document.getElementById("inputcss").value; previewFrame.document.write("<html><head><title></title>"); previewFrame.document.write("<style type='text/css'>"+cssCode+"</styles>"); previewFrame.document.write("</head>"); previewFrame.document.write("<body>"+htmlCode+"</body></html>"); //previewFrame.document.close(); } </script> </head> <body> <form name="control" id="control" action=""> <h2 id="demotitle">Creating Web Pages</h2> <p> <input type="button" value="Submit Code" onClick="sendCode()"/> <input type="button" value="Show Only Code" onClick="showCode()" /> <input type="button" value="Show Only Preview" onClick="showPreview()"/> <input type="button" value="Show Code and Preview" onClick="showBoth()"/> </p> </form> </body> </html> Okay, here is my assignment: reate an HTML document with 2 JavaScript functions as described below. Call the document useparameters.html The first function will use a parameter for the Width of a horizontal rule. When called, the function will draw a horizontal rule of a width specified by the Functions argument. Prompt the user for the pixel width information. The second function will use parameters for two heading sizes. The parameters will be used for the size of the text that will be displayed on the first line and the size of the text that will be displayed on the second line. The heading size will be different on the first and second lines. Prompt the user for these two headings as well (one prompt for each). The body of the HTML document will contain a page heading and call the two functions you created, displaying a horizontal rule and two lines of text which will be formated based upon the parameters the user entered into the prompts. Here is my 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>Use Parameters</title> <script type="text/javascript"> <!-- var hrsize var htwosize var psize function bar() { hrsize = window.prompt( "Please enter the size you want your horizontal rule to be (in pixels)", 50 ) hsize = hrsize document.write("<HR ALIGN='left' width=" + hrsize + ">"); } function output() { htwosize = window.prompt( "Please enter the size you want your heading to be (in pixels)", 18 ) htwosize = htwosize document.write("<h2" + htwosize + "/h2>") } function output() { psize = window.prompt( "Please enter the size you want your paragraphcs to be (in pixels)", 12 ) psize = psize document.write("<p" + psize + "/p>") } --> </script> </head><body> <script type="text/javascript"> <!-- bar(hrsize) output(htwosize) output (psize) --> </script> <h2>JavaScript Rules!</h2><p>Using JavaScript is fun! </p> <p> This is some standard HTML, unlike the above which was generated with javaScript.</p> </body> </html> What am I doing wrong? New assignment. This is the code i have below already supplied now. not exactly correct yet but want to just get something to work from i need to insert an embedded script element in head section of document, purpose os to hide htmlcode and csscode frames to provide more screen space to hide 2 frames i am to change value of rows attribute in demo frameset to "100,1,*" id of the frameset object is demo Code: <title>Web Design Demo Control Buttons</title> <link href="title.css" rel="stylesheet" type="text/css" /> <script src="demo.htm" type="text/javascript"></script> <script type="text/javascript"> function showPreview(id,x,y) { object=document.getElementById(id); object.style.visibility="hidden"; top.FrameName.rows = "100,1,*"; } </script> just for your reference here is the demo part Code: <html> <head> <!-- New Perspectives on JavaScript Tutorial 6 Case Problem 3 Web Design Demo Filename: demo.htm Supporting files: css.htm, html.htm, title.htm --> <title>HTML Demo</title> </head> <frameset rows="100,210,*" id="demo" name="demo"> <frame name="title" id="title" src="title.htm" scrolling="no" /> <frameset cols="*,*"> <frame name="code1" id="code1" src="html.htm" /> <frame name="code2" id="code2" src="css.htm" /> </frameset> <frame name="output" id="output" /> </frameset> </html> how does this look so far just remember the top code is what i am working on what should i change and add? suggestions anyone? hi Folks, I am new for HTML FRAMES. I have the code like as shown below. Code: <FRAMESET rows="0,*" FRAMEBORDER=0 FRAMESPACING=0 BORDER=0> <FRAME SRC="Javascript:parent.getStartupScreen ()" name="RP" scrolling="no" > <FRAMESET rows="0,*,0,8%" FRAMEBORDER=0 FRAMESPACING=0 BORDER=0> <FRAME SRC="/jsp/hierarchy/control.jsp" name="cF" scrolling="NO"> <FRAME SRC="Javascript:parent.getBlank()" name="vF" scrolling="AUTO"> <FRAME SRC="Javascript:parent.getBlank()" name="dF" scrolling="NO"> <FRAME SRC="/jsp/resourceplanner/ResourcePlannerFooter.jsp" name="RPF" scrolling="NO"> </FRAMESET> </FRAMESET> i am currently on "RPF" Frame. I want to refer "RP" Frame loaded "Form" Elements . Please suggest me . Thanks... Hi, im having a problem adding a frame busting killer that counteracts a frame killer script on sites so i can load them inside my iframes.. here is the code i use <?php $result = mysql_query("SELECT ru.id, ru.username, ru.owid FROM raidbar_users ru LEFT JOIN raidbar_groups rg ON ru.groupid = rg.id WHERE rg.id = '".(int)$_REQUEST['group']."'") or die(mysql_error()); $myRaidid = raidid(); if(isset($_GET['gm'])) { echo '<FRAMESET rows="*,*,*,30" frameborder="0">' . "\n"; echo ' <FRAMESET cols="*,*" frameborder="0" scrolling="no">' . "\n"; $i = 0; while($row = mysql_fetch_array($result)) { if ($i == 2) { echo ' </FRAMESET>' . "\n"; echo ' <FRAMESET cols="*,*" frameborder="0" scrolling="no">' . "\n"; $i = 0; } echo ' <FRAME src="http://'.$server[$siteConfig['userServer']].'.***********/joinraid.php?raidid=' . $myRaidid . '&suid=' . $row['owid'] . '&serverid='.$siteConfig['userServer'].'">' . "\n"; $i++; } echo ' <FRAME src="">' . "\n"; echo ' </FRAMESET>' . "\n"; echo ' <FRAMESET frameborder="0" scrolling="no">' . "\n"; echo ' <FRAME src="http://'.$server[$siteConfig['userServer']].'.***********/raidmembers.php?raidid=' . $myRaidid . '">' . "\n"; echo ' </FRAMESET>' . "\n"; echo '</FRAMESET>' . "\n"; } else { echo '<table cellspacing=1 cellpadding=1>' . "\n"; echo '<tr>' . "\n"; $i = 0; while($row = mysql_fetch_array($result)) { if ($i == 2) { echo '</tr>' . "\n"; echo '<tr>' . "\n"; $i = 0; } echo ' <td><iframe src="./acct.php?suid=' . $row['owid'] . '" width=450 height=225 scrolling=no frameborder=0></iframe>' . "\n"; $i++; } echo '</tr>' . "\n"; echo '<tr>' . "\n"; echo ' <td><iframe src=http://'.$server[$siteConfig['userServer']].'.***********/raidmembers.php?raidid=' . raidid() . '&serverid='.$siteConfig['userServer'].' width=250 height=30 scrolling=no></iframe>' . "\n"; echo '</tr>' . "\n"; echo '</table>' . "\n"; } ?> Now im told to use the following.. <script type="text/javascript"> var prevent_bust = 0 window.onbeforeunload = function() { prevent_bust++ } setInterval(function() { if (prevent_bust > 0) { prevent_bust -= 2 window.top.location = 'http://server-which-responds-with-204.com' } }, 1) </script> or var prevent_bust = 0; // Event handler to catch execution of the busting script. window.onbeforeunload = function() { prevent_bust++ }; // Continuously monitor whether busting script has fired. setInterval(function() { if (prevent_bust > 0) { // Yes: it has fired. prevent_bust -= 2; // Avoid further action. // Get a 'No Content' status which keeps us on the same page. window.top.location = 'http://server-which-responds-with-204.com'; } }, 1); But the window.top.location i dont know how to incorporate that to work. Can anyone help? Hello, Iam currently experimenting with Java Scripting and have hit a wall about the use of Functions. I am trying to create a difference function which would work out the difference between two numbers. e.g. 14 and 18 I am able to create a function and if statement to find the larger number of a argument but am having trouble writing one to find the difference between two numbers. Iam also confused (i know probably a silly question) but is the operator used the same for this function. Hope people can make sense of that. Thanks, Hello all here is a more intelligent question. This one is just on an exercise I am doing. I have to call a function using parameter values. my main function is this Code: function showResults(race,name,party,votes) or just function showResults in the next lines below i have to call the function is this the right way Code: <script type="text/javascript"> { showResults=("race[0],name1,party1,votes1"); } </script> or should it be without the { and } like this? Code: script type="text/javascript"> showResults=("race[0],name1,party1,votes1"); </script> or is it like this Code: script type="text/javascript"> showResults(race[0],name1,party1,votes1); </script> Thanks all, what would be the proper method Thanks Forgive me if the code is rather bad, I am new to Javascript. Now what I'm aiming to do is after I have entered the contents of the Array's I then want to query the newly created array/database, based on the track number, Via a seprate function. However all the values I entered, always come up empty. No matter how many solutions I tried I can't get the query to work. So I've decided to come to you guys/gals for help. Code: mainMenu() function mainMenu() { menu = 0; menu = eval(prompt("Select an Operation to Continue\n ====================\n 1 - Create new Database\n 2 - Query Database\n 3 - Show Report\n Any other to exit")); switch (menu) { case 1: insert(trackNumber) break; case 2: query(trackNumber) break; case 3: break; } } // Enter the track number function trackNumber() { var theNumber = eval(prompt("Enter Track Number")); if ((theNumber >= 0) && (theNumber < 100)) { return theNumber; // Stores the track number for insert(trackNumber) } } // This function will allow the user via the (trackNumber) // parameter to insert the contents of the database function insert(trackNumber) { // Create new Array's trackNum = new Array(5) trackName = new Array(5) trackArtist = new Array(5) // For each Track we want to hold the trackNumber(), // the track name and the track's artist. for(var i = 0; i < trackNum.length; i++) { trackNum[i] = trackNumber() trackName[i]= prompt("Enter Track Name: " + i) trackArtist[i] = prompt("Enter Track Artist: " + i) } } // This Function will allow the user to query the database, based on track number. function query(trackNumber) { var trackSearch = trackNumber() var j = 0; for(j in query) { if (query[j] == trackSearch) { alert("Track Number: " + trackSearch + "\nTrack Name: " + trackName[j] + "\nTrack Artist " + trackArtist[j]); break; } else if (query[j] != trackSearch) { alert("Track Number: Empty" + "\nTrack Name: Empty" + "\nTrack Artist: Empty"); break; } } } If someone could please help me by posting some relevant code that would help accomplish this, I would greatly appreciate it, as so far I have been scratching my head puzzled, at how I could solve this. i am new to JavaScript and i have an assignment to create a tour calculator here is the code and its not working please help its urgent thanks. [code] <!DOCTYPE> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> .font { font-size: 28pt; } font2 { font-size: 15pt; } </style> </head> <body> <strong class="font">USA Tour Cost Calculator</strong> <br/> <br/> Conplete the form below to calculate the cost of your tour of the United States <script type="text/javascript"> function calculate(){ var cost=0; var accomodation=0 var radio1 var radio2 var duration=0 function accomodation() { for (var i=1; i<=3; i++) {radio1= document.getElementById("radio"+i); if (radio1.checked==true) {accomodation=i;}} if (accomodation=1){cost=parseInt(radio.value); return value;} else if (accomodation=2){cost=parseInt(radio.value); return value;} else if (accomodation=3) {cost=parseInt(radio.value);return value;} else {window.alert("Please select the type of accomodation")} } function peak() { var cost=accomodation() var peak=document.getElementById("check1") if (peak.checked==true) {cost +=parseInt(checkbox.value); return value;} else {cost=accomodation()} } function calc(){ var cost=peak() for (var i=1; i<=4; i++){ radio2=document.getElementById("Radiobutton"+i); if (radio2.checked==true) {duration=i;} if (duration=1) {cost*=parseInt(radio.value); return value;} else if (duraion=2){cost*=parseInt(radio.value); return value;} else if(duration=3) {cost*=parseInt(radio.value); return value;} else if(duration=4){caost*=parseInt(radio.value); return value;} else {alert("Please select the duration of tour")} } } </script> <br/> <form id="form2" name="form2" method="post" action=""> <p> <label> <input type="radio" name="RadioGroup2" value="95" id="Radio1" /> Camping</label> <br /> <label> <input type="radio" name="RadioGroup2" value="140" id="Radio2" /> Budget Hotel</label> <br /> <label> <input type="radio" name="RadioGroup2" value="170" id="Radio3" /> Premier Hotel</label> <br /> </p> </form> Click here if you will be travelling during the peak season of June to August: <input name="" type="checkbox" value="20" id="check1" /> <br/> <br/> Duration of tour: <form id="form1" name="form1" method="post" action=""> <label> <input type="radio" name="RadioGroup1" value="4" id="Radiobutton1" /> 4 days, 1sate</label> <br /> <label> <input type="radio" name="RadioGroup1" value="7" id="Radiobutton2" /> 7 dasy, 3 states</label> <br /> <label> <input type="radio" name="RadioGroup1" value="14" id="Radiobutton3" /> 14 days, 12 states</label> <br /> <label> <input type="radio" name="RadioGroup1" value="20" id="Radiobutton4" /> 20 days, 18 states</label> <br /> </p> </form> <br/> <p> <input type="submit" value="Calculate" onClick='alert("The total cost of your tour is $calculate();")'><input type="reset" value="Reset" /></p> </body> </html> [code] I'm building a webpage using javascript and iframes. Basically I have an iframe in the middle of the index.html page that links to another html page (let's call it iframe.html). My question is, is it possible to call a javascript function from iframe.html to control an object on index.html? If so, how do I do this? I'd like to be able to assign an image in iframe.html with the hyperlink of href="javascript:function()", where the function effects the CSS of a div on index.html. Thanks All -- I have a JavaScript config file called gameSetting.js which contains a bunch of variables which configures a particular game. I also have a shared JavaScript library which uses the variables in gameSetting.js, which I include like so: <script type="text/javascript" src="gameSetting.js" ></script> <script type="text/javascript" src="gameLibrary.js" ></script> In gameSetting.js I have: $(document).ready(function() { // call some functions / classes in gameLibrary.js } in Firefox, Safari, and Chrome, this works fine. However, in IE, when it's parsing gameSetting.js, it complains that the functions that live in gameLibrary.js aren't defined. When it gets to parsing gameLibrary.js, the variables in gameSetting.js are reported as not being defined. I've tried dynamically bootstrapping the gameLibrary file using this function in document.ready for dynamic load... $.getScript("gameLibrary.js"); However, the same problem still happens in IE, where when it parses the files individually it's not taking into context the file/variables that came before, so it's not an out of load order problem. My options a 1) collapsing all the functions in gameLibrary.js and variables in gameSetting.js into one file. However, this is not practical because this is dealing with literally hundreds of games, and having a gameLibrary.js in ONE location for ONE update is what makes most logical sense. 2) figure out a way to get this to work where variables in file1 are accessible to file2 in IE (as it seems they are in other browsers). jQuery seems to be able to have multiple plugins that all refer to the based jQuery-1.3.2.js, so I know there is a way to get this to work. Help appreciated. Nero Hello, I am new to javascript and have managed to create the below form with few fields validation that is working. I also have an email format validation function which is not working. Any help would be hightly appreciated. Below with the form with the javascript <html> <script language="JavaScript" type="text/javascript"> <!-- var radio_selection=""; function checkform ( form ) { **// ** START ** **if (form.name.value == "") { ****alert( "Please enter your name." ); ****form.name.focus(); ****return false; **} if (form.Phone.value == "") { ****alert( "Please enter your phone number." ); ****form.Phone.focus(); ****return false; **} **if (form.email.value == "") { ****alert( "Please enter your email." ); ****form.email.focus(); ****return false; } if (radio_selection=="") { alert("Please indicate your attendance."); return false; } *// ** END ** **return true; } function checkEmail(form) { if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(form.email.value)) { return true; } alert("Invalid E-mail Address! Please re-enter."); return false; } //--> </script> <body> <form style="font-family:lucida calligraphy;font-size:120%;color:maroon" action="invitees.php" method="post" onsubmit="return checkform(this);checkEmail(this.email.value);"> <table cellspacing="5" cellpadding="5" border="0"> <tr> <td valign="top" > <style="font-family:lucida calligraphy;font-size:100%;color:maroon">Name: </td> <td valign="top"> <input type="text" name="name" id="name" size="40" value="" /> </td> </tr> <tr> <td valign="top"> Phone Number </td> <td valign="top"> <input type="text" name="Phone" id="Phone" size="40" value="" /> </td> </tr> <tr> <td valign="top"> Email Address: </td> <td valign="top"> <input type="text" name="email" id="email" size="40" value="" /> </td> </tr> <tr> <td valign="top"> Will You Attend </td> <td valign="top"> <input type="radio" name="Attendance" id="Attendance_0" value="Yes" onClick="radio_selection='yes'" /> Yes <input type="radio" name="Attendance" id="Attendance_1" value="No" onClick="radio_selection='no'"/> No <input type="radio" name="Attendance" id="Attendance_2" value="Maybe" onClick="radio_selection='maybe'"/> Maybe<br/> </td> </tr> <tr> <td valign="top"> Adults <select name ="adults" id="Adults" > <option>0</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> </select> </td> <td valign="top"> Kids <select name="kids" id="Kids" > <option>0</option> <option>1</option> <option>2</option> <option>3</option> <option>4</option> <option>5</option> <option>6</option> <option>7</option> <option>8</option> <option>9</option> <option>10</option> </select> </td> </tr> <tr> <td valign="top"> Post a Note </td> <td valign="top"> <textarea name="Note" id="Note" rows="6" cols="35"></textarea> </td> </tr> <tr> <td colspan="3" align="center"> <input type="submit" value=" Submit Form " /> </td> </tr> </table> </form> </html></body> Hi all, I've written the following script: Code: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Keys2</title> <script type="text/javascript"> function keyPress(key){ document.getElementById('rect01').style.fill = "red"; } </script> <style> .button { width: 100px; padding-right:10px; height:2em; background-color:#FC3; border-radius:3px; color:#fff; font-weight:bold; } ul { list-style-type: none; padding: 0; margin-left:25px; } li { float:left; width:30px; margin-right:25px; padding:10px; height:2em; background-color:#FC3; font-size:xx-large; } </style> </head> <body> <div> <svg width="1000" height="200"> <rect x="25" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect01"/> <rect x="100" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect02"/> <rect x="175" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect03"/> <rect x="250" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect04"/> <rect x="325" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect05"/> <rect x="400" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect06"/> <rect x="475" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect07"/> <rect x="550" y="50" fill="#FFFFFF" stroke="#000000" width="50" height="150" id="rect08"/> </svg> </div> <div> <ul> <li><a href="#" class="button" onClick="keyPress(rect01);">A</a></li> <li><a href="#" class="button" onClick="keyPress(rect02);">B</a></li> <li><a href="#" class="button" onClick="keyPress(rect03);">C</a></li> <li><a href="#" class="button" onClick="keyPress(rect04);">D</a></li> <li><a href="#" class="button" onClick="keyPress(rect05);">E</a></li> <li><a href="#" class="button" onClick="keyPress(rect06);">F</a></li> <li><a href="#" class="button" onClick="keyPress(rect07);">G</a></li> <li><a href="#" class="button" onClick="keyPress(rect08);">H</a></li> </ul> </div> </body> </html> Now, I could write a version of the keypress function for each rectangle, but that seems like poor coding. Can anyone point out how I might restructure the function or the code so that I can pass the number in the onClick to the rectangle it refers to? Thanks hey all, I am now at the point of being able to see the light at the end of the tunnel (woot!). After a lot of help from you guys I have tackled my RSS feed issue (sort of) to the point where i have a page that does basically what I need it to (http://www.the-rational-investor.com/test042311.php/). I now need to incorporate this java script developed into the big picture and of course, there seems to be problems. Since I know it works on its own, I must be running into problems getting all the functions working simultaneously and I once again need to call on the board's brilliance in figuring out what I am doing wrong....so here it goes I have taken out a lot of unnecessary code just to focus on the java script. Yes there is PHP code embedded but please don't beat up on me too much for that. here is the main page code: Code: <head> <? // function for onmouseover to do ALL THREE tasks // ?> <script type="text/javascript"> function doChanges(y){ var z= y; var imagevar = myimages[z]; var imagethis = this.href; changeimage(imagevar,imagethis); changetext(z); var x=y; var rssfeedvar = myArrayRssFeed[x]; showRSS(rssfeedvar); } </script> <? // First Task - function for onmouseover TEXT // ?> <script type="text/javascript"> function changetext(z){ var s= z; var textchangeEntries = myArrayEntries[s]; var id = document.getElementById("DBtext_large"); id.innerHTML=textchangeEntries; var textchangeWebadr = myArrayWebadr[s]; var id = document.getElementById("DBtext_link").getElementsByTagName('a')[0]; id.nodeValue=textchangeWebadr; id.setAttribute('href',textchangeWebadr); id.innerHTML=textchangeWebadr; var textchangeEmail = myArrayEmail[s]; var id = document.getElementById("DBtext_email"); id.innerHTML=textchangeEmail; var textchangeRssUrl = myArrayRssUrl[s]; var id = document.getElementById("DBtext_rssUrl"); id.innerHTML=textchangeRssUrl; var textchangeRssFeed = myArrayRssFeed[s]; var id = document.getElementById("DBtext_rssFeed"); id.innerHTML=textchangeRssFeed; } </script> <? // Second Task - functions for onmouseover IMAGES // ?> <script type="text/javascript"> function changeimage(towhat,url){ if (document.images){ document.images.targetimage.src=towhat.src gotolink=url } } function warp(){ window.location=gotolink } </script> <script type="text/javascript"> var myArrayEntries = ["<?php echo implode('","',$map_entry_array);?>"]; var myArrayWebadr = ["<?php echo implode('","',$web_adr_array);?>"]; var myArrayEmail = ["<?php echo implode('","',$email_adr_array);?>"]; var myArrayRssUrl = ["<?php echo implode('","',$rss_url_array);?>"]; var myArrayRssFeed = ["<?php echo implode('","',$rss_feed_array);?>"]; var myimages=new Array() var gotolink="#" function preloadimages(){ for (i=0;i<preloadimages.arguments.length;i++){ myimages[i]=new Image() myimages[i].src=preloadimages.arguments[i] } } preloadimages(<?echo("$qs1");?>); </script> <? // Third Task - functions for onmouseover RSS FEED // ?> <script type="text/javascript"> function showRSS(str) { if (str.length==0) { document.getElementById("rssOutput").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("rssOutput").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","getrss.php?q="+str,true); xmlhttp.send(); } </script> </head> getrss.php is unchanged Code: <?php //get the q parameter from URL $q=$_GET["q"]; //find out which feed was selected if($q=="http://twitter.com/statuses/user_timeline/53777622.rss") { $xml=("http://twitter.com/statuses/user_timeline/53777622.rss"); } elseif($q=="http://www.autisticsociety.org/rss/news2.php") { $xml=("http://www.autisticsociety.org/rss/news2.php"); } elseif($q=="http://sableresources.com/news/") { $xml=("http://sableresources.com/news/"); } elseif($q=="http://www.northgateminerals.com/rss/pressrelease.aspx") { $xml=("http://www.northgateminerals.com/rss/pressrelease.aspx"); } elseif($q=="http://www.thompsoncreekmetals.com/s/RSS.asp?MaxItems=4&Version=RSS2.0") { $xml=("http://www.thompsoncreekmetals.com/s/RSS.asp?MaxItems=4&Version=RSS2.0"); } elseif($q=="http://www.imperialmetals.com/s/RSS.asp?MaxItems=10&Version=RSS2.0") { $xml=("http://www.imperialmetals.com/s/RSS.asp?MaxItems=10&Version=RSS2.0"); } elseif($q=="http://investorrelations.walterenergy.com/corporate.rss?c=71978&Rule=Cat=news~subcat=ALL") { $xml=("http://investorrelations.walterenergy.com/corporate.rss?c=71978&Rule=Cat=news~subcat=ALL"); } elseif($q=="http://www.teck.com/framework/comp.aspx?portalName=tc&id=133613&rss=1") { $xml=("http://www.teck.com/framework/comp.aspx?portalName=tc&id=133613&rss=1"); } elseif($q=="http://www.tasekomines.com/tko/RSS.asp?MaxItems=10&Version=RSS2.0") { $xml=("http://www.tasekomines.com/tko/RSS.asp?MaxItems=10&Version=RSS2.0"); } elseif($q=="http://www.rocamines.com/s/RSS.asp?MaxItems=10&Version=RSS2.0") { $xml=("http://www.rocamines.com/s/RSS.asp?MaxItems=10&Version=RSS2.0"); } elseif($q=="http://www.breakwater.ca/rss/pressrelease.aspx") { $xml=("http://www.breakwater.ca/rss/pressrelease.aspx"); } $xmlDoc = new DOMDocument(); $xmlDoc->load($xml); //get elements from "<channel>" $channel=$xmlDoc->getElementsByTagName('channel')->item(0); $channel_title = $channel->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $channel_link = $channel->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $channel_desc = $channel->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; //output elements from "<channel>" echo("<p><a href='" . $channel_link . "'>" . $channel_title . "</a>"); echo("<br />"); echo($channel_desc . "</p>"); //get and output "<item>" elements $x=$xmlDoc->getElementsByTagName('item'); for ($i=0; $i<=2; $i++) { $item_title=$x->item($i)->getElementsByTagName('title') ->item(0)->childNodes->item(0)->nodeValue; $item_link=$x->item($i)->getElementsByTagName('link') ->item(0)->childNodes->item(0)->nodeValue; $item_desc=$x->item($i)->getElementsByTagName('description') ->item(0)->childNodes->item(0)->nodeValue; echo ("<p><a href='" . $item_link . "'>" . $item_title . "</a>"); echo ("<br />"); echo ($item_desc . "</p>"); } ?> Thanks again for all your wonderful help and all the best to you and your families on this Easter weekend, Brian I am currently designing a table as such Code: ___________________________ | TABLE | | | FRAME A |___________________________| | last row clicked | FRAME B |___________________________| the top frame is a table and the bottom frame contains the last row clicked called through onclick. question: if frame B is a php file with a javascript object, how do i call the javascript object's function to print the data? here is what i have so far index.html //this is the source code for the site Code: <html> <frameset rows = "60%, 40%"> <frame src = "table_driver.php" name = "A" id = "FRAME1"> <frame src = "bottom_row.php" name = "B" id = "FRAME2"> </frameset> </html> printJSTable() //prints the table shown in frame A Code: function printJSTable() { echo '<script src = "java_script.js"></script>'; echo '<script src="sorttable.js"></script>'; echo '<table class = "sortable" id = "myTable" border = "1">'; echo '<thead id = "header"><tr>'; foreach($this->columns as $header => $order) { echo '<th>'; echo $header; echo '</th>'; } echo '</tr></thead><tbody>'; $counter = 0; for($i = 0; $i < $this->numRows; $i++) { //IMPORTANT changeRow(this) is JS call echo '<tr onclick = "changeRow(this)" onmouseover = "mouseOver(this)" onmouseout = "mouseOut(this)">'; foreach($this->data[$i] as $key => $value) { echo '<td>'; if($value!="") echo $value; else { echo ''; } $counter++; echo '</td>'; } echo '</tr>'; } echo '</tbody></table>'; echo '<form><input id = "'.$this->numRows.'"type = "button" value = "add row" onclick = "addRow(id)"></form>'; } and this is changeRow(this) which is supposed to create the table in frame b Code: //populates headersArr and rowArr correctly parent.B.obj = new TableData(headersArr, rowArr); parent.B.obj.printTable(); here are the function definitions for TableData Code: function TableData(headers, row) { this.headerArr = headers; this.rowArr = row; } TableData.prorotype.printTable = function() { for(i=0; i<this.headerArr.length; i++) { document.write('<tr><th>'); document.write(this.headerArr[i]); document.write('</th><td>'); document.write(this.rowArr[i]); document.write('</td></tr>'); } } and then, finally, this is the php file for the bottom frame Code: <html> <head> <link rel = "stylesheet" type = "text/css" href = "style.css"/> <script type = "text/javascript" src="java_script.js"></script> </head> <body> <script> obj = new TableData; </script> </body> </html> what i want to do is populate the variable obj from ^ (bottom_row.php) and then use the print function to print it out. right now it is populating correclt,y but i cant get it to print. The error console says that Value undefined (result of expression parent.B.obj.printTable) is not object. ?? sry for all the code! just didnt want to leave anything out thanks! Hi I've set up an html page that contains 3 buttons, which have a sprite rollover effect when hovered over. This is handled by css. When one of the buttons is clicked - a value is passed to an input field. This is handled by Javascript. Both of these functions work. What I would like to do is add a second function when a button is clicked - so that the hover sprite remains selected. Could anyone tell me how to do this please? Here is the button code I have: <button type="button" class="fantasy_button_blue_sprite" id="mcgyver" value="mcgyver" onclick="setHiddenControlValue('option1');">next</button> Here is the input field that gets populated: <input type="<?php echo $type;?>" id="fantasy_friend" name="fantasy_friend" value="<?php echo $fantasy_friend; ?>"> This is the javascript I'm using: <!-- // set the hidden form field when a button is clicked function setHiddenControlValue(selectedValue) { document.getElementById("fantasy_friend").value = selectedValue; parent.document.options_form.their_firstname.value=selectedValue; } And this is the sprite css: .fantasy_button_green_sprite { background: transparent url("/images/align_page/fantasy_button1.jpg") 0 1px no-repeat; height:61px; width:164px; border:none; text-indent:-99999px; cursor: pointer; margin-top:20px; } .fantasy_button_green_sprite:hover { background: transparent url("/images/align_page/fantasy_button1.jpg") 0 -61px no-repeat; } Thanks! Tom --> Hi, i was wondering if there was a way to call a nested javascript function directly, from outside of the function its nested in? for example, if i have the following functions: Code: <script type="text/javascript"> var test = function(){ var testInner = function(){ alert('testInner'); } } </script> can i then call the 'testInner' function directly from an onclick action something like this: Code: <a href="#" onclick="test.testInner()">TEST JS</a><br /><br /> That code is obviously not working for me, but is there something similar to what ive shown here that will work? Thanks in advanced Hello folks: I've got an html table populated by a php foreach routine. One field in this table is an Input type=checkbox. The goal is to run a javascript function when the user checks the checkbox. But, since the checkbox is in a table populated by a foreach routine, I'm having some problems. Below is the applicable code for my table: <?php foreach($results as $row) { $bk_owner = $row['BookOwner']; $addrss_owner = $row['AddressOwner']; $f_name = $row['FName']; $l_name = $row['LName']; $email = $row['EmailAddress']; $d_phone = $row['DeskPhone']; $ext = $row['Ext']; $cell = $row['CellPhone']; $title = $row['Title']; echo "<tr>"; echo "<td class='a'>".$l_name ."</td>"; echo "<td class ='a'>".$f_name ."</td>"; echo "<td class ='c'>".$email ."</td>"; echo "<td class ='a'>".$d_phone ."</td>"; echo "<td class='b'>".$ext."</td>"; echo "<td class='a'>".$cell."</td>"; echo "<td class='c'>".$title."</td>"; echo "<td class='b'><input type='checkbox' id='chk_Bx' value=". $addrss_owner. " onClick='selectFunction()'></input></td>"; echo "</tr>"; } echo"</tbody>"; ?> Specifically, note this line: echo "<td class='b'><input type='checkbox' id='chk_Bx' value=". $addrss_owner. " onClick='selectFunction()'></input></td>"; the value is set to $address_owner. This value is a primary key value and will allow me to run routines related to the record chosen when the checkbox is checked. Following is the javascript code for selectFunction(): function selectFunction(){ var check = document.getElementById("chk_Bx").checked; var val = document.getElementById("chk_Bx").value; alert(val); } At this point the javascript is very simple. All I'm trying to do is pick up applicable values for the record selected. But - I believe because the table is populated through a foreach loop, the javascript alert is returning the same primary key value for every record checked (or unchecked). Also, if I alert out check, it continually returns false, even if I've checked the box and it should read true. I am assuming this is also related to the foreach table presentation. How do I grab ONLY the primary key value, or checked true/false for the applicable record? Thanks in advance: Pavilion CHANGE XX to TT CHANGE zero in c0m to O becoming com CHANGE YYY to WWW hxxps://yyy.yousendit.c0m/download/dklxb2VIcVg1aWF4dnc9PQ first an example of what im trying to do: when logging in to a forum, you enter your info at the top right corner. thts where the login info txt boxes are usually located. under these you'll find a menu bar. if you're logged in, the menu commands/items arent the same as when you're not logged in. example of logged in is search. example of not being logged in is register. anyways under the menu there's the forum itself. u no, sections and topics. the table basically. this is wht im trying to do. even if im doing it wrong plz indulge me I know that ppl dont use frames much anymore. but just go with it. It DOES help to no how to do something in different ways. Ok, assuming you setup my pages, press submit. All 3 frames SHOULD go to 1.php BUT what happens is that the lower two frames go to 1.php. the first frame doesnt. It's the frame that has the form which has the button. If i put the button outside the form and press submit, it works. all 3 frames change. so i'm guessing it's got to do with the form itself. How do I fix it? Thank you!!!! |