JavaScript - Javascript Inheritance Problem
First class:
Code: function ClassOne(){ this.events = []; this.executeEvents = []; this.addEvents = function(event){ this.events.push(event); } this.addExecuteEvents = function(e){ this.executeEvents.push(e) } this.getEvents = function(){ return this.events; } } Second class: Code: function ClassTwo(){ this.add = function(e){ this.addEvents(e) } } ClassTwo.prototype = new ClassOne Here the second class extends the first class, now I want to create two objects of class two, Code: var b = new ClassTwo(); b.add('hello'); var c = new ClassTwo(); c.add('hi'); console.log(c.getEvents()) I just added one event on b and c each, but when I logged the c.getEvents(), it returns both 'hi' and 'hello' events. why?? What am I doing wrong?? how to solve this problem?? Thanks in advance Similar TutorialsWhat are the benefits of prototypal inheritance over classical inheritance?
What are the benefits of prototypal inheritance over classical inheritance?
Hello, I am new with Javascript and running into this problem that I don't understand. I define a base class that only contains an array "elements", and a derived class that contains nothing more (for simplicity): Code: function baseClass() { this.elements = new Array; } function derivedClass() { } derivedClass.prototype = new baseClass; Then I create two instances of the derived class, and add two elements in each: Code: a = new derivedClass(); a.elements.push("A"); a.elements.push("B"); b = new derivedClass(); b.elements.push("C"); b.elements.push("D"); When I examine the contents of these arrays, I see that both a.elements and b.elements contain {"A","B","C","D"} ! I.e. as if the two arrays are in fact the same array! But these are two separate instances of the class, I expect two separate arrays. Note that if instead I use the base class: Code: a = new baseClass(); a.elements.push("A"); a.elements.push("B"); b = new baseClass(); b.elements.push("C"); b.elements.push("D"); then I get a.elements = {"A","B"} and b.elements = {"C","D"}, as I would expect. Could someone explain to me the problem with using the derived class? Thank you, Stephanos I'm trying my best to figure this out with google, but I've found 4 different syntaxes and can't get any of them to work. I need to have several classes extend another for my chess game. I need classes, Rook, Knight, Bishop etc... all extend from class Piece. can anyone help me with the syntax var Piece = Class.create(); Piece.prototype = { initialize: function(src, square){ //init stuff here }, setSqua function(square){ //sets the square of the piece }, } Rook.prototype = new Piece(); function Rook(src, square) { Piece.apply(src, square); } Thanks to anyone who helps Hello All, can someone pls help me with the error shown in firebug for the code below: Firebug error: Object.method is not a function Object.method('superior', function (name) { Constructor functions work until it gets to /* Super method template */. Thats where the error comes from. Code is from javascript - good parts. var mammal = function(spec) { var that = {}; that.get_name = function() { return spec.name; } that.says = function() { return spec.saying || ''; } return that; } var myMammal = mammal({name: 'Herbie', saying: 'Im herb the mammal'}); console.log(myMammal.get_name()); console.log(myMammal.says()); var cat = function(spec) { spec.saying = spec.saying || 'Meow!' var that = mammal(spec); that.purr = function(n) { var i, s = ''; for(i=0; i < n; i +=1) { if(s) { s += '-'; } s += 'r' } return s; } that.get_name =function() { return that.says() +' '+ spec.name +' '+ that.says(); } return that; } var myCat = cat({name: 'Henrietta!', saying: 'Im a pussycat'}) console.log(myCat.get_name()); console.log(myCat.purr(3)); /* Super method template */ Object.method('superior', function (name) { var that = this, method = that[name]; return function ( ) { return method.apply(that, arguments); }; }); /* Super method e.g. */ var coolcat = function (spec) { var that = cat(spec), super_get_name = that.superior('get_name'); that.get_name = function (n) { return 'like ' + super_get_name( ) + ' baby'; }; return that; }; var myCoolCat = coolcat({name: 'Bix'}); console.log(myCoolCat); var name = myCoolCat.get_name(); console.log(name); Hi, I would like to know which is the best approach when trying inheritance with js - module pattern. In the example below, I want that parent.hi() be fired from child: Code: var parent = function(){ return{ hi: function(){ console.info('hi'); } } }(); var child = function(){ return{ bye: function(){ console.info('bye'); }, hi: function(){//look he parent.hi(); } } }(); child.hi(); Is there a better way to do this ? Thanks in advance I'm having a javascript problem with nested elements. Consider an example in which you have two nested elements with element 2 being inside of element 1 and only element 1 has an onmouseout event handler. <div style="position:relative;border:1px solid red;width:300px;height:300px" onmouseout="alert('whatever')"> //element 1 <div style="position:absolute;border:1px solid blue;left:50%;top:50%;margin-left:-50px;margin-top:-50px;width:100px;height:100px">//element 2 </div> </div> The 2 problems here are as follows: 1- Moving the mouse pointer over element 2 from element 1 causes a onmouseout with element 1. But this is a minor problem. 2- Moving the mouse pointer from element 2 back to element 1 causes a mouseout with ,I believe, element 2 even though there is no onmouseout event handler here. This is a major problem. Is problem #2 due to possibly an automatic inheritance of the onmouseover handler from element 1 onto element 2 OR is it the result of event capturing or what else? I can't tell either way. If it's due to inheritance how do you stop this from taking place? The strange thing is that tutorials give this kind of scenario with element 2 inside of element 1 with both elements having the same event handler but they don't say what happens in this case with just one element having a specific event handler. Thank you. 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 please bear with my noobishness, but i've been trying for many hours to understand what is going on behind this code: ** Code: function Person() { document.write('constructor: <br/>'+this.constructor); //displays Person constructor this.name = "Rob Roberson"; this.age = 31; } function Employee() { document.write('<br/>constructor: <br/>'+this.constructor); //displays Person constructor this.dept = "HR"; this.manager = "John Johnson"; } Employee.prototype = new Person(); var Ken = new Employee(); document.write('<br/>'+Ken.constructor); //displays Person constructor document.write('<br/>name:'+ Ken.name + '<br/>age:' + Ken.age + '<br/>dept:' + Ken.dept + '<br/>manager:' + Ken.manager ); //displays all properties correctly *** from what i've read, every object references a prototype. in this case, the Employee function will automatically reference a prototype with 'constructor' as its initial value. this command: Employee.prototype = new Person(); will replace the Employee function's prototype to an instance of Person. so now Employee function's prototype will contain both name and age properties, BUT, and this is where i get lost, ITS CONSTRUCTOR PROPERTY GETS REPLACED! so how does: var Ken = new Employee(); actually construct an instance of Employee if the reference to its constructor has been replaced by an instance of Person that only contains name and age properties? how is Ken ever initialized by Employee constructor? I posted this once, but it disappeared, and I have no notifications that I did anything wrong. I read the rules before posting and wasn't breaking any so I am not sure why it disappeared but here goes again. I am trying to learn Javascript (particularly OOP) from a series of screencasts by Douglas Crockford. I have developed a theoretical "game" to build to illustrate it to myself better, and learn by example. I must be misunderstanding how inheritance works, because my code is not producing the results I thought it would. Here is what I have, followed by an explanation of my understanding. Code: $(function() { function object(o) { function Funct() {} Funct.prototype = o; return new Funct(); } soldier = { pointsCost: 0, movement: "1 Infantry Block", validTargets: {}, weapons: { "Main Weapon": { "Weapon Type": "M4 Carbine", "Fire Range": 12 }, "Secondary Weapon": { "Weapon Type": "JCP .45", "Fire Range": 3 } } }; var rifleman = object(soldier); rifleman.pointsCost += 10; rifleman.validTargets.target1 = "Infantry" rifleman.weapons["Secondary Weapon"]["Weapon Type"] = ""; rifleman.weapons["Secondary Weapon"]["Fire Range"] = ""; var heavyGunner = object(soldier); heavyGunner.pointsCost += 20; heavyGunner.validTargets.target1 = "Infantry"; heavyGunner.validTargets.target2 = "Light Armor"; heavyGunner.weapons["Main Weapon"]["Weapon Type"] = "SAW M249"; heavyGunner.weapons["Main Weapon"]["Fire Range"] = 12; heavyGunner.weapons["Secondary Weapon"]["Weapon Type"] = ""; heavyGunner.weapons["Secondary Weapon"]["Fire Range"] = ""; var sniper = object(soldier); sniper.pointsCost += 30; sniper.validTargets.target1 = "Infantry"; sniper.weapons["Main Weapon"]["Weapon Type"] = "Savage .308"; sniper.weapons["Main Weapon"]["Fire Range"] = 20; sniper.weapons["Secondary Weapon"]["Weapon Type"] = "JCP .45"; sniper.weapons["Secondary Weapon"]["Fire Range"] = 3; var demolitions = object(soldier); demolitions.pointsCost += 30; demolitions.validTargets.target1 = "Infantry"; demolitions.validTargets.target2 = "Light Armor"; demolitions.validTargets.target3 = "Artilery"; demolitions.validTargets.target4 = "Structures"; demolitions.weapons["Main Weapon"]["Weapon Type"] = "SMAW MK153"; demolitions.weapons["Main Weapon"]["Fire Range"] = 16; demolitions.weapons["Secondary Weapon"]["Weapon Type"] = "M1014 Combat Shotgun"; demolitions.weapons["Secondary Weapon"]["Fire Range"] = 1; var infantry = { rifleman: rifleman, heavyGunner: heavyGunner, sniper: sniper, demolitions: demolitions }; console.log(infantry); }); I start by creating an object function that accepts an object passed in, and sets it to the prototype of a constructor (that would allow me to create a new object linked to, and inheriting from, the initial passed in object) I initialized a solider object literal, and pass that into the object function while creating 4 new objects (rifleman, heavyGunner, sniper, demolitions) These four should inherit from and customize upon the soldier object. The way I understood inheritance is that the new objects (example. rifleman) would inherit properties from the old object (i.e. soldier) and change or add properties, affecting only the new (rifleman) object but not changing the old(solider) object. this works ok somewhat in my example, until it comes to nested objects. In the above example I have objects as values for some Object's properties. (i.e. validTargets and weapons) When I change or add these, all of the new objects seem to inherit the last declarations, from demolitions, as if demolitions is actually changing that part of the soldier object so that the other's inherit those properties. From my viewpoint, I expected these values to not be changed and that the 4 infantry types had no link to each other, but only to the soldier object. I apparently misunderstood something, or coded something wrong. Some minor notes: -I will be updating most of the "string" values to be objects, so for instance, the validTargets value of "Infantry" would actually be the infantry object, stating that any of the 4 solider types would be a valid target. - I intend to create weapons as their own viable objects in the future, and pass those objects instead of "strings" - I intend to extend this (once this is working) to create an armor object that contains armor type units, similar in structure to the infantry object. - If I can get this all to work, I may make this into a "simple" dice style battle game. but that is way off, I just want to get this nesting of objects to work with inheritance for now. Thanks in advance for any help you can provide. Here is a link to the "live" example. (not much different there except if you have firebug you can see the console.log method showing the objects, and how they are inheriting in properly from my POV.) Link to Live example... Blue I got an index.php Code: <html> <form action="bacakomik.php" method='post'> <select name="kodekomik"> <option value='../komik1/|23'>Judul Komik1</option> <option value="../komik2/|20">Judul Komik2</option> <option value="../komik3/|10">Juduk Komik3</option> <option value="../komik4/|20">Judul Komik4</option> </select> <input type="submit" /> </form> <?php echo ('<select>'); echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); echo ('</select>'); ?> </html> As you can see, each of the option brings specific value "../komik1/|23" komik1 is a directory | is a delimiter 23 is the pages in one chapter and can be considered also as how many images are there on a specific directory This is my bacakomik.php Code: <?php $dirkomik = $_POST['kodekomik']; $exploded = explode("|", $dirkomik); echo ($exploded[0]); //picture directory echo ("<br>"); echo ($exploded[1]); //total page in the comic $pagecount = (int)$exploded[1]; //Take last posted value, process it right away echo ('<FORM name="guideform"> '); echo ('<select name="guidelinks">'); $i=1; do { echo ('<option value= "'.$i.'">'.'Page '.$i.'</option>'); $i= $i+1; }while($i <= $pagecount); //Printing option and select echo ("</select>"); ?> <input type="button" name="go" value="Go!" onClick="document.getElementById('im').src=document.guideform.guidelinks.options[document.guideform.guidelinks.selectedIndex].value+'.png';"> </FORM> <img src="img0.jpg" id="im"> With the current code on bacakomik.php, I only can change the img src of id "im" in the same directory only. What I want is that the Javascript could "add" the "$exploded[0]" variable so that the picture can be loaded from different directory. Anyone can do this? I believe that the fix should be somewhere on input tag inside OnClick, or do you know where? Anyway, I found this on the net http://p2p.wrox.com/php-faqs/11606-q...avascript.html Please help me to those who can... Hi All, I am desperately pulling my hair out... can you help me understand how I can resolve the below errors: SCRIPT1028: Expected identifier, string or number calender.js, line 318 character 17 SCRIPT1006: Expected ')' blenheim-palace-lunch-cotswolds-p-170.html, line 88 character 35 SCRIPT5007: The value of the property 'getStartDate' is null or undefined, not a Function object blenheim-palace-lunch-cotswolds-p-170.html, line 643 character 7 For this web address... http://tinyurl.com/79msxqm What can I change to fix the issue? The site is working properly in all other browsers but not IE9. Hope you can help. Thanks. I'm having a problem with a javascript code I put together. For all of the PHP, CSS, HTML that I know, well it doesn't carry over to JavaScript, so my attempt at trying this is probably a very bad attempt. Anyways, what I'm trying to accomplish with this code is to get the height of one table and set the padding-bottom to another table, to keep page dimensions even. Code: <script type="text/javascript"> var divArray = document.getElementById('tablecontent').offsetheight; //Subtracting 442 because that's the height of the table. I'm just trying to add onto the bottom. var subtraction = divarray - 442; var tablesidebar = document.getElementById('tablesidebar'); tablesidebar.style.paddingbottom = subtraction + 'px'; </script> Any help to get this working is well appreciated. Thanks, Jeremy Hi and hope someone can help. I'm trying to put together some code within a form that tests whether someone has supplied an email address or a telephone number when the Submit button is pressed. Neither of these fields are require mandatory input. Trouble is my current code always supplies a true result even if no data is put in these fields i.e. the 1st IF statement returns true. What am I doing wrong? Here's my code. Thanks R _____ Code: <script type="text/javascript"> function check_id() { if (document.feedback.email !="" || document.feedback.tel !="") { alert("Thank you. You will be entered into our free prize draw. Good luck!"); } else if (document.feedback.email =="" && document.feedback.tel =="") { confirm("You will not be entered in our free prize draw unless you supply your email address or telephone number. Is that O.K?"); } } function clear (){ var email=""; var tel=""; } </script> <form action="" method="get" name="feedback" enctype="application/x-www-form-urlencoded" onSubmit="check_id();" onReset="confirm('This will clear all your entries, is that O.K?'); clear();"> <div> <label for="email">Your email address:</label> <input name="email" type="text" id="email" size="50" value="" /> </div> <div> <label for="tel">Your telephone number:</label> <input name="tel" type="text" id="tel" size="50" value="" /> </div> <div> <input type="reset" name="reset" id="reset" value="Reset" /> <input type="submit" name="submit" id="submit" value="Submit" /> </div> </form> Hi im wondering if someone could be of some help please, im a newbie to javascript and after some help and advice if possible please. Ive used a template from the web which was a quiz template. Im just trying to get my javascript script to work. I want it to populate my html question/advice box so people can input what there answer to the question and it will give them advice. It's for a data classification advice for a work project. I just dont know where im going wrong or what im missing out - ive read loads of help sections on the web and still cant get the javascript to populate my html boxes. Any help or advice would be really appreciated. Thanks Lee Heres my html code which seems to work ok... the box etc is displayed just doesnt have any content. ----------------------------------------------------------------------- Code: <form method="POST"> <div align="center"><center><table BORDER="1"> <tr> <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="+3" COLOR="#FFFFFF">Data Classification </font></td> </tr> <tr> <td COLSPAN="2" BGCOLOR="#4C0000"><div align="center"><center><p><font SIZE="-1" COLOR="#FFFFFF">2010 <a HREF="Data Governance</font> </p> </center></div><div align="center"><center><p><font COLOR="#FFFFFF">Click on "Next Question" to start advice. Be sure to use small letters (no caps) when entering your letter choice.</font> </td> </tr> <tr> <td><b>Question #:</b></td> <td ALIGN="LEFT"><input TYPE="TEXT" NAME="questNo" SIZE="4"></td> </tr> <tr> <td><b>Question:</b></td> <td><div align="center"><center><p><textarea COLS="70" ROWS="2" name="question" wrap="virtual"></textarea></td> </tr> <tr> <td ALIGN="RIGHT"><b>a)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceA" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>b)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceB" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>c)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceC" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>d)</b></td> <td><div align="center"><center><p><input TYPE="TEXT" NAME="choiceD" SIZE="75"></td> </tr> <tr> <td ALIGN="RIGHT"><b>Your choice:</b></td> <td><input TYPE="TEXT" NAME="yourChoice" SIZE="4"></td> </tr> <tr> <td COLSPAN="2"><div align="center"><center><p><input TYPE="button" VALUE="Check Current Advice" onClick="checkAnswer(this.form)"><input TYPE="button" VALUE="Next Question" onClick="nextQuestion(this.form)"> <input TYPE="reset" VALUE="Start Over" onClick="clearForm(this.form)"></td> </tr> <tr> <td ALIGN="RIGHT"><b>Results:</b></td> <td><div align="center"><center><p><textarea COLS="70" ROWS="3" name="Advice" wrap="virtual"></textarea></td> </tr> <tr> </form> -------------------------------------------------------------------------- Now heres my javascript which i just cant seem to get to work or integrate with the html question/advice box. There will be some text in there that was originally part of the template that i was going to remove at a later stage once id got a better underatnding of where i was going wrong. Code: <html> <head> <script LANGUAGE="JavaScript"> <!-- hide this script tag's contents from old browsers ---> function jumpBox(list) { location.href = list.options[list.selectedIndex].value } //Lee Quinn 2010 All Rights Reserved function init() { questions = new Array() questions[1] = "Is the information you are collecting or creating any of the following?" questions[2] = "Is the information you are collecting or creating any of the following?" questions[3] = "Is the information you are collecting or creating any of the following?" questions[4] = "Is the information you are collecting or creating any of the following?" answerA = new Array() answerA[1] = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases" answerA[2] = "Employee Handbook,Telephone Directory,Organization Charts,Policies and Standards,Training Manuals" answerA[3] = "Customer records, Correspondence containing customer information, Credit card listings,Personnel records/Employee performance reviews,Unit business plans,Proprietary/custom software,Budget information,Internal audit reports,Business reports on strategy, exposures etc" answerA[4] = "Strategic Plans,Encryption keys,Details of mergers or acquisitions,Financial results prior to publication,Online access codes such as passwords or pin" answerB = new Array() answerB[1] = "None of the above" answerB[2] = "None of the above" answerB[3] = "None of the above" answerB[4] = "None of the above" rightAns = new Array rightAns[1] = "A" rightAns[2] = "b" rightAns[3] = "c" rightAns[4] = "d" reference = new Array() reference[1] = "You have indicated yes to question 1, therefore the information you are collecting/creating will be classified as PUBLIC information. It is information that can be disclosed to anyone without violating an individual?s right to privacy. Knowledge of this information does not expose CFS to financial loss, embarrassment, or jeopardize the security of assets." reference[2] = "You have indicated yes to question 2, therefore the information you are collecting/creating will be classified as INTERNAL USE information. It is information that, due to technical or business sensitivity, is limited to employees and contractors who work on-site. It is intended for use only within CFS. Unauthorized disclosure, compromise, or destruction would not have a significant impact on CFS or its employees." reference[3] = "You have indicated yes to question 3, therefore the information you are collecting/creating will be classified as CONFIDENTIAL information. It is information that CFS and its employees have a legal, regulatory, or social obligation to protect. It is intended for use solely within defined groups in CFS. Unauthorized disclosure, compromise, or destruction would adversely impact CFS its customers or its employees. Unless otherwise stated all data should be treated as CONFIDENTIAL.Sensitive data = Confidential or Highly Confidential data." reference[4] = "You have indicated yes to question 4, therefore the information you are collecting/creating will be classified as HIGHLY CONFIDENTIAL information, It is the highest level of classification and is information whose unauthorized disclosure, compromise, or destruction could result in severe damage, provide significant advantage to a competitor, or incur serious financial impact to CFS or its employees. It is intended for restricted use by a very small number of people (possibly 0 or 1) with an explicit, predetermined need to know." } function nextQuestion(form) //set the total number of questions equal to quizend { var quizEnd = eval(4 * 1); if(form.questNo.value =5= quizEnd) { form.question.value = "1"; form.choiceA.value = "Marketing brochures, Customer disclosure statements,Published annual reports, Interviews with news media, Press releases"; form.choiceB.value = "None of the above"; form.choiceC.value = "Unsure"; form.yourChoice.value = "a,b,c,d"; form.results.value = "End of Advice. Your final results are listed below."; } else { if(form.questNo.value == "") {form.questNo.value = 1} else { form.questNo.value = eval(form.questNo.value) + 1; } form.question.value = questions[form.questNo.value]; form.choiceA.value = answerA[form.questNo.value]; form.choiceB.value = answerB[form.questNo.value]; form.choiceC.value = answerC[form.questNo.value]; form.choiceD.value = answerD[form.questNo.value]; form.yourChoice.value = ""; form.results.value = ""; if(form.myScore.value == "") {form.myScore.value = 0; } else { form.myScore.value = form.myScore.value; } } } function checkcurrentadvice(form) { var myScore = 0; var curve = 0; if(form.results.value != "") {form.results.value = "Sorry, no guessing allowed. In order to retry this question you will have to start the quiz over. Click on ''Next Question'' to continue."; } else if(form.yourChoice.value == rightAns[form.questNo.value]) { form.myScore.value = eval(form.myScore.value) + eval(1); form.results.value = "Conratulations! You are correct. That brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ". Click on ''Next Question'' to continue."; } else { form.results.value = "Sorry, you are incorrect. Please refer to " + reference[form.questNo.value] + " before retaking the quiz. This brings your cumulative score to " + form.myScore.value + " out of a possible " + form.questNo.value + ". Click on ''Next Question'' to continue." } function clearForm(form) { form.questNo.value = ""; form.question.value = ""; form.choiceA.value = ""; form.choiceB.value = ""; form.choiceC.value = ""; form.choiceD.value = ""; form.yourChoice.value = ""; form.results.value = ""; form.myScore.value = ""; form.percent.value = ""; form.grade.value = ""; } </script> </head> </html> PHP Code: ?><script type="text/javascript"> var answer=confirm("Do you want to update your email?"); if(answer==true) { <?php mysql_query("update user set u_email ='$email' where u_user='$username'"); ?> alert ("You choose update your email."); } if(answer==false) { alert ("You had rejected to update your email."); //answer=0; } </script> <? i put this javascript within my php, it should perform update when i click ok, and perform nothing when i click cancel, but the problem is, it will still perform update although i click cancel. someone can solve this for me pls..? I have an html page with javascript on it, but the page will not work properly. Spent a lot of time on this and can not get it right. Wonder if someone ca help. hi all i m having the following problem and i m a newbie in javascript. i have 6 .html pages and 1 .js page and those 6 html pages make use of .js page for functions. each html page contains yes or no button. i have problem in validation 1) As soon as the user click 3 yes's he should b directed to the result.html page .plzz reply its urgent. Thanks.. Hello, I have two arrays sd[16][16] and gd[16][16] in javascript. I need to compare the values of the arrays. Code: Code: var score=0; document.write("<table>"); for(c1=0; c1<16; c1++) { document.write("<tr>"); for(c2=0; c2<16; c2++) document.write("<td onClick='changeColor(this);'>" + gd[c1][c2] + "</td>"); document.write("</tr>"); } document.write("</table>"); function changeColor(tdd) { if(tdd.bgColor=='white') { tdd.bgColor='red'; if (gd[c1][c2] == sd[c1][c2]) score+=5; else score-=2; } else { tdd.bgColor='white'; } } function scc() { document.getElementById('scf').innerHTML = score; } </script> <br><br><center><button type='button' onclick='scc()'> Click to see current score</button> <p id="scf">0</p> </center> <br><br> <center><input type="submit" value="Get Solution"/></center> When I try to display score by clicking the "Click to see current score" button, the score is not displayed. Could someone please tell me the problem. |