JavaScript - Javascript Filtering Help
Hi ,
I need a javascript help for the following snippet of html code. The html displays Data in tabular format. There is drop-down at the 'Status" column of this table. If the status is chosen as 'all', then all the rows will be displayed having status ('CO','OK','IN' and '-'). But if the status is selected as 'valid', then the rows having '-' as status will be discarded and only rows having 'CO','OK,'IN' as status will be displayed. The following code is working except for a single row once I select 'valid' as Status from the drop-down. Please notice the cell under "Task" column having value 'checkRsf1' and its immediate right cell containing 'exec' under "Command" column is not coming at all after filtering by "valid". Instead the 'esdnet' and 'IN' (under Method and Status column) are getting shifted to left under wrong column head. Thanks in advance. Below is the html embedded with Javascript. <html> <head> <link rel="stylesheet" type="text/css" href="/css/tree.css" /> </head> <body style="background-color:#fff"> <table border="1" id="mytable"><tr style="background-color:#d0d0d0"> <th align="left">Task</th><th align="left">Command</th><th align="left">Method</th> <th align="left">Status<br><select onchange="showRows(this.value)"> <option value="all">show status</option> <option value="all">all</option> <option value="active">valid</option> </select> </th> <th align="left">Task version</th><th align="left">Tool</th><th align="left">Last changed</th><th align="left">Comments</th></tr> <tr><td rowspan="1">char32</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">H1p</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">H1c</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">adex</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">ds</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">mec</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">admsSim_post</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">Sim_pre</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap"><font color="red">CO</font></td><td nowrap="nowrap">CO</td><td nowrap="nowrap">CO</td><td nowrap="nowrap">Apr 24 </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">amsdSim_post</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap"><font color="red">OK</font></td><td nowrap="nowrap">CO</td><td nowrap="nowrap">CO</td><td nowrap="nowrap">Apr 21 </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">amsdSim_pre</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap"><font color="red">OK</font></td><td nowrap="nowrap">CO</td><td nowrap="nowrap">CO</td><td nowrap="nowrap">May 3 </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">antdrc</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap"><font color="red">CO</font></td><td nowrap="nowrap">CO</td><td nowrap="nowrap">CO</td><td nowrap="nowrap">Apr 24</td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">archive</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">avenue</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">cdl</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap"><font color="red">IN</font></td><td nowrap="nowrap">CO</td><td nowrap="nowrap">CO</td><td nowrap="nowrap">Apr 2</td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">cdl_pre</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap"><font color="red">CO</font></td><td nowrap="nowrap">CO</td><td nowrap="nowrap">CO</td><td nowrap="nowrap">Apr 8</td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="5">checkRsf</td><td rowspan="5">exec</td><td nowrap="nowrap">antdrc</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">drc</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">erc</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">esdnet</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">lvs</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="5">checkRsf1</td><td rowspan="5">exec</td><td nowrap="nowrap">antdrcres</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">drc</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">erc</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">esdnet</td><td nowrap="nowrap">IN</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">lvs</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="5">checkRsf2</td><td rowspan="5">exec</td><td nowrap="nowrap">antdrcres</td><td nowrap="nowrap">IN</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">drc</td><td nowrap="nowrap">IN</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">erc</td><td nowrap="nowrap">IN</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">esdnet</td><td nowrap="nowrap">IN</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">lvs</td><td nowrap="nowrap">IN</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="2"> designSync</td><td rowspan="2">exec</td><td nowrap="nowrap">dssc_layout</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td nowrap="nowrap">dssc_schematic</td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">diosearch</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap">-</td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td><td nowrap="nowrap"> </td></tr> <tr><td rowspan="1">drc</td><td rowspan="1">exec</td><td nowrap="nowrap"> </td><td nowrap="nowrap"><font color="red">IN</font></td><td nowrap="nowrap">CO</td><td nowrap="nowrap">CO</td><td nowrap="nowrap">Apr 3</td><td nowrap="nowrap"> </td></tr> </table> <script type="text/javascript"> mytab=document.getElementById("mytable") function showRows(val){ for (var i = 0; i < mytab.rows.length; i++) { if (val=="all"){ mytab.rows[i].style.display="table-row" } else { if (mytab.rows[i].innerHTML.match("-")){ mytab.rows[i].style.display="none" } } } } </script> </body> </html> Similar TutorialsHi, I have an array for all the trousers on my site. It includes the image, name, waist, description, price and buy link. The javascript I use below outputs all products in the array. What I'd like to do is only output products which contain either "Wrangler" or "Levi" in the name string AND "forty" or "thirty" in the waist string. Would anyone know how to change the for loop in order to do this? Code: for(i=0;i<Trousers.length;i++){ $('body').append("<div><img src='"+Trousers[i].ProductImage+"'>"+"<br /><strong>"+Trousers[i].name+"</strong><br /><span style='color: #999; font-size:10px;'>"+Trousers[i].waist+"</span><br />"+Trousers[i].description+"<br /><strong>"+Trousers[i].price+"</strong><br /><a href='"+Trousers[i].buyLink+"'>Add to Basket</a></div>"); } Thanks in advance 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. I want to have another go at Javascript. I have several books on the subject but I find that my eyesight is a major problem. Therefore I want to try an on-line solution, preferably free. I have Googled, but there are so many that I am almost dizzy with the choices. Perhaps someone could recommend one. Not too fussy visually. My knowledge is VERY basic. Frank Hello! I am trying to find a script that allows you to open multiple browser tabs and then close each of those tabs, either one by one or all at once. Does anyone know how to do this please? Thanks so much for your help. Does anyone know how to make URL links that use Javascript still work when users have Javascript disabled on their browser? The only reason I'm using JS on a URL is because my link opens a PDF file, and I'm forcing it not to cache so users have the latest version. I tried the <script><noscript> tags, but I'm not sure if I'm using it correctly, as my URL completely disappears. Below is my HTML/Javascript code: <p class="download"> <script type="text/javascript">document.write("<span style=\"text-decoration: underline;\"><a href=\"javascript:void(0);\" onclick=\"window.open( 'http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf?nocache='+ Math.floor( Math.random()*11 ) );\" >The Child Magazines Media Kit</a></span> (PDF 1 MB) ");</script> <noscript><span style="text-decoration: underline;"><a href="http://www.webchild.com.au/mediakit/Direct_Media_Kit_Web.pdf" >The Child Magazines Media Kit</a></span> (PDF 1 MB)</noscript> </p> Thanks for any help, Michael Hi, I have the following code snippet: test.html ====== <script language="javascript" type="text/javascript"> var testVariable = "test"; </script> <script language="javascript" type="text/javascript" src="test.js"> </script> test.js ===== var testVariable = window.top.testVariable; In firefox, I'm able to access testvariable defined within test.html in test.js. But in chrome, test.js couldnot get the window.top.testVariable field defined in test.html. Can any one please let me know how i can make it work in chrome?. Am i missing something here?. Hi Guys, I am new at JavaScript and start to do some tutorials.What I am trying to do here is prompting user to input a name and if the name was valid the page(document) will display with all objects like the button.But if user enter a wrong name then the button will be disabled! I create the following code but it did not work <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</title> <script language="JavaScript" type=""> function changeColor(){ document.bgColor = "Gray"; } </script> </head> <body> <script language="JavaScript" type="text/javascript"> var person = ""; person = prompt('What is Your Name:'); if (person == "Foo") { document.write("<h1 />Welcome " + person); document.bgColor = "Yellow"; } else { document.write("<h1 />Access Denied!!!!"); document.bgColor = "Red"; document.getElementById("gree").disabled = true; } </script> <div> <p/><input id="gree" type="button" value="Gray " onClick="changeColor();"> </div> </body> </html> as you can see I used the: document.getElementById("gree").disabled = true; but it did not work , could you please give an idea how I can solve this problem? Thanks Hi Guys I am trying to modify the functionality of my page. I want to be able to activate this piece of code using another javascript function. This is the code I want to activate: Code: <script type="text/javascript"><!-- $('#button-cart').bind('click', function() { $.ajax({ url: 'index.php?route=checkout/cart/update', type: 'post', data: $('.product-info input[type=\'text\'], .product-info input[type=\'hidden\'], .product-info input[type=\'radio\']:checked, .product-info input[type=\'checkbox\']:checked, .product-info select, .product-info textarea, .date_data input[type=\'text\']'), dataType: 'json', success: function(json) { $('.success, .warning, .attention, information, .error').remove(); if (json['error']) { if (json['error']['warning']) { $('#notification').html('<div class="warning" style="display: none;">' + json['error']['warning'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.warning').fadeIn('slow'); } for (i in json['error']) { $('#option-' + i).after('<span class="error">' + json['error'][i] + '</span>'); } } if (json['success']) { $('#notification').html('<div class="success" style="display: none;">' + json['success'] + '<img src="catalog/view/theme/default/image/close.png" alt="" class="close" /></div>'); $('.success').fadeIn('slow'); $('#cart_total').html(json['total']); $('html, body').animate({ scrollTop: 0 }, 'slow'); } } }); }); //--></script> And this is how I want the format of the function to be: function testsession() { if there is a session called 'hiredate' { activate the script above } else { var el = document.getElementById("product_data"); } } I just dont know how to write this in javascript Could you help me if possible please Hey, I've got to make the values of some textboxes change the co-ordinates of my sprite on a canvas and havent a clue on how to do it, Here is my form with the two textboxes and submit button: <form> x: <input type="text" name="x" /><br /> y: <input type="text" name:"y" /><br /> <input type="submit" value="Submit"/><br /> </form> And i need it so that they change the values of these: //this shows where my sprite will start on the canvas var block_x; var block_y; searched the internet for hours and cant really find anything i understand or works. any help is much appreciated I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... I want to insert this js snippet Code: function addText(smiley) { document.getElementById('message').value += " " + smiley + " "; document.getElementById('message').focus(); return false; } to a loaded iframe with name&id chtifrm. I can access it & change embed something in its html via using something like: Code: $(parent.chtifrm.document.body).append('<div id=\"smly\" style=\"cursor:pointer;float:left;top:200px;display:none;position:absolute;\"><\/div>'); .... Code: parent.chtifrm.document.getElementById('chatbox_option_disco').style.display == 'none' but how do I insert js in the head of loaded iframe? 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 I wrote a log function that took note of various function calls. Thinking that functions are first class objects, and objects have properties, I made the name of each logged function a property of that function, e.g., brightenInnerPara.name = "brightenInnerPara"; Every browser I tried (Firefox, MSIE, Opera, Chrome, Safari) accepted the assignment, no problem. In Firefox and MSIE, the result was what I wanted: brightenInnerPara.name == "brightenInnerPara" But in the others, the result was: brightenInnerPara.name == null Question 1. Which Javascript is correct here? I favor Firefox and MSIE, not merely because they were willing to give me what I wanted, but also because it makes no sense to accept an assignment statement without throwing an error and then give it a null semantics, like Chrome, Opera, and Safari did. I found a workaround, using assignments like this: brightenInnerPara.prototype.name = "brightenInnerPara"; To my surprise, that worked in every browser. But I don't know why. It seems that such assignments are enough to cause each function to have its own distinct prototype. Question 2. Just how inefficient is my workaround, and why does it work? I have these lines of codes, but I can not get the calendar shown in the browser. can anyone help me on this. Thanks! <html> <head> $(document).ready(function() { $('#calendar').datepicker({ dateFormat: 'yy-mm-dd', changeYear: false, changeMonth: false, minDate: '-1m', maxDate: '+2m', }); </head> <body> <div id='calendar'> </div> </body> </html> Hi. I am cool man. Can someone tell me how has the application of JavaScript improved the user experience of website?
Hello friends, I need a help in HTML and java script I want that whenever i scroll the HTML page downwards then when i reaches at the bottom of the page then some event should get fired or some action should get performed like twitter I don't understand, how can i do that ? Hey Guys, I need some more help with a project. Here's a current line of code. Code: final = oneline + "<br />" + final + oneline + "<br />"; Based on combining that with a for loop and some if () conditions, this is the result if a user enter 3 as the number of xs. Code: xxx xx xx xxx It's close to what my output is supposed to be, but it's missing one component. In between that pair of "xx", a variable called name is supposed to come out. Here's what it's supposed to look like if name = CodingForums Code: xxx xx CodingForums xx xxx I originally had this down, but then my computer crashed, and I couldn't recreate it again. I know it's something with that line. Can anyone advise me on what to do next? Thanks! EDIT: Here's the full code Code: <html> <head> <script type="text/javascript"> var name = prompt("What's your name?","Stranger"); var ask = prompt("How wide do you want the pyramid?","10"); var num = parseInt(ask); var final = ""; var oneline = ""; var name = "Welcome " + name + "!"; for (var j = 0; j < num; j++) { oneline = oneline + "x"; if ((oneline != "x") && (num != 1)) { final = oneline + "<br />" + final + oneline + "<br />"; } else if (num == 1) { final = "x" + "<br />" + name + "<br />" + "x"; } } </script> </head> <body> <script type="text/javascript"> document.writeln(final); </script> </body> </html> Hi guy's Not sure if what i want to do is possible, i am a very basic computer user and any help would be great. i have a relay that is conect to my router and if i type the following into the address bar it turns it on for 2 seconds. "http://192.168.1.68/state.xml?relayState=2" What i would love to do is be able to add a book mark which once selected it fires off the above string and closes the window without a prompt, is this possible??? i have spent hours and hours and seem to be going nowhere. Thanks for all your help Daniel I wonder whether anyone can help me please... I have the following javascript in place. <script type="text/javascript"> function goTo() {var url = document.forms[0].url.value; var model = document.forms[0].model.value; var size = document.forms[0].size.value; var type = document.forms[0].type.value; var hertz = document.forms[0].hertz.value; window.location = url+model+'&'+'size='+size+'&type='+type + '&hertz='+hertz+'.htm'; return false;} </script> It is used along with a dropdown window of selection critieria which when selections are made and submitted it forms a url address. What I need to do is to check whether the url address formed actually exists. If it doesn't then it is redirected to another url. I hope I have explained this okay. Many thanks ! |