JavaScript - Variable File Path Based On Date Variables...
Similar TutorialsI have a drop down menu where people can select a month, day and year. Based on their selection, I want to show them an image. If their selection is >= July 26, 2010 but <= July 25, 2011, show the red image; If their selection is >= July 26, 2011 but <= July 25, 2012, show the white image; If their selection is >= July 26, 2012 but <= July 25, 2013, show the blue image; If their selection is >= July 26, 2013 but <= July 25, 2014, show the yellow image; I don't know how to compare a selected date to a range of dates like this. Hi all, I have an .xsl file that reads an xml file and populates an html file and that is working well. I want to have many xml files (one per project) and one .xsl and html file. The goal would be to get the user to browse for the particular xml file they want to use and have the html file reference the path and file name. There will be a main page where the user will browse for the xml file in question. When they hit submit, the information (document path) is passed to the html file and the html file opens with information from the xml page they selected .In my html file I have the following: Code: xml.load(''12345.xml'') Basically I would like to somehow browse to the xml file in question and pass that variable (file path and name) to the html file and replace "1234.xml" with the path and name selected by the browse section. Does this make sense? Thanks. Reply With Quote 01-22-2015, 11:04 PM #2 Old Pedant View Profile View Forum Posts Supreme Master coder! Join Date Feb 2009 Posts 28,310 Thanks 82 Thanked 4,754 Times in 4,716 Posts The easiest way to do this would be via server-side code. For example, just have a PHP page the includes the desired ".xml" file into a page that is already setup with the XSLT. I vaguely recall reading that there is a way to "apply" XSLT to a dynamic set of XML, but the function named apply() in XSLT doesn't do anything like this. Still, the easiest way to control this would be via the server side code. Heck, that would even allow you to string together "pieces" of XML from various files to create the final document. I'm working on a site built through Squarespace, and I've run into some limitations. They've told me it's possible to build a Javascript to pull specific images from one page's journal entries and place them (with links to the entry) on other pages. Can somebody send me in the right direction on how I would do this? Basically I want to find a most recent posting tagged with a specific category, find the file file path of it's related image, and make that appear on the page that my javascript is on. Hi, I have a large e-commerce site that runs on a database. There are many products on the site which have 'variables' attached to them, e.g. colour, width, height etc. I have a script in place to sort the products depending on these variables. Apologies for the length of the code. Code: (function(i) {var u =navigator.userAgent;var e=/*@cc_on!@*/false; var st = setTimeout;if(/webkit/i.test(u)){st(function(){var dr=document.readyState; if(dr=="loaded"||dr=="complete"){i()}else{st(arguments.callee,10);}},10);} else if((/mozilla/i.test(u)&&!/(compati)/.test(u)) || (/opera/i.test(u))){ document.addEventListener("DOMContentLoaded",i,false); } else if(e){ ( function(){var t=document.createElement('doc:rdy');try{t.doScroll('left'); i();t=null;}catch(e){st(arguments.callee,0);}})();}})(sortinit); var prodlines = new Array(); // for Products var spanids = new Array(); var lastsorttype = 'default'; var bReadyToSort = false; var searchlines = new Array(); // for Search Results var searchspanids = new Array(); var searchlastsorttype = 'default'; var bSearchReadyToSort = false; var sectlines = new Array(); // for Sections var sectspanids = new Array(); var sectlastsorttype = 'default'; var bSectReadyToSort = false; var bSortInitalised = false; // Search Results Related function searchreseq(seqtype){ // resequence search results if ( ! (bSearchReadyToSort || bPageIsLoaded) ) { alert('Please wait until the page has fully loaded. (SRC)'); return false; } searchlines.length = 0; searchspanids.length = 0; var spans = document.getElementsByTagName('span'); for ( var i=0; i<spans.length; i++ ) { if ( spans[i].id.indexOf('searchsortline_') == 0 ) { searchspanids.push(spans[i]); searchlines.push({ id: spans[i].id, price: spans[i].getAttribute('price').replace(/[^\d\.]/g,''), seq: spans[i].getAttribute('seq'), pname: spans[i].getAttribute('pname'), phtml: spans[i].innerHTML }); } } if ( seqtype == 'lowhigh' ) searchlines.sort(function(a,b){return a.price - b.price}); if ( seqtype == 'highlow' ) searchlines.sort(function(a,b){return b.price - a.price}); if ( seqtype == 'default' ) searchlines.sort(function(a,b){return a.seq - b.seq}); if ( seqtype == 'alpha' ) searchlines.sort(function(a,b){return (a.pname <= b.pname) ? -1 : 1;}); if ( seqtype == 'reverse' ) searchlines.sort(function(a,b){return (b.pname <= a.pname) ? -1 : 1;}); searchlastsorttype = seqtype; setCookie('SEARCHSORTTYPE', searchlastsorttype); searchshowsorttype(); for ( var i=0; i<searchlines.length; i++ ) { searchspanids[i].innerHTML = searchlines[i].phtml; searchspanids[i].id = searchlines[i].id; searchspanids[i].setAttribute('price', searchlines[i].price); searchspanids[i].setAttribute('seq', searchlines[i].seq); searchspanids[i].setAttribute('pname', searchlines[i].pname); } return false; } function searchshowsorttype(){ // highlight the type of sort that's currently in use if ( document.getElementById('searchsortdropdown') ) // see if we're using drop-downs { var dropdowns = document.getElementsByTagName('select'); // all drop-downs for ( var i=0; i<dropdowns.length; i++ ) { if ( dropdowns[i].name == 'searchsortdropdown' ) // relevant one { var sdd = dropdowns[i]; for ( var j=0; j<sdd.options.length; j++ ) { if ( sdd.options[j].value == searchlastsorttype ) sdd.selectedIndex = j; } } } } else { var buttonlinks = document.getElementsByTagName('input'); // looking for buttons for ( var i=0; i<buttonlinks.length; i++ ) { if ( buttonlinks[i].name == 'searchsortlink' ) { buttonlinks[i].className = ( buttonlinks[i].id == searchlastsorttype ) ? 'searchsortactive' : 'searchsortinactive'; } } var buttonlinks = document.getElementsByTagName('a'); // looking for A tags for ( var i=0; i<buttonlinks.length; i++ ) { if ( buttonlinks[i].name == 'searchsortlink' ) { buttonlinks[i].className = ( buttonlinks[i].id == searchlastsorttype ) ? 'searchsortactive' : 'searchsortinactive'; } } } } // Section Related function sectionseq(seqtype){ // resequence Sections if ( ! (bSectReadyToSort || bPageIsLoaded) ) { alert('Please wait until the page has fully loaded. (SECT)'); return false; } sectlines.length = 0; sectspanids.length = 0; var spans = document.getElementsByTagName('span'); for ( var i=0; i<spans.length; i++ ) { if ( spans[i].id.indexOf('sectionline_') == 0 ) { sectspanids.push(spans[i]); sectlines.push({ id: spans[i].id, price: spans[i].getAttribute('price'), seq: spans[i].getAttribute('seq'), pname: spans[i].getAttribute('pname'), phtml: spans[i].innerHTML }); } } if ( seqtype == 'lowhigh' ) sectlines.sort(function(a,b){return a.price - b.price}); if ( seqtype == 'highlow' ) sectlines.sort(function(a,b){return b.price - a.price}); if ( seqtype == 'default' ) sectlines.sort(function(a,b){return a.seq - b.seq}); if ( seqtype == 'alpha' ) sectlines.sort(function(a,b){return (a.pname <= b.pname) ? -1 : 1;}); if ( seqtype == 'reverse' ) sectlines.sort(function(a,b){return (b.pname <= a.pname) ? -1 : 1;}); sectlastsorttype = seqtype; setCookie('SECTSORTTYPE', sectlastsorttype); sectshowsorttype(); for ( var i=0; i<sectlines.length; i++ ) { sectspanids[i].innerHTML = sectlines[i].phtml; sectspanids[i].id = sectlines[i].id; sectspanids[i].setAttribute('price', sectlines[i].price); sectspanids[i].setAttribute('seq', sectlines[i].seq); sectspanids[i].setAttribute('pname', sectlines[i].pname); } return false; } function sectshowsorttype(){ // highlight the type of sort that's currently in use if ( document.getElementById('sectionsortdropdown') ) // see if we're using drop-downs { var dropdowns = document.getElementsByTagName('select'); // all drop-downs for ( var i=0; i<dropdowns.length; i++ ) { if ( dropdowns[i].name == 'sectionsortdropdown' ) // relevant one { var sdd = dropdowns[i]; for ( var j=0; j<sdd.options.length; j++ ) { if ( sdd.options[j].value == sectlastsorttype ) sdd.selectedIndex = j; } } } } else { var buttonlinks = document.getElementsByTagName('input'); // looking for buttons for ( var i=0; i<buttonlinks.length; i++ ) { if ( buttonlinks[i].name == 'sectsortlink' ) { buttonlinks[i].className = ( buttonlinks[i].id == sectlastsorttype ) ? 'sectsortactive' : 'sectsortinactive'; } } var buttonlinks = document.getElementsByTagName('a'); // looking for A tags for ( var i=0; i<buttonlinks.length; i++ ) { if ( buttonlinks[i].name == 'sectsortlink' ) { buttonlinks[i].className = ( buttonlinks[i].id == sectlastsorttype ) ? 'sectsortactive' : 'sectsortinactive'; } } } } // Product Related function reseq(seqtype, gotoanchor){ // resequence products if ( ! (bReadyToSort || bPageIsLoaded) ) { alert('Please wait until the page has fully loaded. (PROD)'); return false; } prodlines.length = 0; spanids.length = 0; var spans = document.getElementsByTagName('span'); for ( var i=0; i<spans.length; i++ ) { if ( spans[i].id.indexOf('sortline_') == 0 ) { spanids.push(spans[i]); prodlines.push({ id: spans[i].id, price: spans[i].getAttribute('price'), seq: spans[i].getAttribute('seq'), pname: spans[i].getAttribute('pname'), brand: spans[i].getAttribute('brand'), capacity: spans[i].getAttribute('capacity'), height: spans[i].getAttribute('height'), width: spans[i].getAttribute('width'), depth: spans[i].getAttribute('depth'), colour: spans[i].getAttribute('colour'), energyrating: spans[i].getAttribute('energyrating'), spinspeed: spans[i].getAttribute('spinspeed'), phtml: spans[i].innerHTML }); } } if ( seqtype == 'lowhigh' ) prodlines.sort(function(a,b){return a.price - b.price}); if ( seqtype == 'highlow' ) prodlines.sort(function(a,b){return b.price - a.price}); if ( seqtype == 'default' ) prodlines.sort(function(a,b){return a.seq - b.seq}); if ( seqtype == 'alpha' ) prodlines.sort(function(a,b){return (a.pname <= b.pname) ? -1 : 1;}); if ( seqtype == 'reverse' ) prodlines.sort(function(a,b){return (b.pname <= a.pname) ? -1 : 1;}); if ( seqtype == 'brand' ) prodlines.sort(function(a,b){return (a.brand <= b.brand) ? -1 : 1;}); if ( seqtype == 'capacity' ) prodlines.sort(function(a,b){return (b.capacity <= a.capacity) ? -1 : 1;}); if ( seqtype == 'height' ) prodlines.sort(function(a,b){return (a.height <= b.height) ? -1 : 1;}); if ( seqtype == 'width' ) prodlines.sort(function(a,b){return (a.width <= b.width) ? -1 : 1;}); if ( seqtype == 'depth' ) prodlines.sort(function(a,b){return (a.depth <= b.depth) ? -1 : 1;}); if ( seqtype == 'colour' ) prodlines.sort(function(a,b){return (a.colour <= b.colour) ? -1 : 1;}); if ( seqtype == 'energyrating' ) prodlines.sort(function(a,b){return (a.energyrating <= b.energyrating) ? -1 : 1;}); if ( seqtype == 'spinspeed' ) prodlines.sort(function(a,b){return (b.spinspeed <= a.spinspeed) ? -1 : 1;}); lastsorttype = seqtype; setCookie('SORTTYPE', lastsorttype); showsorttype(); for ( var i=0; i<prodlines.length; i++ ) { spanids[i].innerHTML = prodlines[i].phtml; spanids[i].id = prodlines[i].id; spanids[i].setAttribute('price', prodlines[i].price); spanids[i].setAttribute('seq', prodlines[i].seq); spanids[i].setAttribute('pname', prodlines[i].pname); spanids[i].setAttribute('brand', prodlines[i].brand); spanids[i].setAttribute('capacity', prodlines[i].capacity); spanids[i].setAttribute('height', prodlines[i].height); spanids[i].setAttribute('width', prodlines[i].width); spanids[i].setAttribute('depth', prodlines[i].depth); spanids[i].setAttribute('colour', prodlines[i].colour); spanids[i].setAttribute('energyrating', prodlines[i].energyrating); spanids[i].setAttribute('spinspeed', prodlines[i].spinspeed); } if ( gotoanchor && location.hash ) scrolltoanchor(location.hash); // Product Page just loaded and Anchor so we need to reposition // // Some Drillpine add-ons need reactivated after the DOM has been fiddled with // // Tabber (needs V210 onwards) - reset Tabber if ( window.resetallpanes ) resetallpanes(); // Tabber V3 if ( window.jqinittabber ) jqinittabber(); // Lightbox / Slimbox if ( window.Slimbox && window.Slimbox.scanPage ) Slimbox.scanPage(); // Lightbox / Slimbox2 if ( (typeof(jQuery) == 'function') && (typeof(jQuery.slimbox) == 'function') ) { $("a[rel^='lightbox']").slimbox({/* Put custom options here */}, null, function(el) { return (this == el) || ((this.rel.length > 8) && (this.rel == el.rel)); }); } return false; } function showsorttype(){ // highlight the type of sort that's currently in use if ( document.getElementById('sortdropdown') ) // see if we're using drop-downs { var dropdowns = document.getElementsByTagName('select'); // all drop-downs for ( var i=0; i<dropdowns.length; i++ ) { if ( dropdowns[i].name == 'sortdropdown' ) // relevant one { var sdd = dropdowns[i]; for ( var j=0; j<sdd.options.length; j++ ) { if ( sdd.options[j].value == lastsorttype ) sdd.selectedIndex = j; } } } } else { var buttonlinks = document.getElementsByTagName('input'); // looking for buttons for ( var i=0; i<buttonlinks.length; i++ ) { if ( buttonlinks[i].name == 'sortlink' ) { buttonlinks[i].className = ( buttonlinks[i].id == lastsorttype ) ? 'sortactive' : 'sortinactive'; } } var buttonlinks = document.getElementsByTagName('a'); // looking for A tags for ( var i=0; i<buttonlinks.length; i++ ) { if ( buttonlinks[i].name == 'sortlink' ) { buttonlinks[i].className = ( buttonlinks[i].id == lastsorttype ) ? 'sortactive' : 'sortinactive'; } } } } // General code function hidetagswithid(tag, id){ // hide all tags with ID var alltags = document.getElementsByTagName(tag); // all such tags for ( var i=0; i<alltags.length; i++ ) { if ( alltags[i].id == id ) // with ID { alltags[i].style.display = 'none'; // hide entire control alltags[i].style.visibility = 'hidden'; // hide entire control } } } function scrolltoanchor(anc){ // reposition to display anchor var ancs = document.getElementsByTagName('a'); anc = anc.replace(/.*\#/,''); // Search highlight passes duplicate anchors - lose one if ( ancs[anc] ) ancs[anc].scrollIntoView(true); } function sortinit(){ // called when DOM is loaded if (arguments.callee.done) return; arguments.callee.done = true; bSortInitialised = true; // Products if ( document.getElementById('sortwidget') ) { bReadyToSort = true; lastsorttype = getCookie('SORTTYPE'); if ( lastsorttype == null ) lastsorttype = 'default'; setCookie('SORTTYPE', lastsorttype); showsorttype(); if ( lastsorttype != 'default' ) { reseq(lastsorttype, true); } } // Search Results if ( document.getElementById('searchsortwidget') ) { bSearchReadyToSort = true; searchlastsorttype = getCookie('SEARCHSORTTYPE'); if ( searchlastsorttype == null ) searchlastsorttype = 'default'; setCookie('SEARCHSORTTYPE', searchlastsorttype); searchshowsorttype(); if ( searchlastsorttype != 'default' ) { searchreseq(searchlastsorttype); } } // Sections if ( document.getElementById('sectsortwidget') ) { // check for no prices available and hide buttons if so var spans = document.getElementsByTagName('span'); var rtot = 0; for ( var i=0; i<spans.length; i++ ) { if ( spans[i].id.indexOf('sectionline_') == 0 ) { var price = spans[i].getAttribute('price'); rtot += (price != null) ? price - 0 : 0; } } if ( rtot == 0 ) { if ( SectionSortLinksFinalOnly ) // do we only show links on final Sections { hidetagswithid('span', 'sectsortwidget'); // hide all sort widgets } else { if ( document.getElementById('sectpricelinks') ) // button or text links { hidetagswithid('span', 'sectpricelinks'); } if ( document.getElementById('sectionsortdropdown') ) // drop-down list { var dropdowns = document.getElementsByTagName('select'); // all drop-downs for ( var i=0; i<dropdowns.length; i++ ) { if ( dropdowns[i].id == 'sectionsortdropdown' ) // relevant one { var opts = dropdowns[i].options; for ( var j=opts.length; j>0; j-- ) // scan backwards as we're deleting items { if ( (opts[j - 1].value == "lowhigh") || (opts[j - 1].value == "highlow") ) { opts[j - 1] = null; } } } } } } } bSectReadyToSort = true; sectlastsorttype = getCookie('SECTSORTTYPE'); if ( sectlastsorttype == null ) sectlastsorttype = 'default'; setCookie('SECTSORTTYPE', sectlastsorttype); sectshowsorttype(); // only resequence if button showing and we've a non default sequence if ( (document.getElementById('sectsortwidget').style.display != 'none') && (sectlastsorttype != 'default') ) { sectionseq(sectlastsorttype); } } } function onloadsortinit(){ // optionally called on onload if ( ! bSortInitalised ) sortinit(); // only init if it's not already run } // in case we cannot activate on DOM loaded if (window.attachEvent) // IE { window.attachEvent("onload", onloadsortinit); } else // DOM { window.addEventListener("load", onloadsortinit, false); } I didn't write this script and I'm not a JavaScript expert, so i don't know how to edit it properly. I want to change it's function from sorting to filtering, i.e. something along the lines of a slice function. Any advice would be much appreciated. Javascript novice here looking to create a dynamic dropdown based on date. It's a list of preset prices that will change each month to reflect a pro-rated system. Any thoughts/examples on how I would go about setting this up using javascript would be much appreciated. Thanks. Here's what I need: In September, the dropdown will display these prices Code: <option value="100">Product 1</option> <option value="150">Product 2</option> <option value="200">Product 3</option> In October, the dropdown will display these prices <option value="50">Product 1</option> <option value="100">Product 2</option> <option value="150">Product 3</option> I have this script that I got from some site. When you click on a link tied to a div it hides all other divs and displays just that one. Well, that works, but I want it to display one of the divs on page load based on today's date. For example, it will display the "summer" div if today's date is anywhere between June 1 and August 31. When links to other divs are clicked that div will disappear and other ones will appear in its place. Anyway, here's the code, and I don't know anything about javascript so I have no idea where to even start editing it. Please help Code: <script type="text/javascript"> <!-- Layer Show/Hide Script last="" function changeDiv(the_div,the_change) { var the_style = getStyleObject(the_div); if (the_style != false) { the_style.display = "block" if(last!="") { last.display = "none" } } last=the_style } function getStyleObject(objectId) { if (document.getElementById && document.getElementById(objectId)) { return document.getElementById(objectId).style; } else if (document.all && document.all(objectId)) { return document.all(objectId).style; } else { return false; } } //--> </script> Hello all. I have created a 2 frame site where I want the top frame (header) to redirect the other frame (main) to a different page depending on the date, time, and second. For example, on 12 FEB at 07:00:00, I would like the header frame to redirect the main frames page to EmmasBday.html; in which I would be alerted of my little sisters Birthday. This is for personal use and isn't going to be hosted online so I will just use JavaScript, it's basically a simple system to remind me of crucial events at certain times and dates so I don't forget them. The same events will apply every year, so there is no need to programme in specific years although having the option could prove useful. I am aware of other alternatives to achieve this, but would very much like to work with JavaScript; as I can expand it. As I state, this is for personal use and therefore won't be hosting it; I will use JavaScript throughout and cannot use anything else like PHP, Perl, etc. I am aware JavaScript takes the time & date from the computer hosting it (unlike PHP), which is fine. So, for example; at 14:30:00 I will be informed to get dinner; and at 15:00:45 I'll be informed to study. The knowledge you guys have presented so far is phenomenal, and I couldn't think of anybody better to ask for assistance. Anyway, I hope you can resolve my problem and I'm looking forward to a response! Thanks for your concern, you brain Gods you! AHa. Hi guys. I am kind of new to javascript, and was hoping that someone here could help out on a problem I have been having. What I am trying to do is to make a page which will redirect to three diffrent sites, based on date. I want it to change to diffrent sites during the time before summer to summer, the time before xmas till xmas and from before easter till easter. A bit more spesific this would be: From 29. march --> 22. july (summer) From 22. august --> 24. december (xmas) From 3. january --> 22. march (easter) Could you help me out? I have tried lots of diffrent ways to do this with javascripts if...else statements, but I havent yet found a way to make it work properly. Really thankful for answers! I'm new to coding and recently undertook the position as my school district's webmaster. We use a six day schedule where the days are labeled A-F. I want to be able to display the Today is...A graphic based on the date. I tried some scripts from other forums, but it does not appear to be working. Any suggestions? TY <code> <script language="javascript"> <!-- var picture=''; mytime=new Date(); mymonth=mytime.getMonth()+1; mydate=mytime.getDate(); if (mymonth==9 && mydate==13){picture="<img src=/images/d.gif>"; } if (mymonth==9 && mydate==14){picture="<img src=/images/e.gif width=150 height=150 alt=E>"; } if (mymonth==9 && mydate==15){picture="<img src=/images/f.gif width=150 height=150 alt=F>"; } if (mymonth==9 && mydate==16){picture="<img src=/images/A.gif width=150 height=150 alt=A>"; } if (mymonth==9 && mydate==19){picture="<img src=/images/B.gif width=150 height=150 alt=B>"; } if (mymonth==9 && mydate==20){picture="<img src=/images/c.gif width=150 height=150 alt=C>"; } //--> </script></code> Hello, I've been trying to figure this script out for awhile and I've hit a wall. Basically, what I want to do for my organization's website is to use JS to display an image containing our hours and have it change each day of the week. The hard part (for me) is that there are certain days we're closed. Ideally, I'd like a separate "We're Closed" message to overwrite the image carrying our hours on specific days (major holidays like Xmas, New Years, Vet's Day, furlough periods, etc. etc.). Here's the code I've managed to cobble together (I have a real basic understanding of JS, so I've been pulling scripts from sites offering free copy/pastecode): [CODE] <script language="javascript"> mytime=new Date(); mymonth=mytime.getMonth()+1; mydate=mytime.getDate(); myday=mytime.getDay(); arday = new Array("sunday.png", "monday.png", "tuesday.png", "wednesday.png", "thursday.png", "friday.png", "saturday.png"); document.write("<img src='" + arday[myday] + "'>"); if (mymonth==12 && mydate==24){document.write("<img src='closure.png'>"); } </script> [CODE] For the most part, this code works just fine. However, if I jump my system clock to December 24, the "closure.png" comes up appears ALONGSIDE the hours image for that day of the week. In other words, I've got two images appearing right next to each other - that's not what I want. How can I work the code in such a way that when a closure date comes up (in this case, 12/24), just the "closure.png" image shows up by itself? Thank you all so much for your time and patience. Hi All, I have a form that captures member registration details. In the admin section .. I would like to change the Status field of a record/s from NEW to PAYMENT DUE after 14 days from the data of submission. The status change should automatically trigger on the 15th day. So when the admin checks the list page he/she should be able to view the updated status field. Any pointers how to accomplish this? Thanks in advance. Vinny Can anyone tell me how I can check to see if a checkbox has actually been checked or not? The code I need to use this in basically gets data from a form which has alot of dropdowns and a checkbox in it. The function builds a query based on the values it finds in these variables. I was trying to check to see if the checkbox was selected and if so assign a value to another var but I can't seem to get it to work. Any ideas? The checkbox is called pics. if (pics.checked) { var photos = "Yes"; } else { var photos = "No"; } if (pics.checked == 1) { var photos = "Yes"; } else { var photos = "No"; } Any help much appreciated. Hi, I haven't used variable variables before and I'm still trying to get my head around it. I think I'm going OK but I have run into a fairly obscure little problem that I thought I'd throw out there to see if anyone has any ideas... The plan: to make a distance calculator that measures a line made by clicking on a google map. Overall distance is shown at the side, but segment length is shown in tooltip-like labels called Elabels. Segments can get dragged and segment length is updated as dragging occurs. Being that the number of segments (and labels) depends on the number of user clicks, I thought it would be a good idea to use the variable variable to keep all the references unique. If there's a better way to do this, I'd love to hear about it. The problem: it all works fine, except that, if you consider that dragging a point on a line changes two line lengths (let's say A is the start, B is the drag point and C is the end), only one length is updating - the A to B section. What I want is for the Elabel at C to reflect the change in the B to C line length as well. Anyway. Here's the page I'm working on. The relevant code is below. I've tried duplicating it and adding +1 to the variables (and every permutation thereof) but no dice. All I need really is for exactly what's happening now to be happening in the next Elabel along in the array. Any suggestions much appreciated. Code: function leftClick(overlay, point) { count++; var mar1= count-2; var mar2= count-1; var mar3= count; var mar4= count+1; window["label" + mar2]=new ELabel(point, dist ,"labelstyle",new GSize(10,10)); labels2.push(window["label" + mar2]); map.addOverlay(window["label" + mar2]); // Drag listener GEvent.addListener(marker, "drag", function() { drawOverlay(); window["marker" + mar2]=markers[mar1]; window["marker" + mar3]=markers[mar2]; window["marker" + mar4]=markers[mar3]; line = [window["marker" + mar2].getPoint(),window["marker" + mar3].getPoint()]; dist2=window["marker" + mar2].getPoint().distanceFrom(window["marker" + mar3].getPoint()); dist2="Segment<br> length:<br>"+dist2.toFixed(0)+"m"; if(parseInt(dist2)>10000){dist2=(parseInt(dist2)/1000).toFixed(1)+"km";} window["label" + mar2].setPoint(marker.getPoint()); window["label" + mar2].setContents(dist2); } Hi, in PHP I can assign a variable do... PHP Code: function setvar($anyvar,$val){ $$anyvar=$val; } setval('myvar',$whatever); how to do in javascript ... I thied window.anyvar= and this[anyvar] and several other combinations but no joy Edit: fixed, my bad, was being a muppet, was calling setvar(varname,val) instead of setvar('varname',val); Ok I am very very new to java to the point where I only know how to use pre-made javascripts in my php code so be gentle. First, here is part of a form I have: Code: <select name = "pulmonologist" > <option selected="" value="">---Select--- <option value="none">None</option> <?php while ($row2 = mysql_fetch_assoc ($results2)) { ?><option value = "<?php echo $row2['staff_name'];?>"><?php echo $row2['staff_name'];?></option> <?php } ?> </select> Ok now I want to echo the value that the user selects on the SAME page (i.e. before the submit button is pressed) (so I can't do it with php, I need javascript) like this: Code: <input type="submit" value = "Contact <?php echo $pulmonologist;?>" /> Can you tell me how to do this? Thanks! Codes for Dropdown menu based on radio buttons selection needed!? I need urgent help with this: I need codes for a dropdown menu that is altered by radio buttons. I want to insert the value selected from the dropdown menu into a table. 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 Very new to javascript, so I apologize in advance. I honestly tried to figure this out on my own, and I'm just not able. I'm trying to create a family tree online that has several other related family charts. I want each person's name and birth year to be stored in javascript variables, then I want to be able to just go through the tree, and put the persons name once, and have it put the appropriate name and birthyear in the little boxes that the css is creating. In the js file... I would do this for each family member. Code: var johnname = "John Smith"; var johnbirthyear = "Jan 1 1930"; var janename = "Jane Doe"; var janebirthyear = "Jan 1 1940"; var mikename = "mike wilson"; var mikebirthyear = "Jan 1 1950"; var saraname = "sara johnston"; var sarabirthyear = "Jan 1 1960"; In the HTML file... Code: <div id = "boybox"> <script type="text/javascript"> id = "john"; <!-- this is the only thing I want to have to change --> name = id+"name"; document.write(name); </script> <div id = "year"> <script type="text/javascript"> birthyear = id+"year"; document.write(birthyear); </script> </div> </div> So I thought I had it all figured out. I thought that the above would take the id of John that I added, go to the line that sets the name, add john to the word name, and then document write the variable of johnname from the js file. I know you're laughing at me because of course it instead made the value of name to johnname, then wrote the word johnname in the box. Can anyone point me in the right direction please? ultimately I want to go through and be able to just type the persons name in the html for that box once, and have it update with their appropriate info. Thanks, and sorry for such a rookie question. |