JavaScript - Function Event Being Uncontrollably Fired...
I'm writing an XML generating app here, and i have come across an interesting problem.
When i click on any part of the body of the document, the function addRow() is being triggered. This is odd, because the only event handler that should ever fire this is a Button that much be clicked, and it is also triggered once when the document is Loaded. The biggest question is, ...why when i click anywhere on the document, is this even being triggered. here's my code (sorry it's a bit long..but copy and paste and you should be able to replicate what i'm getting) Some notes: 1. removing the script tabber.js does not change this error. It still happens 2. removing the onLoad= in the body, and manually adding in the first table cell, and row of the table seems to fix this, however, i need to eventually load a list of table cells from a CSV file. So that workaround won't be sufficient Code: <html> <title>Site Management</title> <script type="text/javascript" src="tabber.js"></script> <link rel="stylesheet" href="example.css" TYPE="text/css" MEDIA="screen"> <script type="text/javascript"> //document.write('<style type="text/css">.tabber{display:none;}<\/style>'); </script> <script type="text/javascript"> var HumidorInnerHTML = [8]; var IntroInnerHTML = [6]; var ImageInnerHTML = [6]; var OthersInnerHTML = [8]; var WatchInnerHTML = [10]; // Intro InnerHTML IntroInnerHTML[0] = "<img src='NoImage.gif' style='height:100px; width:100px;'>"; IntroInnerHTML[1] = "<input type='textbox' id='Intro_Caption" + IntroIndex + "'>"; IntroInnerHTML[2] = "<input type='textbox' value='85' id='Intro_Height" + IntroIndex +"'>"; IntroInnerHTML[3] = "<input type='textbox' value='56' id='Intro_Width" + IntroIndex + "'>"; IntroInnerHTML[4] = "<img src='delete.png' onClick=DeleteRow('" + IntroIndex + "','Intro_Table');>"; IntroInnerHTML[5] = "<img src='add.png' onClick=AddRow('" + IntroIndex + "','Intro_Table');>"; var MyTable; var IntroIndex = 0; var ImageIndex = 0; var WatchIndex = 0; var HumidorIndex = 0; var OthersIndex = 0; function AddRow(index, DIV) { MyTable = document.getElementById(DIV); var newCell; var newRow = MyTable.insertRow(index); for (var i = 0; i < IntroInnerHTML.length; i++) { newCell = newRow.insertCell(i); newCell.innerHTML = IntroInnerHTML[i]; } IntroIndex++; } function Init() { AddRow(1, "Intro_Table"); } function DeleteRow(index, DIV) { MyTable = document.getElementById(DIV); MyTable.deleteRow(index); } function WriteXML() { // Write All XML Files // Display Tab Variables var Display_Small_Image = document.getElementById("Display_Small_Src").value; var Display_Large_Image =document.getElementById("Display_Large_Src").value; var Display_Caption =document.getElementById("Display_Caption").value; var Display_Height = document.getElementById("Display_Width").value; var Display_Width = document.getElementById("Display_Height").value; //var XMLheader = "<?xml version="1.0" encoding="utf-8" standalone="yes"?><images><pic><image>"; var XMLdata = XMLdata + Display_Small_Image + "</image>" + "<caption><![CDATA[" + Display_Caption + "<width>" + Display_Width + "</width>" + "<height>" + Display_Height + "</height>" + "<detailimage>" + Display_Large_Image; var XMLfooter = "</detailimage></pic></images>"; // Write the XML File to the Disk } </script> </head> <body onClick="Init();"> <div class="tabber"> <div class="tabbertab"> <h2>Display</h2> <p> <div> <center><b><font size="5px">Display Options</font></b></center> <br> <table> <tr> <td> <table> <tr> <td>Small Image</td><td><input type="file" id="Display_Small_Src" onChange="SmallImageChanged('Display_Small_Src', 'Display_Image_Small');"></td> </tr> <tr> <td>Full Size Image</td><td><input type="file" id="Display_Large_Src" onChange="SmallImageChanged('Display_Large_Src', 'Display_Image_Large');"></td> </tr> <tr> <td>Caption</td><td><input type="textbox" id="Display_Caption"></td> </tr> <tr> <td>Width</td><td><input type="textbox" id="Display_Width"></td> </tr> <tr> <td>Height</td><td><input type="textbox" id="Display_Height"></td> </tr> </table> </td> <td> <table> <tr> <td> <img src="NoImage.gif" style="height:150px; width: 150px; border: 1px solid red;" id="Display_Image_Small"></td><td> <img src="NoImage.gif" style="height:150px; width: 150px; border: 1px solid red;" id="Display_Image_Large"></td> </tr> </table> </td> </tr> </table> </div> </p> </div> <div class="tabbertab"> <h2>Humidor</h2> <p> <div> <center><b><font size="5px">Humidor Options</font></b></center> <br> <table border="1" id="Humidor_Table"> <tr> <td>Image</td> <td>Caption</td> <td>Height</td> <td>Width </td> <td>Picture 1</td><td>Picture 2</td><td>Remove</td> <td>Add</td> </tr> </table> </div> </p> </div> <div class="tabbertab"> <h2>Image</h2> <p> <div> <center><b><font size="5px">Image Options</font></b></center> <br> <table border="1" id="Image_Table"> <tr> <td>Image</td> <td>Caption</td> <td>Height</td> <td>Width </td> <td>Remove</td> <td>Add</td> </tr> </table> </div> </p> </div> <div class="tabbertab"> <h2>Intro</h2> <p> <div> <center><b><font size="5px">Intro Options</font></b></center> <br> <table border="1" id="Intro_Table"> <tr> <td>Image</td> <td>Caption</td> <td>Height</td> <td>Width </td> <td>Remove</td> <td>Add</td> </tr> </table> </div> </p> </div> <div class="tabbertab"> <h2>Others</h2> <p> <center><b><font size="5px">Others Options</font></b></center> <br> <div> <table border="1" id="Others_Table"> </tr> <td>Image</td> <td>Caption</td> <td>Height</td><td>Width</td><td>Image 1<td>Image 2</td><td>Remove</td><td>Add</td> </tr> </table> </div> </p> </div> <div class="tabbertab"> <h2>Watch</h2> <p> <center><b><font size="5px">Watch Options</font></b></center> <br> <div> <table border="1" id="Watch_Table"> <tr> <td>Preview Image</td> <td>Caption</td> <td>Height</td> <td>Width </td> <td>Image1</td> <td>Image2</td> <td>Image3</td> <td>Image4</td> <td>Remove</td> <td>Add</td> </tr> </table> </div> </p> </div> </div> <br> <center> <input type="button" value="Save" onClick="WriteXML();"> </center> </body> </html> Similar Tutorialsis it possible to capture the control.event or element.event that was fired to invoke the onbeforeunload event. for example, if a button is clicked and it causes the onbeforeunload event to fire can i determine which button was clicked. thanks Hi i am using the following code to load a part of page dynamically using jquery Code: loadNextBackInPage_URL = null; function callBackFunctionLoadNextBackInPage(data) { //alert(data); $("#left").fadeTo(100,1); var data = $(data).find( '#left' ); $("#left").html(data); if(supports_history_api()) { history.pushState(null, null, loadNextBackInPage_URL); window.addEventListener("popstate", function(e) { alert('s'); loadNextBackInPage(location.pathname); }); } else { } } function loadNextBackInPage(url,parm) { //alert(url); loadNextBackInPage_URL = url; $("#left").fadeTo(100,.2); $.post(url,parm,callBackFunctionLoadNextBackInPage,'html'); } The loading part and even changing the browser URL is working. but why is the PoP state function being fired multiple times? I call loadNextBackInPage() originally through an onclick function. I was working on a tutorial for some ajax uploading stuff and I ran across a new function syntax I don't recognize. I am not a Javascript pro, but I am not a newbie either. here is the code I am working on: Code: function handleFileSelect(e){ var files = e.target.files; var output = []; for(var i=0,f;f=files[i];i++){ if(f.type.match('image.*')){ var reader = new FileReader(); reader.onload = (function(theFile){ return function(e){ var span = document.createElement('span'); span.innerHTML = ['<img class="thumb" src="',e.target.result,'" title="',theFile.nbame,'" />'].join(''); document.getElementById('list').insertBefore(span,null); }; })(f); reader.readAsDataURL(f); } } document.getElementById('list').innerHTML = '<ul>'+output.join('')+'</ul>'; } document.getElementById('files').addEventListener('change',handleFileSelect,false); To be a little more clear, the code in question is that is the very middle. The syntax I don't understand is: Code: class.event = (function(arguments){ //stuff you put in a function... })(more Arguments?); I tried to customize a simple one to learn for myself and I wrote this: Code: var a = 'A'; var b = 'B'; test = (function(t){ alert(t); alert(b); })(b); test(a); The browser would alert 'B' and that's it. The console would tell me that 'test is not a function.' OK, so I am confused. The topmost code works. What I am wondering is what the syntax is called for creating a function (or event listener?) that way, and how it works. Although if I new what it was called I could just google how it works. Hi, I am trying to fire a mouse event in IE at a particular coordinate. All the coordinates are set right before firing the event. But when the event gets fired, the client point gets changed and gets the value same as offset point. i.e., I created a mouse event with ClientPoint = (583,438) , offset= (585,481) and screen = (585,589). The event when it gets fired from the browser however has the client point as (585,481) - the rest are fine though. Can someone tell me how can I reliably fire a mouse event at a particular client point in IE? TIA srd The following coding works in Konqueror 3.5.10 on Ubuntu 8.04.3 LTS but not on Firefox 3.0.10 Linux/3.5.7 XP, Opera 10.10 Linux or IE8 XP. I can't see why but it may be to do with the recursion (showtable calls onclick calls addit which calls showtable ...). Somehow it is not seeing the addit routine the second time round. It is meant just to add a line. Eventually it needs to be a complex table but this is for illustration. There are other ways to solve this but this would be the simplest - if it worked! What happens is that one line is added OK but then it chokes. This is what makes me think it is the recursion but I can't see otherwise how to make it write the updated text. I realise I should have a document.close() in it as well and I have tried adding <![CDATA[ ... ]]> as well. Other than in Konqueror, it gives an error message saying object not found (in IE8) or more explicitly: Code: function onclick(event){ addit(4); } with 'addit is not defined' in Firebug. In Konqueror it works sweetly. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <head> <script language='Javascript' type='text/javascript'> if(typeof(sections) == 'undefined'){ var sections=['Text 0','Text 1','Text 2']; } function addit(ilocal){ sections.splice(sections.length,0,'Text '+ilocal); showtable(); } function showtable(){ var i,j,ip1; for(i=0;i<sections.length;i++){ ip1=i+1; document.write('Section ',i,': ',sections[i],'<br>'); } document.write("<input type='button' value='Add' onClick='addit(",ip1,")' /><br>"); for(j=0;j<sections.length;j++){document.write(sections[j]," ");} } </script> </head><body> <script language='Javascript' type='text/javascript'> showtable(); </script> </body> </html> Clues would be very much appreciated - my baldness coefficient is increasing daily! Hello im trying to make a drop down for my store, so that onchange the price of the option is displayed and my paypal buttons variables are changed. I cant get the "total" function to call when the selection of the drop down is changed. please help iv'e been looking around for a week and still havent fixed it. My event handler sets on load <body onload="x.onchange=function(){total();}"> heres my script Code: <script type="text-JavaScript"> "use strict"; /*document.getelementbyid("ddm").onchange = total;*/ var price; var title; var x = document.getelementbyid("ddm"); var size_prices= new Array(); size_prices["cards"]=18; size_prices["5x7sm"]=20; size_prices["5x7dm"]=25; size_prices["8x10sm"]=30; size_prices["8x10dm"]=35; size_prices["16x20sm"]=45; size_prices["16x20dm"]=50; function total() { y = size_prices[x.value]; document.getelementbyid("total").innerhtml = "$" + y + ".00"; title = "image title" + (x.value); document.getelementbyid("title").setAttribute("value", title); document.getelementbyid("price").setAttribute("value", y); } function verify() { } </script> here is the code for the select and the paypal button Code: <form action=""> <select name="sizes" id="ddm"> <option value="_">Please chose a size</option> <option value="cards">cards</option> <option value="5x7sm">5x7 single mat</option> <option value="5x7dm">5x7 double mat</option> </select> </form> Code: <form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post" onsubmit="verify()"> <input type="hidden" name="business" value="kin@kinskards.tcom" /> <input type="hidden" name="cmd" value="_cart" /> <input type="hidden" name="add" value="1" /> <input type="hidden" id="title" name="item_name" value="Candle" /> <input type="hidden" id="price" name="amount" value="3.95" /> <input type="hidden" name="currency_code" value="USD" /> <input type="image" name="submit" src="https://www.paypal.com/en_US/i/btn/btn_cart_LG.gif" alt="paypal" /> <img alt="" border="0" width="1" height="1" src="https://www.paypal.com/en_US/i/scr/pixel.gif" /> </form> Hello! I'm working with nested functions and trying to pass a 'this' value to an anonymous being used in an assignment for an event listener. Here's the basics of my code: Code: <div id='abc'></div> <script type='text/javascript'> var abc = function () { this.myFunction = function() { var myObj myObj = document.createElement("input"); myObj.setAttribute("type", "button"); myObj.setAttribute("value", "Click Me"); myObj.addEventListener("click", function () { this.doDing(); }, false); document.getElementById('abc').appendChild(myObj); } this.doDing = function () { alert('ding'); } } var myInstance = new abc(); myInstance.myFunction(); </script> So, this should plop a button inside our DIV and when clicked I'd like it to run the alert-ding; unfortunately it seems to want to run the function as defined under the buttons object which doesn't work out too well. Any suggestions? Thanks! HTML CODE BELOW (JAVASCRIPT CODE FOLLOWS); Code: <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8"> <title>Text Object value Property</title> <script type="text/javascript" src="../jsb-global.js"></script> <script type="text/javascript" src="jsb-11-02.js"></script> </head> <body> <h1>Text Object value Property</h1> <form id="UCform" action="make-uppercase.php"> <p> <input type="text" id="converter" name="converter" value="sample"> </p> </form> </body> </html> This program below switches what is entered into the text filed to caps when hitting the enter button or the tab button. Can someone explain to me why it is not working. The answer would be helpful to a newbie who's trying hard to learn the fundamentals... Code: // initialize when the page has loaded window.onload = initialize; var oInput; // (global) input field to make uppercase // apply behaviors when document has loaded function initialize() { // do this only if the browser can handle DOM methods if (document.getElementById) { // apply event handler to the button oInput = document.getElementById('converter'); if (oInput){ var event = oInput.onchange; upperMe(event); } // apply event handler to the form var oForm = document.getElementById('UCform'); if (oForm) { var event = oForm.onsubmit; upperMe(event); } } } // make the text UPPERCASE function upperMe(evt) { // consolidate event handling if (!evt) evt = window.event; // set input field value to the uppercase version of itself var sUpperCaseValue = oInput.value.toUpperCase(); oInput.value = sUpperCaseValue; // cancel default behavior (esp. form submission) // W3C DOM method (hide from IE) if (evt.preventDefault) evt.preventDefault(); // IE method return false; } Hello, Is it possible to set an html element's (created through HTML DOM's createElement() method) 'onclick' attribute's value to a Javascript function which requires a parameter, passing a variable to it at the same time? I have the following Javascript code: Code: var parentDiv = document.getElementById("subscribers"); var stubSpan = document.createElement("span"); stubSpan.id = "opentok_subscriber_" + stream.streamId; stubSpan.onclick = showStreamInFullScreenMode(stream); parentDiv.appendChild(stubSpan); 'stream' in the bolded line is a parameter variable of the function that the above code is in, and I'm trying to pass it to another function using an onclick event. Can this be done, or am I crazy to be even trying to do this? Thanks in advance. I have the following javascript function: [ function addNewWindowEvent(evType, fn) { if (window.addEventListener) { this.addEventListener("load", fn, false); return true; } else if (window.attachEvent) { var onload = "onload" this.attachEvent(onload, fn); return true; } else { return false; } } ] which is giving me a an exception every time a page on our site loads. The actual exception in firefox is this: uncaught exception: [Exception... "Could not convert JavaScript argument" nsresult: "0x80570009 (NS_ERROR_XPC_BAD_CONVERT_JS)" location: "JS frame :: https://cms-dev.stchas.edu/global/js/hdvscripts.js :: addNewWindowEvent :: line 5" data: no] and I'm not sure exactly what it's complaining about. I'm relatively new to javascript so diagnosing and fixing this problem has me quite puzzled, and so far I have been unable to find anything helpful when I try and google for information on this. I would appreciate any help or suggestions. Thanks. henryv Hello all, and thank you for your coments, I want to preserve a 16/9 aspect ratio to the window after any resize, making the width a function of the height. As I have a window.resizeTo() inside the window.onresize event function, the infinite loop is served. How may I quit it? Code: <html><head><title>Title</title><script languaje="javascript"> const c_ra=16/9; window.onresize = function WindowReSize() { var myWidth = 0, myHeight = 0; if( typeof( window.innerWidth ) == 'number' ) { //Non-IE // myWidth = window.innerWidth; myHeight = window.innerHeight; } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) { //IE 6+ in 'standards compliant mode' // myWidth = document.documentElement.clientWidth; myHeight = document.documentElement.clientHeight; } myWidth = Math.floor(myHeight*c_ra); window.resizeTo(myWidth,myHeight); // ** CAUTION resize event in a onresize event handler ! }; </script></head><body><p>Hello World</p></body></html> Hi forum, I am trying to attach an event to a dynamically produced button, and then use stopPropagation and preventDefault. Code: function chapter12_nodeOne() { //create an element var element = document.createElement('input'); //set some attributes element.setAttribute('type', 'button'); element.setAttribute('value', 'submit'); element.setAttribute('id', 'myBtn'); //appendd the element into a DIV document.getElementById('myDiv').appendChild(element); //uses EventUtil to attach an event listener EventUtil.addHandler(element, 'click', function() { alert('event attached'); }); var flag = confirm('prevent default behavior of button?'); if (flag) { var el = document.getElementById('myBtn');/////////////////////////(1) var ev = el.onclick; } } var EventUtil = { addHandler: function(element, type, handler) { //check if the element and the browser support DOM Level 2 event attachment //if the user is not browsing with IE if (element.addEventListener) { element.addEventListener(type, handler, false); } //if user is browsing with IE else if (element.attachEvent) { element.attachEvent("on" + type, handler); } //if user is using a browser that only supports DOM Level 0 event attachment else { element["on" + type] = handler; } }, removeHandler: function(element, type, handler) { //check if the element and the browser support DOM Level 2 event attachment //if the user is not browsing with IE if (element.removeEventListener) { element.removeEventListener(type, handler, false); } //if user is browsing with IE else if (element.detachEvent) { element.detachEvent("on" + type, handler); } //if user is using a browser that only supports DOM Level 0 event attachment else { element["on" + type] = null; } } }; But when debugging I see under el on the line marked with (1) that the onclick event is null. What am I doing wrong?! PS:the event is attached, when I click on the button I get an alert message I have a ondrag event handler and in that I am trying to retrieve e.ClientX but it always return 0 in Mozilla. Works fine in IE though. How can retrieve the clientX and clientY in ondrag event? Hi Chaps, I have a PHP form with one input and a button. A jQuery script ('loading' animated gif) is triggered on the click of the submit button. I also have a Spry Validation field linked to the input. At the moment, if the validation is triggered, the animated gif continues and won't stop. The furthest I've managed to get with it, is to click the validation message to stop the animation, but what I'm really after is to stop the animation when the validation is visible/triggered, but I can't find a suitable Event. Code: <script type="text/javascript"> $(function() { $("#button_download") .click(function() { }) .throbber(); $("#sprytextfield1") .click(function(sprytextfield1) { $.throbberHide(); }) }); </script> If someone can point me in the right direction, that would be sweet. HI, i know very little about javascript, just enough to get me into trouble actually lol. Here is what im working with. I have a custom Instant messenger for members. It uses embed object macromedia as well as javascript to diplay the window and send messages. What i want to do is simply add an onchange that when one person is typing it shows they are typing (ie xxxxx is typing....) My experience is in php and html and i looked thru the script and the javascript functions but im not sure what im looking for exactly. Do i need to have access to the swf or fla file and be able to edit them to do this? I dont see any form inputs or i would know exactly where to put the onchange lol. Im guessing the input is in the swf or fla file not sure how that works. what im guessing is that in the embed or the object tags (ill play with it) i can put something like Code: document.write('test on change\n'); i think i need to wrap that in doc write script type=javascript in quotes so it parses. If i can get that text to show up inside the IM where i want it then i can try to figure out how to set focus on box and recongize onchange and do some testing. I think i might even be able to doc write the onchange command but not sure. Thanks I can't seem to get the event listener to run an event when I focus on the text field with the ID username. JavaScript: Code: function listener_loginForm() { var fields = Array("username","password"); for ( j = 0; j < fields.length; j++ ) { var objs = document.getElementById(fields[j]); for ( var i = 0; i < objs.length; ++i ) { var elm = objs [ i ]; elm.onblur = function() { display_text_bg(this); }; if (elm.Id = "password") { elm.onfocus = function() { switch_field(this); }; } } } } //This function attaches events to elements. var addEvent = function( elm, evt, fun ) { if ( elm.addEventListener ) { elm.addEventListener( evt, fun, false ); } else if ( elm.attachEvent ) { elm.attachEvent( 'on' + evt, fun ); } else { elm [ 'on' + evt ] = fun; } }; addEvent ( window, "load", listener_loginForm ); //Put text in fields if there is not data, also switch text field to password field //when focused on. Switch back to text field if no text is entered. function display_text_bg(obj) { alert("remove text"); } function switch_field(obj) { alert("switch"); } HTML: Code: <form name="login" class="login"> <label for="username">Username: </label><br /> <input type="text" name="username" id="username" /> <br /><br /> <label for="password">Password: </label><br /> <input type="text" name="password" id="password" /> <br /><br /> <label for="remember">Remember Me? </label><br /> <br /> <span class="remember"> <span class="text">Never</span> <input type="hidden" value="never" name="rememberme" /> <ul> <li>Never</li> <li>24 Hours</li> <li>1 Week</li> <li>Always</li> </ul> </span> </form> Hello All, How can i want to capture onscroll event in Javascript ? Thanks in advance. Dammit, for some reason this script has stopped working :/ When I click the links with the ID's of "login_dialog" and "register_dialog" a div should be shown... I'm using an event listener to do this. Code: function listener_items() { //Text field background addEvent(document.getElementById('input_username'), "click", add_username_password); addEvent(document.getElementById('input_username'), "blur", remove_username_password); addEvent(document.getElementById('input_password'), "click", add_username_password); addEvent(document.getElementById('input_password'), "blur", remove_username_password); //Switch between forms addEvent(document.getElementById('dialog_login'), "click", login_dialog_login); addEvent(document.getElementById('dialog_register'), "click", login_dialog_register); addEvent(document.getElementById('dialog_recovery'), "click", login_dialog_recovery); //Display Dialog addEvent(document.getElementById('login_dialog'), "click", navbar_login); addEvent(document.getElementById('register_dialog'), "click", navbar_register); //Close Dialog addEvent(document.getElementById('close_dialog'), "click", login_dialog_close); } //Login dialog, login form input fields background text var add_username_password = function() { add_input_text(this); }; var remove_username_password = function() { remove_input_text(this); }; //Login dialog buttons var login_dialog_login = function() { display_form('login'); }; var login_dialog_register = function() { display_form('register'); }; var login_dialog_recovery = function() { display_form('recovery'); }; //Close dialog var login_dialog_close = function() { display_dialog('login', 'hidden'); }; //Navigation bar buttons var navbar_login = function() { display_dialog('login', 'visible'); }; var navbar_register = function() { display_dialog('register', 'visible'); }; //This function attaches events to elements. var addEvent = function( elm, evt, fun ) { if ( elm.addEventListener ) { elm.addEventListener( evt, fun, false ); } else if ( elm.attachEvent ) { elm.attachEvent( 'on' + evt, fun ); } else { elm [ 'on' + evt ] = fun; } }; addEvent ( window, "load", listener_items ); //Display/Hide login dialog function display_dialog(dialog, fun) { //Define the active menu item style var active_style = "border-right-width:3px; width:113px; border-right-color:#33CCFF; color:#FFFFFF;"; //Creat array with all forms var formsHide = Array("login","register","recovery"); var i = 0; document.getElementById('wrapper').setAttribute('style', 'visibility:' + fun); for ( i = 0; i < formsHide.length; i++ ) { if ( formsHide[i] == dialog && fun == 'visible' ); document.getElementById("dialog_" + dialog).setAttribute('style', active_style); document.getElementById(formsHide[i] + "_form").setAttribute('style', 'visibility:visible'); formsHide.splice(i, 1); } document.getElementById(formsHide[i] + "_form").setAttribute('style', 'visibility:hidden'); } } //Put text in fields if there is not data, also switch text field to password field //when focused on. Switch back to text field if no text is entered. function add_input_text(obj) { var id = obj.id.split("input_"); document.getElementById(id[1]).innerHTML = ''; } function remove_input_text(obj) { if (obj.value.length == 0) { var id = obj.id.split("input_"); var id2 = id[1].substr(0, 1).toUpperCase() + id[1].substr(1); document.getElementById(id[1]).innerHTML = id2; } } function display_form(form) { //Define the active menu item style var active_style = "border-right-width:3px; width:113px; border-right-color:#33CCFF; color:#FFFFFF;"; var forms = Array("login", "register", "recovery"); for ( c = 0; c < forms.length; c++ ) { if ( forms[c] == form ) { document.getElementById( forms[c] + "_form" ).style.visibility = "visible"; document.getElementById("dialog_" + forms[c]).setAttribute('style', active_style); document.getElementById("dialog_" + forms[c]).setAttribute('class', 'overlay_table' + ' ' + forms[c] + ' active'); forms.splice(c, 1); } } for ( c = 0; c < forms.length; c++ ) { document.getElementById("dialog_" + forms[c]).setAttribute('style', '') document.getElementById( forms[c] + "_form" ).style.visibility = "hidden"; document.getElementById("dialog_" + forms[c]).setAttribute('class', 'overlay_table' + ' ' + forms[c]); } } HTML: Code: <span><a href="#" id="login_dialog" style="color:#33CCFF;">Login</a></span> <span><a href="#" id="register_dialog" >Register</a></span> Hi, New to javascript. Doing web page with ASP/VB.NET. Have text boxes for UI on page. Two command buttons - Submit (for db update) and Cancel. I need the Cancel button to prompt the user to verify cancellation. Need OK/Cancel buttons on alert. If user selects Cancel-no action. If user selects OK then I want the text boxes cleared of user text input and focus returned to first text box. I think this may be the code but do not know how to apply it. function Clear() { var res=window.confirm("Please confirm cancellation-text boxes will be cleared"); if(res==true) { document.getElementById("StrtDte").value=""; document.getElementById("EndDte").value=""; document.getElementById("txtProjRegHrsAl").value=""; document.getElementById("txtProjOTHrsAl").value=""; document.getElementById("ddlRAS").focus(); } } Is this code valid or invalid for the events I need? How do I set it to fire when user clicks the ASP Cancel button? Thanks, John Hi I'm a newbie. Please help me. I'm using Joomla. I've got a dropdown which reads the filename from the database. When the user selects it I want an onchange event to open the pdf. I've been at it for 2 days now. Code: <?php $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("metnet", $con); $sql="SELECT * FROM newsletter"; $result = mysql_query($sql); echo "<form method='post'>"; $dropdown = "<select name='sname' onChange='location(this.form.sname)' >"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['fpath']}'>{$row['fpath']}</option>"; } $dropdown .= "\r\n</select>"; echo $dropdown; ?> |