JavaScript - My Rollover Images Have Spaces In Between Them And I Need Them To Touch...
Hello,
I just created a new page topper for my website, and am new to javascript. I spent HOURS on designing all of the mouseover images that are on my website now, except there are spaces in between all of the images and I designed them to touch. You can see what I am talking about on my website he http://www.corporateavedesign.com I've tried everything in the code to get these images to touch. Can anyone help? Here is my code: Code: <SCRIPT LANGUAGE="JavaScript"> <!-- Begin loadImage1 = new Image(); loadImage1.src = "http://www.corporateavedesign.com/images/website-logoMO1.jpg"; staticImage1 = new Image(); staticImage1.src = "http://www.corporateavedesign.com/images/website-logo1.jpg"; loadImage2 = new Image(); loadImage2.src = "http://www.corporateavedesign.com/images/website-logoMO2.jpg"; staticImage2 = new Image(); staticImage2.src = "http://www.corporateavedesign.com/images/website-logo2.jpg"; loadImage3 = new Image(); loadImage3.src = "http://www.corporateavedesign.com/images/website-logoMO3.jpg"; staticImage3 = new Image(); staticImage3.src = "http://www.corporateavedesign.com/images/website-logo3.jpg"; loadImage4 = new Image(); loadImage4.src = "http://www.corporateavedesign.com/images/website-logoMO4.jpg"; staticImage4 = new Image(); staticImage4.src = "http://www.corporateavedesign.com/images/website-logo4.jpg"; loadImage5 = new Image(); loadImage5.src = "http://www.corporateavedesign.com/images/website-logoMO5.jpg"; staticImage5 = new Image(); staticImage5.src = "http://www.corporateavedesign.com/images/website-logo5.jpg"; loadImage6 = new Image(); loadImage6.src = "http://www.corporateavedesign.com/images/website-logoMO6.jpg"; staticImage6 = new Image(); staticImage6.src = "http://www.corporateavedesign.com/images/website-logo6.jpg"; // End --> </script> <!-- STEP TWO: Insert this code into the BODY of your HTML document --> <TD style="BORDER-TOP: #000000 0px solid; BORDER-LEFT-WIDTH: 0px; BORDER-LEFT-COLOR: #000000; BORDER-BOTTOM: #000000 0px solid; BORDER-RIGHT-WIDTH: 0px; BORDER-RIGHT-COLOR: #000000" vAlign=bottom bgColor=#ffffff colSpan=2 height=10> <CENTER> <a href="http://www.corporateavedesign.com/" onmouseover="image1.src=loadImage1.src;" onmouseout="image1.src=staticImage1.src;"> <img name="image1" src="http://www.corporateavedesign.com/images/website-logo1.jpg" border=0></a> <a href="http://www.corporateavedesign.com/" onmouseover="image2.src=loadImage2.src;" onmouseout="image2.src=staticImage2.src;"> <img name="image2" src="http://www.corporateavedesign.com/images/website-logo2.jpg" border=0></a> <a href="http://www.corporateavedesign.com/pages/AboutUs.htm" onmouseover="image3.src=loadImage3.src;" onmouseout="image3.src=staticImage3.src;"> <img name="image3" src="http://www.corporateavedesign.com/images/website-logo3.jpg" border=0></a> <a href="http://www.corporateavedesign.com/contact.htm" onmouseover="image4.src=loadImage4.src;" onmouseout="image4.src=staticImage4.src;"> <img name="image4" src="http://www.corporateavedesign.com/images/website-logo4.jpg" border=0></a> <a href="http://www.corporateavedesign.com/pages/Portfolio.htm" onmouseover="image5.src=loadImage5.src;" onmouseout="image5.src=staticImage5.src;"> <img name="image5" src="http://www.corporateavedesign.com/images/website-logo5.jpg" border=0></a> <a href="http://www.corporateavedesign.com/category_36/Current-Price-List.htm" onmouseover="image6.src=loadImage6.src;" onmouseout="image6.src=staticImage6.src;"> <img name="image6" src="http://www.corporateavedesign.com/images/website-logo6.jpg" border=0></a> </CENTER> Please help if you can, I am desperate and my website looks crazy right now! THANKS!!! Similar TutorialsI have some rollover images on my website, and they don't switch until the page is finished loading. Is this standard? Is there a way to have the rollovers work when the page is still in the process of loading all the images? Thanks Hi all I've been looking now for over a week on how create this http://instances.110mb.com/ effect when you hover over the ships on that page. I would be eternally grateful for any ideas how to replicate this effect. Thanks Rob I'm trying to do some rollover images for a webpage I need to design, for class. I have them set up, and they work.. but the issue is that I set it up in such a way that the .js file is dynamic, and works for each page. You know, so that I don't actually have to specify the images within the .js file. The problem with THAT is that it doesn't automatically load the rollover version of each image, when the page loads.. so it's a bit sluggish. Here's my .js file Code: function swap_image(name,source) { document.images[name].src=source; var argv=swap_image.arguments; if(argv[2] && argv[3] && document.getElementById) { element=document.getElementById(argv[2]); element.innerHTML=argv[3]; } } Here's how I have it in the HTML Code: <a href="gallery" onmouseover="swap_image('gallery','/images/galleryro.jpg')" onmouseout="swap_image('gallery','/images/gallery.jpg')"> <img style = "top:150px; left:100px;" border="0" id="gallery" src="/images/gallery.jpg"/> </a> Is there anything I can do to force it to load the rollover image, without sacrificing my dynamic .js code? Hi i have two images which are part of a rollover button that i want to have paused until the intro animation finishes. I have the javascript code but the rollover images are specified in the css. I just have the id to them in the html. I was wondering if anyone knew how to include the rollover files with the pausing javascript code. the files are profile.gif and profileover.gif. I tried to add the files to the preload part of the javascript but that didn't work. The website is www.creationindex.com/indextest.html thank you
I am using this: http://www.crowdsavings.com/open-source/drawbox (http://page-test.co.uk/jquery.drawbox.js is the main JS file). It works fine on desktop browsers, but there is an issue on every Touch mobile phone I have tried. When you draw on the canvas and then go to click a button off the canvas, it doesn't work. You need to touch off the canvas and then the button. So using the demo above, if you draw on the canvas and then click the 'Clear Canvas' button, it doesn't work and you have to press it again. I have tried setting focus on the body and also detecting what the focus is when a touch action is performed, but no luck. I know the entire screen is responsive to touch and mouse events, where I would have thought it best to just make the canvas section respond to touch/mouse events. I'd be grateful for any help please. I've just started to build my first ever sencha app and am pleased with the results so far, but am now stuck on one thing. I've built a search form and want to be able to display the results on the same page, but this is where I'm stuck. The form works and sends the results using GET, but it doesn't send it to the correct place. I want to show it on the same page (I've built a php file called search.php to handle the results), but it reloads the whole app with the variables in the url. I've tested all of the code away from the app and it works perfectly so I know the problem isn't with the code, but more with my lack of understanding of Sencha so would be extremely grateful for any help. Code: searchForms = new Ext.TabPanel({ fullscreen: true, title: 'Search', displayField: 'text', sto searchForm, iconCls: 'search', items: [{ id: 'searchSubmit', xtype: 'form', standardSubmit : true, scroll: 'vertical', items: [{ xtype: 'fieldset', title: 'Keywords', defaults: { // labelAlign: 'right' labelWidth: '35%' }, items: [{ xtype: 'textfield', name: 'keywords', id: 'keywords', placeHolder: 'EG: Music, TV', autoCapitalize : true, required: true, useClearIcon: true }] }, { xtype: 'fieldset', title: 'Advanced Search', items: [{ xtype: 'selectfield', name: 'genre', id: 'genre', label: 'Genre', options: [{ text: 'All', value: ' ' text: 'Country', value: '1' text: 'Sci-Fi', value: '2' text: 'Western', value: '3' }] }, { xtype: 'selectfield', name: 'media', id: 'media', label: 'Media', options: [{ text: 'All', value: ' ' text: 'Music', value: '1' text: 'TV', value: '2' text: 'Movie', value: '3' }] }] }, { layout: 'vbox', defaults: {xtype: 'button', flex: 1, style: 'margin: .5em;'}, items: [{ text: 'Search', ui: 'confirm', scope: this, hasDisabled: false, handler: function(){ searchForms.submit({ url: 'search.php' }); } }, { text: 'Reset', ui: 'decline', handler: function(){ searchForms.reset(); } }] }] }] }); I've then tried to use this to display the results on the same page, but as I say this just doesn't work. It doesn't call the search.php page at all. I've made sure all of the files (except the index.js file which is in a js folder) are in the same directory as the index.html file. I've also tried to load the file in the app seperately by using: Code: Ext.regModel('mobile', { fields: [ {name: 'text', type: 'string'} ] }); var searchForm = new Ext.data.TreeStore({ model: 'mobile', proxy: { type: 'ajax', url: 'search.php?keywords=test', reader: { type: 'tree', root: 'items' } } }); and that works perfectly so I know that all of the php stuff is working and does work with Sencha Touch, but I'm just not sure how to get it to only work when somebody clicks 'search' I'd be grateful for any help with this as I've spent days searching the web to get this fix, but nothing seems to be working I don't know if this is of help, but the main javascript file is: Code: var tabPanel; var homePanel = new Ext.Panel({ title: 'Home', iconCls: 'home', fullscreen: true, scroll:{direction:'vertical',threshold:7}, items: [{ html: '<center><p>Home</p></center>' }] }); var servicePanel = new Ext.Panel({ title: 'Services', iconCls: 'team', fullscreen: true, items: [{ html: '<center>Please choose a service</center>' }] }); var searchPanel = new Ext.Panel({ title: 'Search', iconCls: 'search', fullscreen: true, items: [{ html: '<center>Search</center>' }] }); var feedtabpanel = new Ext.Carousel({ title: 'More', iconCls: 'more', fullscreen: true, sortable : true, xtype:'panel', scroll:{direction:'vertical',threshold:7}, items: [ { title: 'Contact', html : '<center><h1>Contact Us</h1></center>', }, { title: 'Feedback', html : '<center><h1>Let us know what you think<h1></center>', }, { title: 'Tell a friend', html : '<center><h1>Tell your friends how much you love this app</h1></center>', } ] }); searchForms = new Ext.TabPanel({ fullscreen: true, title: 'Search', displayField: 'text', sto searchForm, iconCls: 'search', items: [{ id: 'searchSubmit', xtype: 'form', standardSubmit : true, scroll: 'vertical', items: [{ xtype: 'fieldset', title: 'Keywords', defaults: { // labelAlign: 'right' labelWidth: '35%' }, items: [{ xtype: 'textfield', name: 'keywords', id: 'keywords', placeHolder: 'EG: Music, TV', autoCapitalize : true, required: true, useClearIcon: true }] }, { xtype: 'fieldset', title: 'Advanced Search', items: [{ xtype: 'selectfield', name: 'genre', id: 'genre', label: 'Genre', options: [{ text: 'All', value: ' ' text: 'Country', value: '1' text: 'Sci-Fi', value: '2' text: 'Western', value: '3' }] }, { xtype: 'selectfield', name: 'media', id: 'media', label: 'Media', options: [{ text: 'All', value: ' ' text: 'Music', value: '1' text: 'TV', value: '2' text: 'Movie', value: '3' }] }] }, { layout: 'vbox', defaults: {xtype: 'button', flex: 1, style: 'margin: .5em;'}, items: [{ text: 'Search', ui: 'confirm', scope: this, hasDisabled: false, handler: function(){ searchForms.submit({ url: 'search.php' }); } }, { text: 'Reset', ui: 'decline', handler: function(){ searchForms.reset(); } }] }] }] }); Ext.regModel('mobile', { fields: [ {name: 'text', type: 'string'} ] }); var searchForm = new Ext.data.TreeStore({ model: 'mobile', proxy: { type: 'ajax', url: 'search.php', reader: { type: 'tree', root: 'items' } } }); var store = new Ext.data.TreeStore({ model: 'mobile', proxy: { type: 'ajax', url: 'areas.php', reader: { type: 'tree', root: 'items' } } }); var nestedList = new Ext.NestedList({ fullscreen: true, title: 'Location', displayField: 'text', sto store, iconCls: 'locate', }); nestedList.on('leafitemtap', function(subList, subIdx, el, e) { var store = subList.getStore(), record = store.getAt(subIdx), recordNode = record.node, title = nestedList.renderTitleText(recordNode), card, preventHide, anim; if (record) { card = record.get('card'); anim = record.get('animation'); preventHide = record.get('preventHide'); } if (card) { tabPanel.setCard(card, anim || 'slide'); tabPanel.currentCard = card; } }); var services = new Ext.data.TreeStore({ model: 'mobile', proxy: { type: 'ajax', url: 'subcats.php', reader: { type: 'tree', root: 'items' } } }); var servicesList = new Ext.NestedList({ fullscreen: true, title: 'Services', displayField: 'text', sto services, iconCls: 'team', }); servicesList.on('leafitemtap', function(subList, subIdx, el, e) { var store = subList.getStore(), record = store.getAt(subIdx), recordNode = record.node, title = servicesList.renderTitleText(recordNode), card, preventHide, anim; if (record) { card = record.get('card'); anim = record.get('animation'); preventHide = record.get('preventHide'); } if (card) { tabPanel.setCard(card, anim || 'slide'); tabPanel.currentCard = card; } }); Ext.setup({ icon: 'icon.png', glossOnIcon: false, tabletStartupScreen: 'tablet_startup.png', phoneStartupScreen: 'phone_startup.png', onReady: function() { tabPanel = new Ext.TabPanel({ tabBar: { dock: 'bottom', layout: { pack: 'center' } }, fullscreen: true, ui: 'dark', animation: { type: 'cardslide', cover: true }, items: [ homePanel, nestedList, servicesList, searchForms, feedtabpanel ] }); } }) i am new to sencha touch,and i created a login form which accepts user id and password and a login button,so when i click on login button i should get the user id value as a alert.and the code is Code: Ext.setup ({ onReady: function () { var myform=new Ext.form.FormPanel({ id:'form', fullscreen:true, standardSubmit:true, dockedItems:[{ Dock:'top', xtype:'toolbar', height:40, title:'Tool Bar', id:'login', } ], items:[{ xtype:'textfield', name:'id', width:'50%', align:'center', label:'User Id' }, { xtype:'textfield', name:'pwd', id:'pwd', width:'50%', align:'center', label:'Password' }, { xtype:'button', ui:'round', width:'50%', text:'Login', align:'center', handler:function() { gettingvalues();/* var fields = form.getValues(); console.log(fields['name']); */ } } ], }); gettingvalues=function() { var fields=myform.getValues(); Ext.Msg.alert(fields['id'].getValue()); } } }); But am not getting any value in alert,what i have to do. and after that i want to send those values to our local server which requires id and password,it will be in the format of... oururl?action=login&id=xyz&pwd=xyz, in this it will accepts and returns the response,so for that what i have to write, please let me know as soon as possible. Thanks in advance. Hi developers Needing some help. My javascript/css drop down menu is not working on the ipad or other touch screen devices. It works fine on laptops & desktops which use a mouse. I've discovered that this is because touchscreen devices like the Ipad do not recognise the onmouseover/onmouseout event handler that my script relies on. Is there any way I can modify my script so that it is compatiable both with traditional devices and touchscreen devices? The code I am using is: <script type="text/javascript"><!-- var timeout = 500; var closetimer = 0; var ddmenuitem = 0; // open hidden layer function mopen(id) { // cancel close timer mcancelclosetime(); // close old layer if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; // get new layer and show it ddmenuitem = document.getElementById(id); ddmenuitem.style.visibility = 'visible'; } // close showed layer function mclose() { if(ddmenuitem) ddmenuitem.style.visibility = 'hidden'; } // go close timer function mclosetime() { closetimer = window.setTimeout(mclose, timeout); } // cancel close timer function mcancelclosetime() { if(closetimer) { window.clearTimeout(closetimer); closetimer = null; } } // close layer when click-out document.onclick = mclose; //--></script> Which drives the following html: <ul id="links"> <li><a href="whats_new/whats_new.html">what's new</a></li> <li><a href="#" onmouseover="mopen('m1')" onmouseout="mclosetime()">clothing</a> <div id="m1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"> <a href="clothing/clothing_page1.html">clothing</a> </div> </li> <li><a href="#" onmouseover="mopen('m2')" onmouseout="mclosetime()">accessories</a> <div id="m2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"> <a href="bags/bags_page1.html">bags</a> <a href="jewellery/jewellery_page1.html">jewellery</a> </div> </li> </ul> Any suggestions would be much appreciated. Thank you. Nonye Edit2:: This is what I got to work. Code: <INPUT class=touch type=button value='UP' onMouseDown="up=true;" onMouseUp="up=false;"> <INPUT class=touch type=button value='DOWN' onMouseDown="down=true;" onMouseUp="down=false;"> Then added a check to see if (up==true) {move up code} else if (down==true) {move down code} etc Edit:: Basically Code: <INPUT class=touch type=button value='38' onMouseDown="movingUP();"> Then in JS Code: function movingUP(){ window.event.keyCode = 38; } But what do I put in movingUP() to send keyCode 38 when while the button is being clicked????????????????????? Trying to add 8 icons of W,A,S,D, LEFT, RIGHT, UP, DOWN which upon click/touch will input the relative command to the screen canvas for mobiles that don't have a keyboard. They aren't clicking on the canvas. I need some buttons/icons/images outside the canvas probably in a div, that send input events as an alternative to a keyboard...Something that can be clicked and held down to repeatedly spam that key to walk in that direction. I have script to click icons from a keyboard and output the clicked key to a text field, but I don't know how to tie it into my keyboard listener in my game.. My game code uses: Code: // Handle keyboard controls var keysDown = {}; addEventListener("keydown", function (e) { keysDown[e.keyCode] = true; }, false); addEventListener("keyup", function (e) { delete keysDown[e.keyCode]; }, false); Then elsewhere I can trigger events when keysDown contains the number of a key that triggers an item like: Code: if (38 in keysDown && hero.y > 0 ) { // Player holding UP key //walk north code here } Is there a simple way to click on a button and send the "UP" keyCode to the entire screen? Particularly the canvas element......Or get it into my keysDown[e.keyCode]; I found this: Quote: function addKey(cKey) { d = document.forms["foo"].elements["bar"]; d.value = (cKey.value=='backspace') ? d.value.slice(0,-1) : d.value+cKey.value; } //elsewhere in html body <INPUT class=touch type=button value=w onClick="addKey(this)"> which will send 'w' when clicked, and I tried to send '38' instead but it only sends it to 1 element and not the entire screen....so it shows 38 in a text box each time I click it but it doesn't actually send 38 to keys being pressed. Is there a simple way to do this? I wanted to add a fire button and others I figured I could just put an image with an event but can't figure it out.... Hello all, I've got a problem with a JS dropdown menu that I'm using. It's an unordered HTML list that is driven by a JS file. The menu is at Watt You Need Electrical - Offering Electrical Services For Geelong, Bellarine Peninsula & The Surf Coast Initially when I got the menu template all the top level items and all the list items were coded as links. What I've done is make the Electrical heading just text and the two dropdown list items below it are still links. The menu works both on a desktop with a pointer and also on a mobile device by touch. The problem is that on a mobile device when I touch the Electrical heading the dropdown doesn't appear. The Solar heading and the dropdown below it work fine because the Solar heading is still a link. Obviously I've created the problem by changing the Electrical heading to text from a link but I'd like to be able to have it that way. I've tested using some online mobile device emulators and it works OK there but when I physically test on an Iphone 5 the bug is there. I haven't been able to get my hands on any other phones or devices to test yet so don't know if it's a problem just with Iphones or Ipads. I've had a look through the Dropdown.src.js file but it's way beyond me, I've listed both the HTML and JS file below. Code: <!DOCTYPE html> <html> <head> <title>Watt You Need Electrical - Offering Electrical Services For Geelong, Bellarine Peninsula & The Surf Coast</title> <meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" /> <meta name="description" content="Watt You Need Electrical is your one stop shop for all types of electrical services. Whether you need some domestic, commercial, or even industrial electrical work done we can help. We also can advise on and install solar power systems and split air conditioners." /> <meta name="keywords" content="electrical services" /> <meta name="robots" content="index, follow" /> <link rel="stylesheet" type="text/css" href="css/styles.css" media="Screen" /> <link rel="stylesheet" type="text/css" href="css/mobile.css" media="handheld" /> <link media="only screen and (max-device-width: 480px)" href="css/mobile.css" type="text/css" rel="stylesheet" /> <script> // initialise the drop-down menus runOnLoad(Dropdown.initialise); </script> </head> <body> <div id="wrapper"> <a href="tel://+61425859742"><div id="mobile_header"></div></a> <a href="tel://+61425859742"><div id="phoneBlock"></div></a> <div id="header"></div> <div id="nav"> <ul class="dropdown"> <li> <a href="index.html">Home</a> </li> <li>Electrical <ul> <li> <a href="domestic_electrician.html">Domestic</a> </li> <li> <a href="electrical_contractors.html">Commercial/Industrial</a> </li> </ul> </li> <li> <a href="air_conditioner_installation.html">Air Conditioners</a> </li> <li> <a href="solar_power_systems.html">Solar</a> <ul> <li><a href="solar_system_maintenance.html">Maintenance</a> </li> <li><a href="solar_energy_facts.html">About Solar</a> </li> </ul> </li> <li> <a href="b_type_gas_service.html">Type B Gas</a> </li> <li> <a href="formgenerator/forms/contact.html">Contact Us</a> </li> </ul> </div> <div id="content-2"> <div class="clear"> </div> <div id="top_border"></div> <div id="content-2-1"> <span class="blackheading">Watt You Need Electrical - Offering Electrical Services For Geelong, Bellarine Peninsula & The Surf Coast</span> <p>Watt You Need Electrical Services can help you with all your electrical needs. We're not one of the big franchise electrical contractors so we can take that extra bit of time and effort to make sure you get the best service and advice. <br /><br /> If it's just an extra power point you need all the way to a complete house rewire, thinking about making the switch to solar power, or if you want a split airconditioner to keep your house or business cool and comfortable, our focus is on exceeding our customer's expectations and providing the best quality job at a competitive price. <br /><br /> Our service doesn't just stop at <a href="domestic_electrician.html">domestic electrical</a> and <a href="solar_power_systems.html">solar power</a>, we can also attend to your <a href="electrical_contractors.html">commercial and industrial electrical</a> needs and we specialise in <a href="b_type_gas_service.html">B Class gas appliance</a> repair and maintenance. Our range of services and quality workmanship are what sets us apart from other electrical contractors. <br /><br /> <a href="formgenerator/forms/contact.html">Contact us</a> today and let Watt You Need Electrical take care of your domestic, solar, air conditioning and commercial and industrial electrical services. </p> </div> <div id="bottom_border"></div> </div> <div id="footer"> <table class="tableFooter"> <tr><td>Watt You Need Electrical Pty. Ltd. © 2014</td></tr> </table> </div> </div> </body> </html> Code: /* Dropdown.js Creates touch-friendly drop-down menus Created by Stephen Morley - http://code.stephenmorley.org/ - and released under the terms of the CC0 1.0 Universal legal code: http://creativecommons.org/publicdomain/zero/1.0/legalcode */ // create the Dropdown object var Dropdown = (function(){ // the delay, in milliseconds var DELAY = 250; // the list of menus var menus = []; // Initialises the drop-down menus. function initialise(){ // listen for touch events on the document if appropriate if ('createTouch' in document){ document.body.addEventListener('touchstart', handleTouchStart, false); } // loop over the menus, converting them var menus = document.querySelectorAll('ul.dropdown'); for (var i = 0; i < menus.length; i ++) applyTo(menus[i]); } /* Handles a touch start event. The parameter is: * * e - the event */ function handleTouchStart(e){ // determine whether any menu is open var isOpen = false; for (var i = 0; i < menus.length; i ++){ if (menus[i].isOpen) isOpen = true; } // return immediately if all menus are closed if (!isOpen) return; // move up the document tree until we reach the root node var node = e.target; while (node != null){ // return immediately if we are inside a drop-down menu if (/\bdropdown\b/.test(node.className)) return; // move onto the parent node node = node.parentNode; } // close all menus close(); } /* Closes all menus except the specified menu. The parameter is: * * menu - a menu not to close; this parameter is optional */ function close(menu){ // loop over the menus, closing them for (var i = 0; i < menus.length; i ++){ if (menus[i] != menu) menus[i].close(); } } /* Creates a drop-down menu. The parameter is: * * node - either the DOM node of the menu or the ID of the node */ function applyTo(node){ // fetch the DOM node if a string was supplied if (typeof node == 'string') node = document.getElementById(node); // create and store the new menu menus.push(new Menu(node)); } /* Creates a drop-down menu. The parameter is: * * node - the DOM node of the menu */ function Menu(node){ // store the node this.node = node; // update the class name node.className += ' dropdownJavaScript'; // listen for mouse events if ('addEventListener' in node){ node.addEventListener( 'mouseover', this.bind(this.handleMouseOver), false); node.addEventListener('mouseout', this.bind(this.handleMouseOut), false); node.addEventListener('click', this.bind(this.handleClick), false); }else{ node.attachEvent('onmouseover', this.bind(this.handleMouseOver)); node.attachEvent('onmouseout', this.bind(this.handleMouseOut)); node.attachEvent('onclick', this.bind(this.handleClick)); } // listen for touch events if appropriate if ('createTouch' in document){ node.addEventListener('touchstart', this.bind(this.handleClick), false); } } // whether the menu is open Menu.prototype.isOpen = false; // the timeout Menu.prototype.timeout = null; /* Binds the specified function to the current object. The parameter is: * * f - the function */ Menu.prototype.bind = function(f){ // return the bound function var thisObject = this; return function(){ f.apply(thisObject, arguments); } } /* Handles a mouse over event. The parameters a * * e - the event * immediate - true to open the menu without a delay */ Menu.prototype.handleMouseOver = function(e, immediate){ // clear the timeout this.clearTimeout(); // find the parent list item var item = ('target' in e ? e.target : e.srcElement); while (item.nodeName != 'LI' && item != this.node) item = item.parentNode; // if the target is within a list item, set the timeout if (item.nodeName == 'LI'){ this.toOpen = item; this.timeout = window.setTimeout(this.bind(this.open), (immediate ? 0 : DELAY)); } } // Handles a mouse out event. Menu.prototype.handleMouseOut = function(){ // clear the timeout this.clearTimeout(); // set the timeout this.timeout = window.setTimeout(this.bind(this.close), DELAY); } /* Handles a click event. The parameter is: * * e - the event */ Menu.prototype.handleClick = function(e){ // close any other menus close(this); // find the parent list item var item = ('target' in e ? e.target : e.srcElement); while (item.nodeName != 'LI' && item != this.node) item = item.parentNode; // check that the target is within a list item if (item.nodeName == 'LI'){ // check whether the item has a closed submenu var submenu = this.getChildrenByTagName(item, 'UL'); if (submenu.length > 0 && !/\bdropdownOpen\b/.test(item.className)){ // open the submenu this.handleMouseOver(e, true); // prevent the default action if ('preventDefault' in e){ e.preventDefault(); }else{ e.returnValue = false; } } } } // Clears the timeout. Menu.prototype.clearTimeout = function(){ // clear the timeout if (this.timeout){ window.clearTimeout(this.timeout); this.timeout = null; } } // Opens the last item hovered over. Menu.prototype.open = function(){ // store that the menu is open this.isOpen = true; // loop over the list items with the same parent var items = this.getChildrenByTagName(this.toOpen.parentNode, 'LI'); for (var i = 0; i < items.length; i ++){ // check whether there is a submenu var submenu = this.getChildrenByTagName(items[i], 'UL'); if (submenu.length > 0){ // check whether the submenu should be opened or closed if (items[i] != this.toOpen){ // close the submenu items[i].className = items[i].className.replace(/\bdropdownOpen\b/g, ''); this.close(items[i]); }else if (!/\bdropdownOpen\b/.test(items[i].className)){ // open the submenu items[i].className += ' dropdownOpen'; // determine the location of the edges of the submenu var left = 0; var node = submenu[0]; while (node){ left += node.offsetLeft; node = node.offsetParent; } right = left + submenu[0].offsetWidth; // move the submenu to the right of the item if appropriate if (left < 0) items[i].className += ' dropdownLeftToRight'; // move the submenu to the left of the item if appropriate if (right > document.body.clientWidth){ items[i].className += ' dropdownRightToLeft'; } } } } } /* Closes the menus within the specified node. The parameter is: * * node - the node; if omitted, all menus are closed */ Menu.prototype.close = function(node){ // if no node was specified, close all menus if (!node){ this.isOpen = false; node = this.node; } // loop over the items, closing their submenus var items = node.getElementsByTagName('li'); for (var i = 0; i < items.length; i ++){ items[i].className = items[i].className.replace(/\bdropdownOpen\b/g, ''); } } /* Returns an array containing the children of the specified node with the * specified tag name. The parameters a * * node - the node * tagName - the tag name */ Menu.prototype.getChildrenByTagName = function(node, tagName){ // initialise the list of children var result = []; // loop over the children, adding those with the right tag name to the list for (var i = 0; i < node.childNodes.length; i ++){ if (node.childNodes[i].nodeName == tagName){ result.push(node.childNodes[i]); } } // return the children return result; } // return the public API return { initialise : initialise, applyTo : applyTo }; })(); Any help is appreciated. Hey guys, Lookin' for a little help, not sure if it can even be done? hopefully someone has the answer. I'm trying to design myself an online portfolio; here's what I got so far... http://www.gregorymstevens.com/testsite/site.html As you can see my navigation is represented by each bird on the tree (every bird is a link), when you rollver one of the green birds they turn white, however, I am looking to not only have the green bird rollver to white but ALSO have the "choose a" image on the bottom right change to the corresponding page. For instance, when the mouse rolls over a bird-- this image: will turn into this image: while maintaining the original "white bird" rollover. Hopefully I'm explaining this correctly -- Any help greatly appreciated! So <br/> creates a brake but is there a way to make "tab" space?
Hey Guys, I am a student doing my Cert IV in IT and am having a bit of trouble with some code. I have a form that when a letter is entered it returns a message saying you need to enter numbers in, and am trying to find a way of it checking if there are spaces in the numbers entered at the same time as checking if a number has been entered. My code looks as follows: Code: <html> <head> <title>Activity 2.25</title> </head> <script type="text/javascript"> function validateform() { var element; var BikeMoney; var TVMoney; var iPodMoney; var CarPrice; var flag; flag="OK" element=document.getElementsByTagName('input'); for(counter=0; counter<element.length; counter++) { switch (element[counter].type) { case "submit": break; default: if(isNaN(element[counter].value)) { alert("You will need to enter a number into " + element[counter].name); flag="NotOK" } else { BikeMoney=element[0].value; TVMoney=element[1].value; iPodMoney=element[2].value; CarPrice=element[3].value; } } } if(flag=="OK") if ((Number(BikeMoney)) && (Number(TVMoney)) && (Number(iPodMoney)) && (Number(CarPrice))) { TotalMoney = parseFloat (BikeMoney) + parseFloat (TVMoney) + parseFloat (iPodMoney) if(TotalMoney >= CarPrice) { alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you can afford the car"); } else { alert("The total money is " + TotalMoney + " and the car price is " + CarPrice + " and you cannot afford the car"); } } else { alert("Enter numbers Please"); } } </script> <body> <form name="input form" method="post" action=""> <table> <tr><td>Enter money from bike sale</td><td><input type="text" name="Bike Money"></td></tr> <tr><td>Enter money from TV sale</td><td><input type="text" name="TV Money"></td></tr> <tr><td>Enter money from iPod sale</td><td><input type="text" name="iPod Money"></td></tr> <tr><td>Enter the price of the car</td><td><input type="text" name="Car Price"></td></tr> <tr><td></td><td><input type="submit" value="Submit Details" onclick=validateform()></td></tr> </table> </form> </body> </html> I have a string variable: var mystring = ' hello world '; How can I truncate white spaces placed before or after my string value? Thank you in advance to help. How can I to delete white spaces around parameter that I to pass with HTML forms. For example, if I have 'firstname lastname ' or ' firstname lastname', exist it a builtin function in javascript to obtian 'firstname lastname'? savio Hi All, I have a form in my homepage which takes some values. In that, a text box takes multiple values seperated by spaces. I have allowed only alphanumeric characters in that with the following code. Code: function rmsplcharchkdepo() { var iChars = "\\\/~!@#$%^&*()=+[]{}|;:?,.\"`'<>"; var un= document.getElementById("deposit").value; for (var i = 0; i < document.ipmform.deposit.value.length; i++) { if (iChars.indexOf(document.ipmform.deposit.value.charAt(i)) != -1) { alert ("Error!! Remove Special Characters."); document.getElementById("deposit").value = un.substring(0,0); return false; } } } How can i trim the multiple spaces entered by the user between values instead of one single space allowed.. For eg: TEXTBOX:INDIA USA UK User should not be able to enter a space at the beginning, multiple spaces between the values and at the end. This is just to avoid unwanted complications at the backend. In brief i need a script which trim multiple and consecutive spaces to one. It would be a great help if some one can help me in this. hi all i m using the following validation code to validate email id Code: if (!/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,4})+$/.test(document.getElementById("customer_name").value)) { msg=msg+"Must Enter a valid Login-id/Email\n"; document.getElementById("customer_name").focus(); } now i need that if the email id contains white blank space in front of email id or end of email id then this validation should pass otherwise not. at present if there is blank space in front and end of email id then the validation doesnt passes and gives alert. what should i add in it to validate it or how can it automatically remove white spaces before validating. vineet Hi guys (and gals) Working on my uni essay, and really struggling here with a resolution to this part of code. Maybe I shouldnt be looking for the answer, but more so on where I am going wrong. What I am meant to do is replace the spaces in sString with the actual word 'space' i.e hello 'everyone' = 'hellospaceeveryone' Any help would be appreciated! Code: function substituteSpaces(aString) { sRet = ''; for (var iA = 0; iA < aString.length; iA++) { if (iA = 0) sRet = sRet + ' '; //sRet = sRet + 'space'; //var nextLetter = aString.charAt(iA); // sRet = sRet + nextLetter; } } sSpace = substituteSpaces('a string with spaces'); alert ("Hello"); Hi everyone, I run a math site and I just recently built a little program to generate math problems. When the user submits the correct answer the program changes the problem and all the steps/hints. Everything works fine except that during the change over there are all these weird blocks (same color as my background) (*FireFox Only). It only lasts for a couple of seconds, but it would be nicer if it smoothly replaced the problem. Here is the test site: http://www.rootmath.org/test/solving-limits The program/practice problem is at the bottom, if you don't know how to solve it you can hit "hint" until it gives you the answer. When you enter the correct answer and then click for a new problem you'll see the funky blocks. Any help/suggestions would be greatly appreciated! Here is the code: writeProblem() is called when the user gets the right answer and asks for another problem: Code: var writeProblem = function(){ //these are neccessary after the first call to writeProblem. $(".steps").hide(); $("#submit_answer").show(); $("#next_problem").hide(); showStep.reset(); //CLEAR "steps_area" var problem_area = document.getElementById('steps_area'); while(problem_area.firstChild){ problem_area.removeChild(problem_area.firstChild); } //Create a limit problem var limit = limits(); limit.setDenominator(rand(6,0)); var denom = limit.getDenominator(); var randInt = 0//rand(3,0); var lim = limit.getType(randInt, denom); var step = lim.step(denom); answer = lim.getAnswer(); //made global so checkAnswer() can access it var x = document.getElementById('problem'); x.innerHTML = addLatex(lim.problem); var problem_area = document.getElementById('steps_area'); //loop over array of steps and print them to steps div var length = step.length; for(var i=0; i<length; i++){ var divTag = document.createElement("div"); divTag.id = "step" + i; divTag.className = "steps"; divTag.innerHTML = step[i]; problem_area.appendChild(divTag); MathJax.Hub.Queue(["Typeset",MathJax.Hub,'step' + i]); } // MathJax Queue for processing latex that javascript filled in MathJax.Hub.Queue(["Typeset",MathJax.Hub,'problem']); } Hi I am trying to make all the cells within a table droppable spaces, using the scriptaculous library. However I am not able to do so, and I am not certain why. The table cells are creating within the javascript. I then try to apply the droppables to the table cells through iteration, through the function when the document loads. It does not seem to be working. The document accesses an external php page and has inline php within a div element. I am uncertain if by having the draggable elements instantiated within the php script, that this would be causing any problem, as I cannot see how this would be, the php draggables all appear to be corresponding to the css in the document. Any help with the droppables would be appreciated. I have set up a css class hover, so that when the draggable passes over the droppable the edges of the droppable area should be turning blue, but this is not happening. Not sure what the problem is. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 3.2//EN"> <HTML> <HEAD> <META name="generator" content="Free Script Editor, see www.freescripteditor.com"> <TITLE>Email Client</TITLE> <link rel="stylesheet" type="text/css" href="http://localhost/email/styles/style1.css"/> <script src="javascript/prototype.js" type="text/javascript"></script> <script src="javascript/scriptaculous.js" type="text/javascript"></script> <script src="javascript/dragdrop.js" type="text/javascript"></script> <script src="javascript/controls.js" type="text/javascript"></script> <script src="javascript/effects.js" type="text/javascript"></script> <script type="text/javascript"> var xmlhttp = false; //check if we are using IE try { //If the javascript version is greater than 5. xmlhttp = new ActiveXObject("Msxml2.XMLHTTP"); alert ("You are using Microsoft Internet Explorer."); } catch(e) { //if not, then use the older active x object. try { //if we are using Internet Explorer xmlhttp = new ActiveXObject("Microsoft.XMLHTTP"); alert("You are using Microsoft Internet Explorer"); } catch (E) { xmlhttp = false; } } //If we are using a non-IE browser, crea a javascript instance of the object if(!xmlhttp && typeof XMLHttpRequest != 'undefined') { xmlhttp = new XMLHttpRequest(); alert ("You are not using Microsoft Internet Explorer"); } function getmessage(inbox_id) { var object = document.getElementById('content'); var server = "getmessage.php?inbox_id=" +inbox_id; xmlhttp.open("GET", server); xmlhttp.onreadystatechange = function() { if(xmlhttp.readyState == 4 && xmlhttp.status == 200) { object.innerHTML = xmlhttp.responseText; } } xmlhttp.send(null); } function addTable() { var dv = document.getElementById("right"); var table = document.createElement("table"); var tbody = document.createElement("tbody"); var x = 0; //create the table rows for(var j =0; j <=2; j++) { var row = document.createElement("tr"); //create the table columns for (var k =0; k<=4;k++) { x++; var cell = document.createElement("td"); var celltext = document.createTextNode(x); cell.appendChild(celltext); cell.setAttribute("className", "droparea"); cell.setAttribute("id", "x"); row.appendChild(cell); } //add the row to the end of the table body tbody.appendChild(row); } table.appendChild(tbody); dv.appendChild(table); table.setAttribute("className", "tbl"); } document.observe("dom:loaded", function() { var dh; var cells = document.getElementsByTagName('td'); for (var z = 0; z <= cells.length; z++) { dh = cells[z].getAttribute('id'); if(dh) { Droppables.add('dh', {accept:'draggable', hoverclass: 'hover'}); } } }); </script> </HEAD> <BODY onload="addTable()"> <div class="container" id="container"> <!--header div - for message 'new', 'reply' --> <div class="header"> <script type="text/javascript" src="buttons/header_nav.js"></script> </div> <!-- end of header div--> <!--Begin the div class left - this will hold the inbox emails for review--> <div class="left"> <?PHP include ($_SERVER['DOCUMENT_ROOT'].'\email\database_connect\connect.php'); $str = "id"; $i = 0; $inbox_query = "select i.inbox_id, i.to, i.subject, i.sent, i.message from inbox as i"; $inbox_result = mysql_query($inbox_query); while($row = mysql_fetch_array($inbox_result)) {//start while trainer query $inbox_id = $row['0']; $to = $row['1']; $subject= $row['2']; $sent = $row['3']; $message = $row['4']; $i++; echo "<div class='draggable' id='$str$i'> $inbox_id $to $sent <a href='#' onclick='getmessage($inbox_id)'>$str$i $subject $message</a> <script type='text/javascript'> new Draggable('$str$i', {scroll: window}); </script> </div>"; }//end while inbox query ?> </div> <!--end left div--> <!--begin the right div - this is the right side of the screen frame for postponed email area--> <div class="right" id="right"> </div> <!--end the right div element--> <!--begin the main content div - this will hold sent message--> <div class="content" id="content" overflow="auto"> </div> <!--end content div--> </div> </BODY> </HTML> |