JavaScript - Div Attribute Controlling Js
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 Similar TutorialsHi, I have a few checkboxes in a form. Some of them work independently, but some make the others go on and off. Specifically the lower ones are controlling the upper ones. Can anyone explain why please? Code: <td> <input type="checkbox" name="weddingitem1" value="Toppers" id="Toppers"/><label for="Toppers" >Toppers<br /> <input type="checkbox" name="weddingitem2" value="Champers" id="Champers"/><label for="Champers" >Champers<br /> </td> Hi, Im trying to change the position of a div when a button is clicked. The js is: Code: function curPos() { objDivStrip = document.getElementById('thumbview'); return objDivStrip.style.top; } function up(pos) { //get objects objImgStrip = document.getElementById('str'); objDivStrip = document.getElementById('thumbview'); //Get End position var totImg = (objImgStrip.height - 100) / 130; var endpos = totImg * 130; if (pos=endpos) { return false; } else { objDivStrip.style.top = pos - 130; } } and the html on the button is Code: <img id="arrow" src="images/arrow_up.jpg" onclick="up(curPos());" /> The code doesnt work but if anyone could point me in the direction to get it to work your help is greatly appreciated. Cheers Sol hi everybody; i'm using this code to trigger functions with left and right arrow keys.. but they work even if the arrow keys pressed in input boxes.. is there any way to prevent this code to work when user presses the arrow keys in input boxes? Code: document.onkeydown = function(evt) { evt = evt || window.event; switch (evt.keyCode) { case 37: geri(); gostergeyaz(); break; case 39: ileri(); gostergeyaz(); break; } }; Hello, I need your help. I have 2 checkboxes. How would I control one from the other? Eg. [ ] Option A [ ] Option B - If Option A was checked first and, I put a checkmark in option B then Uncheck Option A and leave option B checked. - If Option B was checked and, I put a check mark in Option A then uncheck Option B and leave Option A checked. How would that be written in Javascript, I am totally confused. Any help with this is much and foremost greatly appreciated. Cheers, J I am trying to use JavaScript to manipulate the appearance of a web browser. (1) Initially I need to identify and save the current browser settings (e.g. position, height, width, caption on or off, menubar on or off, border on or off). (2) Then I need to change the appearance of the browser to full screen, no border, no caption, no status bar, no menubar). (3) Finally, I need to return the browser to the initial settings using the settings saved at the beginning. I am a novice at JavaScript and am having a difficult time locating details of the language that permit me to accomplish my objectives. John Chapman jchapman@onlinecbt.com I have the following code ... Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="language" content="english"> <meta http-equiv="Content-Style-Type" content="text/css"> <title></title> <style type="text/css"> body { background-color:#000; } #scenery { width:964px; height:482px; padding:318px 0 0 316px; margin:auto; background-image:url('http://www.deshow.net/d/file/travel/2009-10/new-zealand-scenery-738-20.jpg'); } </style> </head> <body> <div id="scenery"> <img src="http://cdn3.iconfinder.com/data/icons/softwaredemo/PNG/128x128/DrawingPin1_Blue.png" alt=""> </div> </body> </html> ... in which I would like to use Javascript to control the values in the 'padding'. Code: padding:318px 0 0 316px; May I know how can I use Javascript to control that 'padding' values? Appreciate any help. Problem I have an index.html that sets up 3 Frames. They are called FrameTop, FrameA and FrameB. See pic below. In FrameTop the user can type in a url into a textbox with id="urlINPUT". When user clicks LOADA it loads that url into FrameA. User can then browse web in FrameA, clicking links etc and going to new pages. The second button LOADB is designed to determine the current location/url of the page displayed in FrameA and load that into FrameB. So far when I write the javascript in FrameTop LOADA works but LOADB loads the FrameTop into FrameB! [error!] If someone can please help me with this problem it would be much appreciated. This work is going towards a free website idea. I suspect my error lies in use of parent/self in the parent.frame.location. Here is my page layout. -----------------Index.html------------------------------------- <frameset rows="5%,*"> <frame name="FrameTop" src="frame_top.html" /> <frameset cols="50%,50%"> <frame name="FrameA" id="FrameA" src="frame_a.html" /> <frame name="FrameB" id="FrameB" src="frame_b.html" /> <noframes> </noframes> </frameset> --------------------frame_top.html------------------------------- <SCRIPT language="JavaScript"> function loadURLintoA() /*gets the url typed in by user and loads it into Frame A. This works fine*/ { var urlrequest= "http://"+document.getElementById('urlINPUT').value; parent.FrameA.location.href = urlrequest; /*sets FrameA location to url that user enters in frametop input*/ } </SCRIPT> <SCRIPT language="JavaScript"> function loadAintoB() /*I WANT this to get the url of the website loaded in frame A and load it into frame B*/ { var urlofA = parent.FrameA.location; parent.FrameB.location = urlofA; /*this is supposed to get the url of FrameA and load it into FrameB*/ } </SCRIPT> </HEAD> <body bgcolor="#848484"> http://<input type="text" name="urlINPUT" value="" id="urlINPUT" size="10"> <input type="button" name="loadAbutton" id="loadAbutton" value="LOAD A" onclick="loadURLintoA()"> <input type="button" name="loadBbutton" id="loadBbutton" value="LOAD B" onclick="loadAintoB()"> ---------------------------------------------- What happens when I run index.html index.html loads the index correctly and displays FrameTop, FrameA and FrameB. The load A button also works correctly BUT when I click LoadB it loads FrameTop into FrameB! This happens when no page is loaded into FrameA AND when an external page in loaded in. Please help, I would be very greatfull if you could point out my mistake. Good day/evening. I am trying to reload the contents of a div asynchronously using jquery. It works fine if the link/button to do so is outside of the div I am reloading, but I need the button to be inside the div I am reloading and it does not work if I do it from there. I have thought about overlaying divs but I need the buttons to be very exactly positioned as its a graphical representation of a map and recoding the way the buttons are placed would not only annoy me but be very difficult. You see its an isometric view of a square, and the buttons need to be placed right along the edges of the 'diamond' therefore always coming inside or on top of the div that contains the map view. So, is what I am trying to do impossible or might I just be going about it the wrong way ? If it is the latter then I will post some code. Thanks in advance. EDIT: sorry, I didn't see the frameworks forum for Jquery stuff, if a mod could please move this thread in there then that would be just fab. I am trying to do a custom add to cart to use with paypal and need to utilize javascript to achieve inserting some code or a weight value per the paypal forms' options choice. Here is my dilemma, All of my items have multiple weights, for instance the below example called Aqua Max 100 comes in .5lbs, 1.5lbs., 10lbs., 20lbs., and 50lbs. Paypal allows you to enter weight but it's one weight per item and I would have to create 5 Paypal buttons just for this one item to calculate the different weights per zip code. I need help making javascript insert the following code within the paypal forms' code upon option select before clicking submit? <input type="hidden" name="weight" value=".5"> <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="1.5"> <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="10 <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="20 <input type="hidden" name="weight_unit" value="lbs"> <input type="hidden" name="weight" value="50 <input type="hidden" name="weight_unit" value="lbs"> The code I came up with is wrong as I'm getting an error but I was originally trying to make it enter a weight using a hidden fillable number and without any real javascript training, just alot of googling but I think I'm pretty close. Please take a look at the code I've came up with so far and maybe point me in the correct direction: <html> <body> <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="business" value="test@test.com"> <input type="hidden" name="currency_code" value="USD"> <input type='hidden'text' name='amt' id='amt' value="0.00"/> <table> <tr> <td> <input type="text" name="on0" value="Aqua Max 100">Aqua Max 100</td></tr> <tr><td> <select name="os0" onChange="getamt()"> <option value="select">Please Select</option> <option value="1/2 lb.">1/2 lb. $3.99 USD</option> <option value="1 - 1/2 lbs">1 - 1/2 lbs $7.59 USD</option> <option value="10 lbs.">10 lbs. $25.80 USD</option> <option value="20 lbs.">20 lbs. $42.75 USD</option> <option value="50 lbs.">50 lbs. $86.20 USD</option> </select></td></tr> </table> <script type="text/javascript"> function getamt() { var sh=0; var choice = document.getElementById("os0").selectedIndex; if (choice == 0) { sh=0; } if (choice == 1) { sh=.5; } if (choice == 2) { sh=1.5; } if (choice == 3) { sh=10; } if (choice == 4) { sh=20 } if (choice == 5) { sh=50.00; } document.getElementById("on0").value=sh; } </script> <input type="image" src="https://images.paypal.com/images/sc-but-03.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" /> <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1"> </form> </body> </html> 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, 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 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 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()". Hello all, First time back here in a while, but I'm trying to get proficient in JS. I want to make my input element reset its value attribute to blank, which is originally set to "your e-mail". You know the effect you see on forms that have text in them, then with the onclick attribute, you can clear the text in the box. So, after looking around trying to find out what to do, here's what I've attempted. HTML Code: <form id="emailbox" name="form1" method="post" action=""> <div> <input type="text" name="go" id="go" value="your e-mail" onclick="removeText()"/> <input type="submit" value="Join" /> </div> </form> JS: Code: <script type="text/javascript"> function removeText(){ var form = document.getElementById['emailbox']; var name = form.elements['go'].value; } </script> What do I do next to complete my objective? 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? 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! 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/ 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;; Hello! I have a superclass where I create a "div" element as a property and then proceed to try and set the element's "id" attribute in a subclass. Interestingly, if I create multiple instances of the subclass with different "id"s, they all end up having the last "id" I specify. I would like it if they retain the individual "id" I specify. Here is the code. Code: function Drag() { this.ele = document.createElement("div"); } function Icon(id) { this.ele.id = id; } Icon.prototype = new Drag(); var hello = new Icon("hello"); var goodbye = new Icon("goodbye"); |