JavaScript - Howto Correct An Error Such As:grosspay(int,int) In Payslip3 Cannot Be Applied To Int
i am making a payslip but i do not know how to correct the error :
=grosspay(int,int) in payslip3 cannot be applied to (int) =netpay(int,int) in payslip3 cannot be applied to (int) =totaldeduction(int,int) in payslip3 cannot be applied to (int) also whenever I type the value and push the button in order to calculate the answers, the inputs are being cleared...... here is the code...... Code: import javax.swing.*; import java.awt.*; import java.awt.event.*; public class payslip3 extends JFrame implements ActionListener { private static int width=600; private static int height=300; private JLabel[] labelJL = new JLabel[18]; private JTextField[] textJT = new JTextField[16]; private JButton[] AddClearExit = new JButton[5]; private JPanel panel = new JPanel(new GridLayout()); public payslip3() { Container pane = getContentPane(); pane.setBackground (Color.black); setTitle("USING BUTTON EVENT"); setSize(width,height); labelJL[0] = new JLabel("Payslip",0); labelJL[0].setForeground(Color.white); labelJL[0].setFont(new Font("Comic Sans MS",Font.BOLD,50)); labelJL[0].setLocation(560,10); labelJL[0].setSize(225,125); pane.add(labelJL[0]); labelJL[0] = new JLabel("RUN DATE:",0); labelJL[0].setForeground(Color.white); labelJL[0].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[0].setLocation(250,150); labelJL[0].setSize(100,20); pane.add(labelJL[0]); textJT[0] = new JTextField(); textJT[0].setBackground(Color.white); textJT[0].setLocation(350,150); textJT[0].setSize(200,20); pane.add(textJT[0]); labelJL[1] = new JLabel("DAYS WORKED:",0); labelJL[1].setForeground(Color.white); labelJL[1].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[1].setLocation(200,200); labelJL[1].setSize(150,20); pane.add(labelJL[1]); textJT[1] = new JTextField(); textJT[1].setBackground(Color.white); textJT[1].setLocation(350,200); textJT[1].setSize(200,20); pane.add(textJT[1]); labelJL[2] = new JLabel("BASIC PAY:",0); labelJL[2].setForeground(Color.white); labelJL[2].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[2].setLocation(225,250); labelJL[2].setSize(100,20); pane.add(labelJL[2]); textJT[2] = new JTextField(); textJT[2].setBackground(Color.white); textJT[2].setLocation(350,250); textJT[2].setSize(200,20); pane.add(textJT[2]); labelJL[3] = new JLabel("OVERTIME WORKED:",0); labelJL[3].setForeground(Color.white); labelJL[3].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[3].setLocation(180,300); labelJL[3].setSize(170,20); pane.add(labelJL[3]); textJT[3] = new JTextField(); textJT[3].setBackground(Color.white); textJT[3].setLocation(350,300); textJT[3].setSize(200,20); pane.add(textJT[3]); labelJL[4] = new JLabel("OVERTIME RATE:",0); labelJL[4].setForeground(Color.white); labelJL[4].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[4].setLocation(180,350); labelJL[4].setSize(200,20); pane.add(labelJL[4]); textJT[4] = new JTextField(); textJT[4].setBackground(Color.white); textJT[4].setLocation(350,350); textJT[4].setSize(200,20); pane.add(textJT[4]); labelJL[5] = new JLabel("GROSS PAY:",0); labelJL[5].setForeground(Color.white); labelJL[5].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[5].setLocation(250,450); labelJL[5].setSize(100,20); pane.add(labelJL[5]); textJT[5] = new JTextField(); textJT[5].setBackground(Color.white); textJT[5].setLocation(350,450); textJT[5].setSize(200,20); pane.add(textJT[5]); labelJL[6] = new JLabel("NET PAY:",0); labelJL[6].setForeground(Color.white); labelJL[6].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[6].setLocation(250,500); labelJL[6].setSize(100,20); pane.add(labelJL[6]); textJT[6] = new JTextField(); textJT[6].setBackground(Color.white); textJT[6].setLocation(350,500); textJT[6].setSize(200,20); pane.add(textJT[6]); labelJL[7] = new JLabel("CUT-OFF DATE:",0); labelJL[7].setForeground(Color.white); labelJL[7].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[7].setLocation(680,150); labelJL[7].setSize(210,20); pane.add(labelJL[7]); textJT[7] = new JTextField(); textJT[7].setBackground(Color.white); textJT[7].setLocation(850,150); textJT[7].setSize(200,20); pane.add(textJT[7]); labelJL[8] = new JLabel("NAME:",0); labelJL[8].setForeground(Color.white); labelJL[8].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[8].setLocation(750,190); labelJL[8].setSize(100,20); pane.add(labelJL[8]); textJT[8] = new JTextField(); textJT[8].setBackground(Color.white); textJT[8].setLocation(850,190); textJT[8].setSize(200,20); pane.add(textJT[8]); labelJL[9] = new JLabel("TAX WITH HELD:",0); labelJL[9].setForeground(Color.white); labelJL[9].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[9].setLocation(680,300); labelJL[9].setSize(200,20); pane.add(labelJL[9]); textJT[9] = new JTextField(); textJT[9].setBackground(Color.white); textJT[9].setLocation(850,300); textJT[9].setSize(200,20); pane.add(textJT[9]); labelJL[10] = new JLabel("SSS:",0); labelJL[10].setForeground(Color.white); labelJL[10].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[10].setLocation(760,350); labelJL[10].setSize(100,20); pane.add(labelJL[10]); textJT[10] = new JTextField(); textJT[10].setBackground(Color.white); textJT[10].setLocation(850,350); textJT[10].setSize(200,20); pane.add(textJT[10]); labelJL[11] = new JLabel("MEDICAL:",0); labelJL[11].setForeground(Color.white); labelJL[11].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[11].setLocation(750,400); labelJL[11].setSize(100,20); pane.add(labelJL[11]); textJT[11] = new JTextField(); textJT[11].setBackground(Color.white); textJT[11].setLocation(850,400); textJT[11].setSize(200,20); pane.add(textJT[11]); labelJL[12] = new JLabel("PAG-IBIG:",0); labelJL[12].setForeground(Color.white); labelJL[12].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[12].setLocation(750,450); labelJL[12].setSize(100,20); pane.add(labelJL[12]); textJT[12] = new JTextField(); textJT[12].setBackground(Color.white); textJT[12].setLocation(850,450); textJT[12].setSize(200,20); pane.add(textJT[12]); labelJL[13] = new JLabel("SSS LOAN:",0); labelJL[13].setForeground(Color.white); labelJL[13].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[13].setLocation(750,500); labelJL[13].setSize(100,20); pane.add(labelJL[13]); textJT[13] = new JTextField(); textJT[13].setBackground(Color.white); textJT[13].setLocation(850,500); textJT[13].setSize(200,20); pane.add(textJT[13]); labelJL[14] = new JLabel("PAG-IBIG LOAN:",0); labelJL[14].setForeground(Color.white); labelJL[14].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[14].setLocation(690,550); labelJL[14].setSize(200,20); pane.add(labelJL[14]); textJT[14] = new JTextField(); textJT[14].setBackground(Color.white); textJT[14].setLocation(850,550); textJT[14].setSize(200,20); pane.add(textJT[14]); labelJL[15] = new JLabel("TOTAL DEDUCTION:",0); labelJL[15].setForeground(Color.white); labelJL[15].setFont(new Font("Verdana",Font.BOLD,13)); labelJL[15].setLocation(675,620); labelJL[15].setSize(200,20); pane.add(labelJL[15]); textJT[15] = new JTextField(); textJT[15].setBackground(Color.white); textJT[15].setLocation(850,620); textJT[15].setSize(200,20); pane.add(textJT[15]); labelJL[16] = new JLabel("DEDUCTION",0); labelJL[16].setForeground(Color.white); labelJL[16].setFont(new Font("Gill Sans Ultra Bold",Font.BOLD,10)); labelJL[16].setLocation(870,250); labelJL[16].setSize(100,20); pane.add(labelJL[16]); AddClearExit[0] = new JButton("Gross Pay"); AddClearExit[0].setLocation(225,750); AddClearExit[0].setSize(150,20); AddClearExit[0].addActionListener(this); pane.add(AddClearExit[0]); AddClearExit[0] = new JButton("Net Pay"); AddClearExit[0].setLocation(825,750); AddClearExit[0].setSize(150,20); AddClearExit[0].addActionListener(this); pane.add(AddClearExit[0]); AddClearExit[0] = new JButton("Total Deduction"); AddClearExit[0].setLocation(1025,750); AddClearExit[0].setSize(200,20); AddClearExit[0].addActionListener(this); pane.add(AddClearExit[0]); AddClearExit[1] = new JButton("Clear"); AddClearExit[1].setLocation(425,750); AddClearExit[1]. setSize(150,20); AddClearExit[1].addActionListener(this); pane.add(AddClearExit[1]); AddClearExit[2] = new JButton("Exit"); AddClearExit[2].setLocation(625,750); AddClearExit[2].setSize(150,20); AddClearExit[2].addActionListener(this); pane.add(AddClearExit[2]); setVisible(true); setDefaultCloseOperation(EXIT_ON_CLOSE); } public void actionPerformed(ActionEvent ae) { String temp = ""; int bp=0,otr=0,grosspay=0,d=0,tw=0,sss=0,m=0,p=0,sssl=0, pl=0,totaldeduction=0,netpay=0; try { bp=Integer.parseInt(textJT[2].getText()); otr=Integer.parseInt(textJT[4].getText()); grosspay=Integer.parseInt(textJT[15].getText()); tw=Integer.parseInt(textJT[8].getText()); sss=Integer.parseInt(textJT[9].getText()); m=Integer.parseInt(textJT[10].getText()); p=Integer.parseInt(textJT[11].getText()); sssl=Integer.parseInt(textJT[12].getText()); pl=Integer.parseInt(textJT[13].getText()); totaldeduction=Integer.parseInt(textJT[14].getText()); netpay=Integer.parseInt(textJT[6].getText()); } catch (Exception ne) { for(int x=0;x<16;textJT[x].setText(temp),x++); } if(ae.getActionCommand().equals("GrossPay")) {temp+=grosspay (bp*otr); textJT[5].setText(temp);} else if(ae.getActionCommand().equals("NetPay")) {temp+=netpay (grosspay-totaldeduction); textJT[6].setText(temp);} else if(ae.getActionCommand().equals("TotalDeduction")) {temp+=totaldeduction (tw+sss+m+p+sssl+pl); textJT[15].setText(temp);} if(ae.getActionCommand().equals("Clear")) for(int x=0;x<16;textJT[x].setText(temp),x++); if(ae.getActionCommand().equals("Exit")) dispose(); } public int grosspay(int x,int y) { return x*y; } public int netpay(int x,int y) { return x-y; } public int totaldeduction(int x,int y) { return x+y; } public static void main (String args[]) { new Button(); } } Similar TutorialsLooking at http://www.directv.com for example: You highlight over the specific sections of their navigation bar, such as "What is DIRECTV?" and it displays sub-options below the section. How would one go about this, and what would the best way to do this? I'm sorry if this wouldn't even be JavaScript; my knowledge doesn't exceed simple coding. Also, I've heard you should use CSS image rollover effects instead of JavaScript for image highlighting because it prevents there from being a second where no image has loaded. How would I prevent that in this case? And a completely unrelated question: Looking at the source of directv's website, there is a LOT of unneeded entering. Is there any reason they did that? Just curious ;p Thanks Hello! I am trying to make a form, with different options and, upon hitting submit, a new page will open with the created URL. for example: 1) Enter the URL: user enters: http://www.supertown.com 2) Enter the city: user enters: Chico 3) Enter the state: user enters: CA [SUBMIT] Then the following window opens: http://www.supertown.com?city=Chico&state=CA Ive been trying to figure this out for over an hour...AHH! I am confused about what the return keyword is actually returning when returning an object, a primitive, or a function. My confusion is compounded by the fact that I'm not sure if a function is an object or not. According to the book JavaScript Programmer Reference it is: "All functions in JavaScript are first class objects , meaning they can be passed around like any other object reference. In fact, regardless of how they are created, functions are instances of a global object named (aptly) Function." However, someone else states that a function is not an object. An object is a set of primitives and references. A function is executable code. Functions become objects through the use of the new operator. Yet, in the book I mentioned, it says you don't need the new keyword to execute the function as an object, as it already inherits from the object Function when the function keyword is used: Code: function functionName([argname1 [, ...[, argnameN]]]) { statements; } So there's one source of contradiction. Now the bigger issue is what is going on when the return keyword is used. Notice the Validation() function returns an object as its last expression. This technique is common, where you return an object which contains functions in form of object notation. I believe this is done so that we create a closure so that when the intepreter exits the Validation() method, since we created a closure by returning an object, which contains the inner functions addRule and getRule, the local variables of Validation() are not destroyed, given that we can reference them through the two inner functions that make use of the local variables of the outer function. So when we use the return keyword on an object literal, and then exit the function, when we call one of the inner functions as we do later: Code: var rule = $.Validation.getRule(types[type]); essentially getRule() is called, passes an argument, which is received by the inner function as parameter we call name: Code: getRule : function(name) { return rules[name]; } First, note that the return {} is written in object notation, therefore making getRule a local variable and, thus, private function only accessible through the namespace of Validation(). Validation() declares the rules local variable and because of the closure, we can access the rules local variable through the getRule() inner function. *****Here's the part that really thows me off. We return rules[name]. So let's say name is equal to email. This is an associative array so email (held in name) is a property of rules. So here we return the object's property: Code: return rules[name]; And then assign it to a local variable called rule: Code: var rule = $.Validation.getRule(types[type]); So when we return an object rules[name], do we return a reference to an object or a value? In other words, by returning rules[name], where name is equal to email, are we then returning a reference to the following object literal: Code: email : { check: function(value) { if(value) return testPattern(value,".+@.+\..+"); return true; }, msg : "Enter a valid e-mail address." } And if we are returning a reference, by returning a reference, are we essentially pointing to this object when we assign it to rule? In other words, the variable rule is just pointing to the object literal? And is that the reason we can then access the check function or msg local variable through rule using dot notation, because rule points to the email object literal? Now the ultimate brain twist for me is that if a function is an object, then why when return a function, it returns a value, such as a boolean, if an object only returns a reference and not the value? Code: //Validation is a local variable as it is in a self-executing anonymous function. The purpose of the said anonymous function is to pass the jQuery object as a parameter $ so the $() function will be in scope of the anonymous function and not interfere with other libraries that make use of the same function technique - in the global scope. (function($) { var rules = { email : { check: function(value) { if(value) return testPattern(value,".+@.+\..+"); return true; }, msg : "Enter a valid e-mail address." }, url : { check : function(value) { if(value) return testPattern(value,"https?://(.+\.)+.{2,4}(/.*)?"); return true; }, msg : "Enter a valid URL." }, required : { check: function(value) { if(value) return true; else return false; }, msg : "This field is required." } } var testPattern = function(value, pattern) { var regExp = new RegExp("^"+pattern+"$",""); return regExp.test(value); //The test() method is built into javascript } return { addRule : function(name, rule) { rules[name] = rule; }, getRule : function(name) { return rules[name]; } } } /* Form factory */ var Form = function(form) { var fields = []; $(form[0].elements).each(function() { var field = $(this); if(field.attr('validation') !== undefined) { fields.push(new Field(field)); } }); this.fields = fields; } Form.prototype = { validate : function() { for(field in this.fields) { this.fields[field].validate(); } }, isValid : function() { for(field in this.fields) { if(!this.fields[field].valid) { this.fields[field].field.focus(); return false; } } return true; } } /* Field factory */ var Field = function(field) { this.field = field; this.valid = false; this.attach("change"); } Field.prototype = { attach : function(event) { var obj = this; if(event == "change") { obj.field.bind("change",function() { return obj.validate(); }); } if(event == "keyup") { obj.field.bind("keyup",function(e) { return obj.validate(); }); } }, validate : function() { var obj = this, field = obj.field, errorClass = "errorlist", errorlist = $(document.createElement("ul")).addClass(errorClass), types = field.attr("validation").split(" "), container = field.parent(), errors = []; field.next(".errorlist").remove(); for (var type in types) { var rule = $.Validation.getRule(types[type]); if(!rule.check(field.val())) { container.addClass("error"); errors.push(rule.msg); } } if(errors.length) { obj.field.unbind("keyup") obj.attach("keyup"); field.after(errorlist.empty()); for(error in errors) { errorlist.append("<li>"+ errors[error] +"</li>"); } obj.valid = false; } else { errorlist.remove(); container.removeClass("error"); obj.valid = true; } } } /* Validation extends jQuery prototype */ $.extend($.fn, { validation : function() { var validator = new Form($(this)); $.data($(this)[0], 'validator', validator); $(this).bind("submit", function(e) { validator.validate(); if(!validator.isValid()) { e.preventDefault(); } }); }, validate : function() { var validator = $.data($(this)[0], 'validator'); validator.validate(); return validator.isValid(); } }); $.Validation = new Validation(); })(jQuery); Thanks for any response. I'm using the jquery plugin found here. I love the look but I have a form that uses functions like this: Code: function cascadeCountry(value) { if (document.getElementById("srchlookstate_province") != null) { http.open('get', 'cascade_search.php?a=country&v=' + value ); document.getElementById('srchlookstate_province').innerHTML=" "+loadingTag; http.onreadystatechange = handleResponse; http.send(null); } } So, when you select a country and it retrieves the state/province text input, the jquery css is not applied to it. Is there something I need to add to the code above or to the jquery initialization code he Code: $(function() { $("form.jqtransform").jqTransform(); }); Does anyone know why I am not getting an alert on an empty form INPUT value? Code: if (document.forms["form"]["targetname"].value == "" && document.forms["form"]["unknownname"] == false) { alert ("What ever"); return false; } document.forms["form"]["targetname"] is a form INPUT text document.forms["form"]["unknownname"] is a form INPUT checkbox I suspect the problem is due to 'false'.. but I can't figure out why. How can I change the day when the user select a month? When they select Feb ->29 days, select May -> 31 days. Like what facebook does. Can anyone tell me what I have done wrong here? I have the following html code Code: <div id='group1'> <tr class='time'> <td colspan='3' name='1262815200'></td> </tr> <tr> <td class='timeleft group1' name='1262815200' colspan='3'></td> </tr> <tr class='game'> <td><input type='radio' name='G1' value='NYJ'>NYJ</td> <td><input type='radio' name='G1' value='BUF'>BUF</td> <td><select name='G1P' class='points' tabindex = '1'></select></td> </tr> </div> and when I use the selector $('#group1 input) it does not select anything (namely the inputs in this code). But when I use the selector $('div input') it will select them (and more on the page which I don't want). Is anyone able to see what I have done wrong? I've tried everything I can think of in terms of testing, and I have narrowed it down to the selector. Thanks. Hi, I'm trying to figure out how to make this work and I'm stumped. I wrote this code: <script type=text/javascript> function firstfunction(); { if(document.form1.inputnumbers.value="55"); { document.form1.outputstate.value="this is a number"; } else if { document.form1.inputnumbers.value="never"; } { document.form1.outputstate.value="this is a number"; } else { document.form1.outputstate.value=""; } </script> <form name="form1" method="post"> <input type="text" id="inputnumbers" name="inputnumbers";> <input type="button"; value="Enter"; onclick="firstfunction()"><br><br> <textarea id="outputstate"; name="outputstate"; cols=60; rows=10; style="border:1"; readonly;> I'm trying to doing something really simple but I can't seem to make it work. I'm trying have the textarea display a certain message depending on if the first input box says a certain word or number. So like in the code, if the user types "55" or "never" in the first box, then the second box should say a certain message. Then I used the else statement so that if "55" or "never" is not entered, then the second box says nothing. If you can spot my error or suggest a different way of going about writing the code, it would be very much appreciated. Thank you. I have tried many ways to do this and have also searched the forum, no go. I was doing it manually doing this: Code: Math.round((#)*100)/100 But no go, so I found this function here on the forum: Code: function roundNumber(num, dec) { var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec); return result; } No go, it works yes, don't get me wrong. But I am working on a invoicing system and it needs to be exact. For instance with this number: Quote: 0.27470000001 It returns 0.27, when in reality it should return 0.28 because of the 7 changes the 4 to 5 and then 5 changes the 7 to 8. But it doesn't work. While reading some things I found while searching google I see that Math.round doesn't work 100% the way it should mathematically. So what options do I have left, I can't believe that a simple rounding calculationg that excel can do ha ha JS cannot. Hello coding forum users, I am working on the only javascript chapter of my HTML textbook. It asks me to: Quote: replace the line <img id="sky" src="sky0.jpg" alt=""/> with a script element that writes the following HTML code: <img id='sky' src='mapNum.jpg' alt=' ' /> where mapNum is the value of the mapNum variable. so I try PHP Code: <script type="text/javascript" /> document.write("<img id='sky' src='mapNum.jpg' alt=' ' />") </script> after a few other attempts I search codingforums and find: PHP Code: document.write("<img id=\"sky\" src='sky"+mapNum+".jpg' alt='' />"); and PHP Code: document.write('<img id="sky" src="sky'+mapNum+'.jpg" alt="" />'); and these work perfectly fine but I don't understand why? my textbook only has one javascript chapter and its really small and vague, and my teacher hasn't answered my emails, so I would be grateful if anyone can tell my why my first code falls flat. I found and am using the following script to add checkbox values to a textarea. Code: <script type="text/javascript"> function add_sub(el){ if (el.checked) el.form.elements['type'].value+=el.value; else{ var re=new RegExp('(.*)'+el.value+'(.*)$'); el.form.elements['type'].value=el.form.elements['type'].value.replace(re,'$1$2'); } } </script> </head> <body> <form name="form1" method=post> <textarea name="type" rows="5" cols="35" onclick="this.focus();this.select();"> </textarea><br> <input type="checkbox" name="bob" id="bob" value="<p>" onclick="add_sub(this);"><label for="bob"><p></label><br> <input type="checkbox" name="bob1" id="bob1" value="<span>" onclick="add_sub(this);"><label for="bob1"><span></label><br> <input type="checkbox" name="bob2" id="bob2" value="<div>" onclick="add_sub(this);"><label for="bob2"><div></label> That is working. However, I wanted to put carriage returns after each checkbox value added, so I added the + "\r\n" as follows: Code: <script type="text/javascript"> function add_sub(el){ if (el.checked) el.form.elements['type'].value+=el.value + "\r\n"; else{ var re=new RegExp('(.*)'+el.value+'(.*)$'); el.form.elements['type'].value=el.form.elements['type'].value.replace(re,'$1$2'); } } </script> That is working when adding the value, but removing the value when the checkbox is unchecked is not working. I know the regular expression, etc. needs to be updated to account for the carriage returns, but I have tried everything I can think of and cannot get it to work. Help correcting the code is appreciated. Which of these is the correct way to set the className attribute, or are they both okay? option 1: Code: var t = document.createElement("p"); t.className = "myclass"; option 2: Code: var t = document.createElement("p"); t.setAttribute("class","myclass"); Good evening. I'm very new to this, but very excited that I've gotten this code so close. I am trying to get the computer to determine if a number is even or not. This is what I have: [CODE] <script type = "text/javascript"> <!-- var firstNumber; // first string entered by user var answer; // the division problem // read in first number from user as a string firstNumber = window.prompt("Enter an integer"); //how to get a remainder var answer = firstNumber / 2 if (answer > 1) { document.writeln(answer + ". This number is even."); } </script> The bottom part is the problem. I am able to code that if the answer is greater than one, then return the following text, however, I can't for the life of me figure how to say... if the remainder is zero. Thank you, Hey guys, I am doing a website and the way it is suppose to work is when you click on a link there is a little triangle beside it, so when you click on it the triangle is suppose to face down but more links appear when you click on it. Anyways here is the code if someone could please tell me what im doing wrong? HTML Code: <ul class="menu" id="subnavmenu"> <li><a href="#" onClick="showHide('sublist1');return false;" id="subheading">About Us</a> <ul id="sublist1" style="display:none;"> <li><a href="#">Visit Us</a></li> <li><a href="#">Contact Us</a></li> <li><a href="#">Archives Unboxed and Revealed</a></li> </li> </ul> CSS Code: #subnavmenu ul.menu { display: block; overflow:hidden; } JAVASCRIPT Code: function showHide(element_id) { if (document.getElementById && document.getElementById(element_id) && document.getElementById(element_id).style) { var menu = document.getElementById(element_id); var arrow = document.getElementById(element_id + '_arrow'); if (menu.style.display == "block") { menu.style.display = "none"; if (arrow.src) { arrow.src = arrow.src.replace("down","right"); } } else { menu.style.display = "block"; if (arrow.src) { arrow.src = arrow.src.replace("right","down"); } } } } I feel like I must be missing something simple but I can't put my finger on it... I'm moderately new to JS (programmed in other languages though) and am working on a Google Maps project. This piece of code should show an alert of the region's name when a map polygon is clicked. Instead, no matter what polygon is clicked, it only does the name for the LAST iterated placemark. Code: for (var i = 0; i < placemarks.length; i++) { placemark = placemarks[i] google.maps.event.addListener(placemark.polygon, "click", function() { alert(placemark.name); }); } What am I misisng? What would be a better way of handling this? Hi there. I have a table which I would like to be highlighted with the click of a button, but I can't seem to reference it correctly. I can make the <td> clickable and function, but when I try to apply it to the button I can't make it reference the td cell, rather than change the background color of the button. The function is: function roll(obj){ obj.style.backgroundColor == "pink" ? obj.style.backgroundColor = "#e5e5e5" : obj.style.backgroundColor = "pink"; } Html: <td style="background-color:#e5e5e5;"><img onmousedown="roll(this);" src="images/plus.png" title="Highlight Lot" /></td> Thanks a lot!! :) Sorry if this is the wrong forum for this question. I get confused about what forum to post a question in with regards to DHTML technologies since they are all frequently used together. Anyhoo, heres my question. I've recently discovered an interesting behavior. When I mouse over a nested element it triggers the 'onmouseout' event handler of the parent element. Take the following code snippet, for instance: Code: <table> <tr> <td onmouseout="window.alert('you moused out of td');"> <img src="image0.gif" style="height:50px; width:50px;" /> </td> </tr> </table> In the code snippet above, the 'onmouseout' event handler executes when you mouse over the image nested inside the <td> element. I wouldn't have thought this would be the appropriate behavior since from my perspective the mouse is still inside the <td> element. Can someone make comments on this. Thank You. Edit: I've discovered that mousing over a nested element causes both an 'onmouseout' and an 'onmouseover' event for the parent element. They are called back to back. Seems a little bit of an odd sequence of events but maybe it makes sense in the grand scheme of things. Yeah, right. Whats wrong with the code below? I'm trying to get the email service provider name. Code: <html> <head> <script type="text/javascript"> function GetProvider { var fullemail = openinviter.email_box.value; var afterat = fullemail.split("@"); var Provider = afterat[1].split("."); var showit = Provider[0]; openinviter.provider_box.value=showit; } </script> </head> <body> <form action="" method="post" name="openinviter"> <input type="text" name="email_box" onchange="GetProvider()" /> <input type="text" name="provider_box" value=""> </form> </body> </html> Thanks alot! I'm brand new to JavaScript, and I come from a purely logical scripting background so forgive me if this is the most poorly formed code/bad technique that you've recently seen. I've played the google games for days and I surrender. I usually find a way to fight through it and figure it out, but I'm going to have to cede this one. I'm simply trying to put a new tab next to a tab that is already present on a page (classed: mirrortab_first) I'm trying to use XPath to select the element and then place newTab before it. Seemed simple enough to start. But as the code sits, the tab always winds up at the bottom of the page. Any thoughts? Kind regards. Code: var newTab = document.createElement("div"); newTab.setAttribute('id','newTab'); newTab.innerHTML = '<table cellpadding="0" cellspacing="0" border="0"><tbody><tr>' + '<td class="mirrortab_first"> </td>' + '<td class="mirrortab_back">' + '<a style="cursor:pointer;">Hide Classifieds</a>' + '</td>' + '<td class="mirrortab_last"> </td>' + '</tr></tbody></table></div>'; var tabLocation = document.evaluate('//td[contains(@class, "mirrortab_first")][1]',document,null,XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,null); for (i=0; i<tabLocation.snapshotLength; i++) { tL = tabLocation.snapshotItem(i).parentNode; } document.body.insertBefore(newTab, document.tL); i am making a simple multiple choice quiz and if user gets all correct i need it to automatically go to a new page rather than having a manual button for that so they cant move on until all questons are answered correctly. Most reatful for anyhelp!!!!!! Thanks Code: <SCRIPT Language ="JavaScript"> function ValidateForm(){ result = new Array(); count = 0; if (!document.forms[0].one[3].checked == true) { result[count] = "Question 1. The correct answer is " + document.forms[0].one[3].value + "."; count++; } if (!document.forms[0].two[0].checked == true) { result[count] = "Question 2. The correct anwser is " + document.forms[0].two[0].value + "."; count++; } if (!document.forms[0].three[3].checked == true) { result[count] = "Question 3. The correct answer is " + document.forms[0].three[3].value + "."; count++; } if (!document.forms[0].four[3].checked == true) { result[count] = "Question 4. The correct answer is " + document.forms[0].four[3].value + "."; count++; } if (result.length > 0) { var vString = ""; for (var i=0; i<result.length; i++) { vString = vString + result[i] + "\n"; } alert(result.length + " incorrect answers:\n" + vString); return(false); } else { alert("All of the questions were answered correctly."); return(true); } } function MM_goToURL() { //v3.0 var i, args=MM_goToURL.arguments; document.MM_returnValue = false; for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'"); } </SCRIPT> |