JavaScript - Constructor Function Question.
I have a dice simulator.
Basically, a user enters how many sides they want on their die, and then I digitally roll 2 of them. And produce the output in a document.writeln. I think I'm having trouble with the this.sides in the constructor function (in the head section). Also, I'm getting a syntax error in Safari : 25TypeError: 'null' is not an object (evaluating 'element.value') Am I not suppose to put the variable in the constructor function? Any help would be appreciated. <head> var element = document.getElementById("number"); var sides = element.value; function Die( ) { this.sides = sides; this.roll = function( ) { return parseInt((Math.random( ) * 1000) % this.sides) + 1; } } </script> </head> <body> <h1>Adam's Dice Rolling Game!</h1><br/> <form action="" method="post"> <p> <input type="text" name="number" id="number"/> </p> <p> <input type="button" value="Roll the dice!" id="roll_me"/> </p> </form> <script type="text/javascript"> var d = new Die( ); d.sides = sides; var rolled_value = d.roll( ); var r1 = document.getElementById( "roll_me" ); r1.onclick = function Die () { document.writeln ( d.roll () ); } </script> Similar Tutorialshi, i'm currently stumped by the following code. what's the point of using x.constructor.prototype? (highlighted in red) why not directly use x.prototype.classname to check whether 'classname' property is in this class? thx in advance Code: function getType(x) { // If x is null, return "null" if (x == null) return "null"; // Next try the typeof operator var t = typeof x; // If the result is not vague, return it if (t != "object") return t; // Otherwise, x is an object. Use the default toString( ) method to // get the class value of the object. var c = Object.prototype.toString.apply(x); // Returns "[object class]" c = c.substring(8, c.length-1); // Strip off "[object" and "]" // If the class is not a vague one, return it. if (c != "Object") return c; // If we get here, c is "Object". Check to see if // the value x is really just a generic object. if (x.constructor == Object) return c; // Okay the type really is "Object" // For user-defined classes, look for a string-valued property named // classname, that is inherited from the object's prototype if ("classname" in x.constructor.prototype && // inherits classname typeof x.constructor.prototype.classname == "string") // its a string return x.constructor.prototype.classname; // If we really can't figure it out, say so. return "<unknown type>"; } I need to detect the "name" of the constructor of an object. For example, myArray.constructor === Array is true, but I want something where that === 'Array' is true. I've heard of Object.constructor.name, but it's not widely compatible. Any ideas (preferably without involving regular expressions)? Thanks in advnce, Julian I had read from books that the constructor property of object is inherited from its prototype. And the prototype can be changed dynamically. New property can be added to or deleted from object even it was created before the prototype change. But I got confused on below codes. Code: function A() { this.title = "A"; } function B() { this.title = "B"; } document.write("<br>"); var b = new B(); document.write(b.constructor); document.write("<br>"); document.write(B.prototype.constructor); document.write("<br>"); B.prototype = new A(); document.write(b.constructor); // Suppose to output "function A() ..." document.write("<br>"); document.write(B.prototype.constructor); document.write("<br>"); B.prototype.constructor = B; document.write(b.constructor); document.write("<br>"); document.write(B.prototype.constructor); document.write("<br>"); But the actual result (both IE and firefox) is Code: function B() { this.title = "B"; } function B() { this.title = "B"; } function B() { this.title = "B"; } function A() { this.title = "A"; } function B() { this.title = "B"; } function B() { this.title = "B"; } Please help me. thanks. How to extend the constructor for the date object of the javasccript so that whenever a call is made to the constructor, I want to perform a particular action? Basically how to define wrappers for default javascript methods or objects like Date() so that I can perform some action and then invoke the original method? So basically if I have something like var a = new Date(); I want it to (say) alert the value of the date everything Date() is called and then execute the default date constructor. TIA Hi - In am learning Javascript and trying to understand why, the following line : Code: arguments.callee.superclass cannot be replaced by : Code: this.constructor.superclass In the following code sample : ( the explanation given is that if someone creates a subclass of PositionedRectangle, then this.constructor will refer to the new subclass constructor, not to PositionedRectangle - but why? 'this' here to my knowledge represents the object 'PositionRectangle' and if not I can't understand why not. ) Code: // Here is a simple Rectangle class. // It has a width and height and can compute its own area function Rectangle(w, h) { this.width = w; this.height = h; } Rectangle.prototype.area = function( ) { return this.width * this.height; } // Here is how we might subclass it function PositionedRectangle(x, y, w, h) { // First, invoke the superclass constructor on the new object // so that it can initialize the width and height. // We use the call method so that we invoke the constructor as a // method of the object to be initialized. // This is called constructor chaining. PositionRectangle.superclass = Rectangle; arguments.callee.superclass .call(this, w, h); // Now store the position of the upper-left corner of the rectangle this.x = x; this.y = y; } // Create a prototype for the subclass that inherits from the prototype // of the superclass. function heir(p) { function f(){} f.prototype = p; return new f(); } PositionRectangle.prototype = heir(Rectangle.prototype); PositionRectangle.prototype.constructor = PositionRectangle; Hi All, Why is the Option constructor converting my text as follows? text = ' 1:30 pm' Option tag that gets generated: <option value="10">&nbsp;&nbsp;1:30 pm</option> How do I suppress the conversion of the & to & by the constructor? I've tried escaping the & but that's a no go. Thanks in advance for any help on this. JD I am trying to understand why I had an error, or why my solution worked. In my HTML I had: Code: <script language="JavaScript" type="text/javascript" src="Book.js"></script> <script language="JavaScript" type="text/javascript" src="Book_TEST.js"></script> Book.js said: Code: function Book(title, author) { this.title = title; this.author = author; } Book.prototype.toString = function() { return '"' + this.title + '" by '+ this.author; }; var Book = new Book ("John", "Dough"); alert (Book); // displays "John Dough" And, predictably, at this stage, the code worked. Book.js said: Code: var myBook = new Book ("JavaScript Tutorials", "Herong Yang"); However, at this point the JavaScript would crash and I'd get an error "Error: Book is not a constructor javascript." I drove myself nuts trying to figure out why the code wasn't working at this later point. Eventually, I copied another object: Code: /* * Person class */ /** * Person constructor * * @param {String} first * The person's first name * @param {String} last * The person's last name */ function Person(first, last) { this.first = first; this.last = last; } /** * Create a string representation of this object * * @return {String} A string representation of this object */ Person.prototype.toString = function() { return this.first + " " + this.last; }; /* var person = new Person ("John", "Dough"); alert (person); // displays "John Dough" */ and then used find and replace to swap {Person, first, last} with {Book, title, author}, resulting in: Code: /* * Book class */ /** * Book constructor * * @param {String} title * The Book's title * @param {String} author * The Book's author */ function Book(title, author) { this.title = title; this.author = author; } /** * Create a string representation of this object * * @return {String} A string representation of this object */ Book.prototype.toString = function() { return '"' + this.title + '" by '+ this.author; }; var Book = new Book ("John", "Dough"); alert (Book); // displays "John Dough" Now, the code worked fine in both script. (i.e., no more error.) So far as I can tell, the only differences between the first and next version of Book.js are the comments and the whitespace. Am I missing something? Can the comments or whitespace somehow effect the logic with which this code has been executing? If I get an error like this again, is there an easier/better way to fix it than to essentially retype the code? Thanks in advance for helping me to understand this. $.fn.superfish = function(op) { } So I see here that a function is being declared and the name of the function is '$.fn.superfish'. Is there any special meaning at all behind the $ in this situation? Hello I have a question which has been bugging me for a while now so have decided to ask it on CF. In PHP you can use the '&' symbol as a function operator for example like so. PHP Code: function demoFunc(&$output='') { for($i=1;$i<count(func_get_args());$i++) { $output .= ' '.func_get_arg($i); } $output = trim($output); } As you can see the '&' symbol was used in the argument section to allow the function to be used like this demoFunc($output,'hello','world'); print $output; My question is how can I do this in JavaScript to do the same thing like use the variable used in the function argument section and use it like it would be used in PHP? Thank you - DJCMBear Here is my webpage (don't laugh!). If you click on Espanol it translates the page to Spanish. English is set up differently and it works too. Please tell me why clicking Spanish works but not French, Portuguese, etc. Code: <body> <p align="center"> <b id='Spanish1'><b id='French1'><b id='Portuguese1'><b id='German1'><b id='Danish1'><b id='Dutch1'><b id='Finnish1'><b id='Swedish1'><b id='Norwegian1'></b>Change Language:</b></b></b></b></b></b></b></b> <input type='button' onclick='TranslateToSpanish()' value='Espanol' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToFrench()' value='Francais' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToPortuguese()' value='Portuguese' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToGerman()' value='Deutsch' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToDanish()' value='Dansk' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToDutch()' value='Nederlands' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToFinnish()' value='Suomi' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToSwedish()' value='Svensk' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type='button' onclick='TranslateToNorwegian()' value='Norske' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <a href='http://www.luxe-bux.com/the-link-of-the-same-page-viewer-is-on-so-it-will-refresh-the-page-back-to-english'><input type='button' value='English' style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"></a> <div class="header" onclick="location.href='http://www.luxe-bux.com';" style="cursor: pointer"> <img src="http://i770.photobucket.com/albums/xx344/colorscolors123/0546d64a.png"> Luxe Bux <font size="2"><b id='Spanish2'><b id='French2'><b id='Portuguese2'><b id='German2'><b id='Danish2'><b id='Dutch2'><b id='Finnish2'><b id='Swedish2'><b id='Norwegian2'></b>Luxuries For Less!</b></b></b></b></b></b></b></b></b><br>.</font></div> <div class="test"> <div class="allthestuff"> <h1><!-- Atomz HTML for Search --> <form method="get" action="http://search.atomz.com/search/" rel="nofollow" target="foo" onSubmit="window.open('', 'foo', 'width=1200,height=500,status=yes,resizable=yes,scrollbars=yes')"> <input type="hidden" name="sp_a" value="sp1004432f"> <p align="center"><font color=ffffff size=3><b id='Spanish3'><b id='French3'><b id='Portuguese3'><b id='German3'><b id='Danish3'><b id='Dutch3'><b id='Finnish3'><b id='Swedish3'><b id='Norwegian3'>Search Luxe Bux:</b></b></b></b></b></b></b></b></b></font> <input size="30" name="sp_q" style="background-color: #cb672d; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011"> <input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Find it!"><b id='Spanish4'></b><b id='French4'></b> <input type="hidden" name="sp_p" value="all"> <input type="hidden" name="sp_f" value="UTF-8"></p> </form> </h1> <div class="container"> <ul> <li><a class="nav" href="http://www.luxe-bux.com"><b class="ShopNow"><b id='Spanish5'><b id='French5'><b id='Portuguese5'><b id='German5'><b id='Danish5'><b id='Dutch5'><b id='Finnish5'><b id='Swedish5'><b id='Norwegian5'>Shop Now!</b></b></b></b></b></b></b></b></b></b></a></li> <li><a class="nav" href="http://www.luxe-bux.com"><b id='Spanish6'><b id='French6'><b id='Portuguese6'><b id='German6'><b id='Danish6'><b id='Dutch6'><b id='Finnish6'><b id='Swedish6'><b id='Norwegian6'>Reviews of Luxe Bux</b></b></b></b></b></b></b></b></b></a></li> <li><a class="nav" href="http://www.luxe-bux.com"><b id='Spanish7'><b id='French7'><b id='Portuguese7'><b id='German7'><b id='Danish7'><b id='Dutch7'><b id='Finnish7'><b id='Swedish7'><b id='Norwegian7'>FAQ/Return Policy/More Info</b></b></b></b></b></b></b></b></b></a></li> <li><a class="nav" href="http://www.luxe-bux.com"><b id='Spanish8'><b id='French8'><b id='Portuguese8'><b id='German8'><b id='Danish8'><b id='Dutch8'><b id='Finnish8'><b id='Swedish8'><b id='Norwegian8'>Contact</b></b></b></b></b></b></b></b></b></a></li> </ul> </div> <br> <div class="IdeaColor"> <div class="marginspacer"> <p><img alt="small-euro-currency-sign.jpg" style="padding: 15px; border: 2px solid #000000;" src="http://www.luxebux.com/sitebuildercontent/sitebuilderpictures/.pond/desaturated-and-resized-only.jpg.w180h269.jpg" align="right" vspace="0" hspace="5"></p> <p> <b id='Spanish9'><b id='French9'><b id='Portuguese9'><b id='German9'><b id='Danish9'><b id='Dutch9'><b id='Finnish9'><b id='Swedish9'><b id='Norwegian9'> <font size="4">Here's what our customers are saying...<br><br></font><br /><font size="3"> "THANK YOU VERY MUCH NICE DEALING WITH"<br> "Exceptional service overall and great care in packaging! I will buy again! A++"<br> "Exactly as advertised! Fast shipping(always takes longer to Canada) A+" <br> "great online sellers. highly recomended! will buy from again"<br> "Arrived in record time and packaged well. Thanks"<br> "Quick"<br> "Great service, very fast shipping. I will definitely buy from them again"<br> "Arrived quickly as described!!"<br><br><br><br><br><br></p> </b></b></b></b></b></b></b></b></b> </div></div> <table height="100"><tr><td></td></tr></table> <table width=100% height=20px bgcolor="#f5e9c3"> <tr><td></td></tr> </table> <script type="text/javascript"> function TranslateToSpanish() { document.getElementById('Spanish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Spanish2').innerHTML = 'Lujos para menos!'; document.getElementById('Spanish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Spanish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Spanish5').innerHTML = 'Tienda ahora!'; document.getElementById('Spanish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Spanish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Spanish8').innerHTML = 'Contacto'; document.getElementById('Spanish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p>'; } </script> <script type="text/javascript"> function TranslateToFrench() { document.getElementById('French1').innerHTML = 'Lengua del cambio:'; document.getElementById('French2').innerHTML = 'Lujos para menos!'; document.getElementById('French3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('French4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('French5').innerHTML = 'Tienda ahora!'; document.getElementById('French6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('French7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('French8').innerHTML = 'Contacto'; document.getElementById('French9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToPortuguese() { document.getElementById('Portuguese1').innerHTML = 'Lengua del cambio:'; document.getElementById('Portuguese2').innerHTML = 'Lujos para menos!'; document.getElementById('Portuguese3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Portuguese4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Portuguese5').innerHTML = 'Tienda ahora!'; document.getElementById('Portuguese6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Portuguese7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Portuguese8').innerHTML = 'Contacto'; document.getElementById('Portuguese9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToGerman() { document.getElementById('German1').innerHTML = 'Lengua del cambio:'; document.getElementById('German2').innerHTML = 'Lujos para menos!'; document.getElementById('German3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('German4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('German5').innerHTML = 'Tienda ahora!'; document.getElementById('German6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('German7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('German8').innerHTML = 'Contacto'; document.getElementById('German9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToDanish() { document.getElementById('Danish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Danish2').innerHTML = 'Lujos para menos!'; document.getElementById('Danish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Danish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Danish5').innerHTML = 'Tienda ahora!'; document.getElementById('Danish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Danish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Danish8').innerHTML = 'Contacto'; document.getElementById('Danish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToDutch() { document.getElementById('Dutch1').innerHTML = 'Lengua del cambio:'; document.getElementById('Dutch2').innerHTML = 'Lujos para menos!'; document.getElementById('Dutch3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Dutch4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Dutch5').innerHTML = 'Tienda ahora!'; document.getElementById('Dutch6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Dutch7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Dutch8').innerHTML = 'Contacto'; document.getElementById('Dutch9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToFinnish() { document.getElementById('Finnish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Finnish2').innerHTML = 'Lujos para menos!'; document.getElementById('Finnish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Finnish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Finnish5').innerHTML = 'Tienda ahora!'; document.getElementById('Finnish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Finnish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Finnish8').innerHTML = 'Contacto'; document.getElementById('Finnish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToSwedish() { document.getElementById('Swedish1').innerHTML = 'Lengua del cambio:'; document.getElementById('Swedish2').innerHTML = 'Lujos para menos!'; document.getElementById('Swedish3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Swedish4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Swedish5').innerHTML = 'Tienda ahora!'; document.getElementById('Swedish6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Swedish7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Swedish8').innerHTML = 'Contacto'; document.getElementById('Swedish9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> <script type="text/javascript"> function TranslateToNorwegian() { document.getElementById('Norwegian1').innerHTML = 'Lengua del cambio:'; document.getElementById('Norwegian2').innerHTML = 'Lujos para menos!'; document.getElementById('Norwegian3').innerHTML = 'Busqueda Luxe Bux:'; document.getElementById('Norwegian4').innerHTML = '<input type="submit" style="background-color: #794011; color: #ffffff; border-width: thin; border-style: dotted; border-color: 794011" value="Encuentrelo!">'; document.getElementById('Norwegian5').innerHTML = 'Tienda ahora!'; document.getElementById('Norwegian6').innerHTML = 'Revisiones de Luxe Bux'; document.getElementById('Norwegian7').innerHTML = 'Politica de FAQ/Return/mas Info'; document.getElementById('Norwegian8').innerHTML = 'Contacto'; document.getElementById('Norwegian9').innerHTML = '<font size="4">Aqui es lo que estan diciendo nuestros clientes...<br><br></font><br /><font size="3">"GRACIAS EL TRATAR MUCHO AGRADABLE DE"<br>"Cuidado total y grande del servicio excepcional en el empaquetado! Comprare otra vez!"<br>"Exactamente segun lo anunciado! Envio rapido (lleva siempre mas de largo Canada)"<br>"grandes vendedores en linea. recomendado altamente! comprara de otra vez"<br>"Llegado en tiempo de registro y empaquetado bien. Grazias"<br>"Aprisa"<br>"Gran servicio, envio muy rapido. Comprare definitivamente de ellos otra vez"<br>"Llegado rapidamente segun lo descrito!!"<br><br><br><br><br><br></p> } </script> </body></html> I've been going through this great tutorial on how to implement a type-ahead feature on a text field and there's something which hopefully you guys can explain. On the third page there is this function. Code: AutoSuggestControl.prototype.init = function () { var oThis = this; this.textbox.onkeyup = function (oEvent) { if (!oEvent) { oEvent = window.event; } oThis.handleKeyUp(oEvent); }; }; What I don't understand is this line: this.textbox.onkeyup = function (oEvent) { I know about anonymous functions, but I don't know where the value for the parameter oEvent is going to come from. Can someone explain this? Thanks! :) Hi! This is probably a classic inheritance thing... I have two objects, C1 and C2. Both contains a callback method named 'callback'. Now, if I let C2 inherit from C1, then C1's 'callback' gets overridden by C2's. The problem is I still want C1's methods to access their own 'callback' method. Is this possible, and is it "valid"? Am I headed down disaster lane here? Should I re-think and refactor? Example: Code: function C1 () {}; C1.prototype.callback = function () { console.log('c1 called'); }; C1.prototype.call = function () { //do stuff this.callback(); }; function C2 () {}; C2.prototype = new C1(); C2.prototype.callback = function () { console.log('c2 called'); }; var obj = new C2(); obj.call(); Output: c2 called Regards Don Hi there I am wondering if anyone can tell me the best way to access the functions of an Iframe from the parent of the frame. I have tried Code: var myFrame = document.getElementById('gigmap'); myFrame.flashMouseover(gid); and Code: window.frames['gigmap'].document.flashMouseover(gid); though these didn't work. Basically this is what i want: Mainpage function a(id) receives flash variable 'id' then sends variable 'number' to iframe function b(id) . The part in red is where I have the problem. In case you are wondering what I am doing is sending an id of a gig in my database when its button rolled over in a flash swf to a Google Map (using Google maps javascript API inside the Iframe 'gigmap) and make the corresponding marker on the map jump. I have it so the iframed map markers send to the flash file on rollover though not the other way round...yet! Is it possible to have an input that points to some other function? For example: Code: function someFunction() { alert('It worked.'); } function doAnotherFunction(doIt, otherFunction) { if (doIt == true) { otherFunction(); } } <input type="button" value="test" onClick="doAnotherFunction(true, someFunction());"> Or would I need a switch statement and have all the various functions hardcoded? which is the real difference between: <script> alert('hello'); </script> and <script> function hi() {alert('hello');} </script> thanks in advance makerjoe ----------SOLUTION---------- ----------ORIGINAL PROBLEM---------- The second line of code. What does it do? It's confusing because it doesn't have a semicolon at the end and it doesn't end with (). Code: var centreicon = new GIcon(); centreicon.constructor centreicon.image = "http://maps.google.com/mapfiles/kml/pal3/icon31.png "; centreicon.shadow = "http://maps.google.com/mapfiles/kml/pal3/icon31s.png "; centreicon.iconSize = new GSize(12, 20); centreicon.shadowSize = new GSize(22, 20); centreicon.iconAnchor = new GPoint(6, 20); centreicon.infoWindowAnchor = new GPoint(5, 1); I found this on stackoverflow while trying to find a way to make my own icons on a map. With that being said. I'm still confused about how to apply the new graphic to a map. I don't see how they apply that picture to a coordinate. Does anyone know how to do that? Can I do this? Code: var centreicon = new GIcon(); centreicon.constructor centreicon.image = "http://maps.google.com/mapfiles/kml/pal3/icon31.png "; centreicon.shadow = "http://maps.google.com/mapfiles/kml/pal3/icon31s.png "; centreicon.iconSize = new GSize(12, 20); centreicon.shadowSize = new GSize(22, 20); centreicon.iconAnchor = new GPoint(6, 20); centreicon.infoWindowAnchor = new GPoint(5, 1); var marker = new GMarker( new GLatLng(-34.397, 150.644) , centreicon); map.addOverlay(marker); -------- A tad bit later -------- So this is the code I have on my testing site Even thought I'ved defined the the icon's image and location It does not show up on the map. What am I missing? Code: <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no" /> <style type="text/css"> html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } </style> <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?key=AIzaSyAWhjy3iZ8g6BZszj299c0yUY6ahKpSr1U&sensor=false"> </script> <script type="text/javascript"> function initialize() { var myOptions = { center: new google.maps.LatLng(-34.397, 150.644), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"),myOptions); var centreicon = new GIcon(); centreicon.constructor centreicon.image = "http://maps.google.com/mapfiles/kml/pal3/icon31.png "; centreicon.shadow = "http://maps.google.com/mapfiles/kml/pal3/icon31s.png "; centreicon.iconSize = new GSize(12, 20); centreicon.shadowSize = new GSize(22, 20); centreicon.iconAnchor = new GPoint(6, 20); centreicon.infoWindowAnchor = new GPoint(5, 1); var marker = new GMarker( new GLatLng(-34.397, 150.644) , centreicon); map.addOverlay(marker); } </script> </head> <body onload="initialize()"> <div id="map_canvas" style="width:100%; height:100%"></div> </body> </html> Hi, I'm having some issues turning this "Please Wait"/Disabled button into a function. Code: <input type="submit" value="Submit Form" onClick="this.disabled = 'true'; this.value='Please wait...';" /> Code: function pleasewait() { this.disabled = 'true'; this.value='Please wait..' } <input type="submit" value="Submit Form" onClick="pleasewait();" /> Thanks much Hi, I am facing a problem in passing replace() function as an argument in user defined java function, can any one help me how to resolve it? intention is to pass a file path to my user defined function, but before passing the path i want to replace the character '\' to '\\' I am posting my javascript function he <a href="#" onclick="OpenDocPreview('<%# Eval("PATH")%>'.replace(/\\/g,"\\\\"), '<%# Eval("Filename")%>')"><%# Eval("DocTitle") %></a> function OpenDocPreview(url, docname) { alert('message from search base : ' + url + ' ' + docname); } thank you, |