JavaScript - Dollar-sign Prefix For Variables?
hi.
i know php but learning javascript. can anybody give me a reason why i might not wanna use the php practice of beginning every variable_name with a dollar-sign: $variable_name??? i am just accustomed to seeing my variables beginning with a dollar_sign. Thanks. Similar TutorialsSo if I have three dollar amounts like .... a = 1,222.00; b = 1,323.00; c = ; d = 1,222.00; How can I alert the highest variable even though there may be 1 or more of them? I have the following code as shown below: Code: <script type="text/javascript"> var a = 12; var b = 35; var c = 56; document.write(a.toString(36).toUpperCase() + "<br>"); document.write(b.toString(36).toUpperCase() + "<br>"); document.write(c.toString(36).toUpperCase() + "<br>"); </script> The problem right now is that for the first 36 number, it always miss the 'prefix 0'. From the code above, it will return the following: Code: C Z 1K My intention was to have all of them display in two character format, as shown below: Code: 0C 0Z 1K May I know how should I do it without having to use if (a < 36) else ... statement? Looking for an example of how to take the value typed in one textbox to be calculated and update the value of a second texbox on the fly. The calculation is, (2.9% X first textbox value) + $0.30 = second textbox value So how do add a dollar sign the the front of total?? Code: total = round_decimals(order_total, 2) total = "$" + total; I really don't know what I am doing, but I need to know how to alter this script to load this website without having to click "Weathersentry online". I would like to double click on the icon the code is attached to and it sign in automatically. Can anyone help? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Sample Signin link WeatherSentry Online</title> </head> <body> <form id="DTNSigninForm" action="http://weather.dtn.com/dtnweather/common/signin.do" style="margin: 0,0,0,0;" > <a onclick='document.getElementById("DTNSigninForm").submit();return false;' href="javascript:void(0);">WeatherSentry Online</a> <input type="hidden" name="username" value="username" /> <input type="hidden" name="password" value="password" /> <input type="hidden" name="autoLogin" value="true" /> </form> </body> </html> I almost got part of this one program to work. It is of a golf sign with a golf ball moving across and landing in the word Golf into the "o" When the ball lands in the o the sign of "your online source of golf equipment" appears after ball has landed and grows in size. right now the ball is what I have but I can not get my sign to appear. I use 2 external files I will post all the coding here here is my main file I worked on this is my golfpage.htm file Code: <html> <head> <!-- New Perspectives on JavaScript Tutorial 4 Case Problem 1 The Golf Page Author: Date: 05 December 2010 Filename: golfpage.htm Supporting files: ball.gif, clouds.jpg, golf.js, golfer.gif, styles.css --> <title>The Golf Page</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="golf.js" type="text/javascript"></script> <script type="text/javascript"> var x = new Array(-395, -389, -383, -377, -371, -365, -359, -353, -346, -340, -334, -328, -322, -316, -310, -304, -297, -291, -285, -279, -273, -267, -261, -255, -248, -242, -236, -230, -224, -218, -212, -206, -199, -193, -187, -181, -175, -169, -163, -157, -150, -144, -138, -132, -126, -120, -114, -108, -101, -95, -93, -91, -88, -86, -83, -81, -78, -76, -73, -71, -69, -66, -64, -61, -59, -56, -54, -51, -49, -47, -44, -42, -39, -37, -34, -32, -29, -27, -24, -22, -20, -17, -15, -12, -10, -7, -5, -2, 0); var y = new Array(-300, -300, -300, -299, -298, -297, -296, -294, -292, -290, -288, -285, -282, -279, -276, -272, -268, -264, -260, -255, -250, -245, -240, -234, -228, -222, -216, -209, -202, -195, -188, -180, -172, -164, -156, -147, -138, -129, -120, -110, -100, -90, -80, -69, -58, -47, -36, -24, -12, 0, -5, -10, -14, -18, -22, -25, -29, -32, -34, -37, -39, -41, -43, -45, -46, -47, -48, -48, -48, -48, -48, -48, -47, -46, -45, -43, -42, -40, -37, -35, -32, -29, -26, -23, -19, -15, -11, -6, 0); var index=0; var lastindex=x.length-1; // var fs=getFontSize("slogan"); function moveBall() { if (index <= lastindex) { placeIt("Ball", x[index], y[index]); index++; setTimeout("moveBall()", 5); } else { setFontSize("slogan", 25); } } </script> </head> <body onload="moveBall()"> <div id="Golfer" ><img src="golfer.gif" width="40px" alt="" /></div> <div id="Title"> THE G<div style="display: inline; position: relative; background-color: black;" ><img id="Ball" src="ball.gif" alt="O" /></div>LF PAGE </div> <div id="box" style=""> <span id="slogan"> Your Online Source of Golf Equipment </span> </div> </body> </html> Here is one external file where I made some functions this is the golf.js file Code: New Perspectives on JavaScript Tutorial 4 Case Problem 1 The Golf Page Name: Date: 05 december 2010 Function List: placeIt(id, x, y) Places the id object at the coordinates (x, y) showIt(id) Shows the id object by setting the object visibility to "visible" getFontSize(id) Retrieves the font size of the id object setFontSize(id, fs) Sets the font size of the id object to fs changeFontSize(id, dfs) Changes the font size of the id object by dfs */ function showIt(id) { object=document.getElementById(id); object.style.visibility="visible"; } function placeIt(id, x, y) { // Places the id object at the coordinates (x,y) object = document.getElementById(id); object.style.left = x + "px"; object.style.top = y + "px"; } function getFontSize(id) { // Returns the font size of the object with the value id object = document.getElementById(id); size = parseInt(object.style.fontSize); return (size); } function setFontSize(id, ptsize) { // Sets the font size of the object with the value id object = document.getElementById(id); object.style.fontSize = ptsize + "pt"; } function changeFontSize(id, dfs) { // Returns the font size of the object with the value id fs = getFontSize(id); setFontSize(id, fs + dfs); } Here is the styles.css page Code: /* New Perspectives on JavaScript Tutorial 4 Case Problem 1 Filename: styles.css This file contains styles used in the golfpage.htm file */ body {font-family:Arial, Helvetica, sans-serif; font-size: 18pt; color:blue; background-image: url(clouds.jpg)} #Title {position: absolute; left:395px; top:260px} #Ball {position:relative; top:0px; left:0px} #Ball img {border-width: 0px} #box {width:600px; height: 250px; border-style:solid; border-width:1 4 4 1; border-color:blue; background-color:rgb(0,255,0); text-align: center} #slogan {visibility: hidden; position: relative; top: 50px; color:black; font-family: Times New Roman, Times, serif; font-style:italic; font-weight:bold} What i am not able to get work i think is to call the changeFontSize() function to increase the size of the "sign" also an if statement to test value of fs variable is less then equal to 20 how do i get my sign to appear on the output? thanks Hello all, Please I need help, I have a php form with different fileds. I have a field called description. The description field should only contains pure text, no numbers, but my users are entering phone numbers and email addresses into this field despite to the fact that there is already dedicated fileds for email and phone. What I want is a javascript funtion or php function that will automatically delete the numbers or @ from the field or prevent entering numbers and @ signs on this particular field. Many thanks in advance for your help. Hello! Looking for some help/advice please. Imagine a wife has signed on to a web site in a browser tab. She does not sign off and walks away to do something else. Her husband sits at the computer and seeing her signed on, opens a new tab and tries to sign on to the same site. I am trying to write a script that will close other tabs/windows when the husband goes to the same site to sign on. So, on the sign on page (or even better, the sign off page), when the sign on button is clicked, a piece of Javascript code is run first. The javascript simply goes through all tabs on the browser, and checks to see if any such tabs has an HTML document that came from the same domain as the sign on page. If such tabs exist, then before POSTing the user name and password to the server, the Javascript code will close those tabs that contain HTML documents came from the same domain. So, I understand I need to set the window.name to a specific value. But does anyone know what the code on the sign on/sign off page to close the other tabs/windows would look like? Thanks so much for any and all help. Hi there, I would like to allow the "+" sign in my 3 textboxes. When the user does not put the "+" sign in the textboxes, and it is being validated, the system will allow it to pass. Also, it must check that it has at least 8 digits. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> <link rel="stylesheet" type="text/css" href="CSS files/specialAlignment.css" /> <link rel="stylesheet" type="text/css" href="CSS files/externalCSS.css"/> <script language = "javascript" type = "text/javascript"> function check() { var fields = new Array("Office Telephone", "Mobile Telephone","Fax Number"); var telnr = /(^[\+]?[\d]{8,20}$)/; var index = new Array(); for(var i = 0; i < fields.length; i++) { var arrayFields = document.getElementsByName(fields[i]); for(var j = 0; j < arrayFields.length; j++) if(!(arrayFields[j].value) == "") { arrayFields[j].className = "defaultColor"; } else { arrayFields[j].className ="changeToRed"; index.push(fields[i]); } } if(index != 0) { joinComma = index.join(', '); alert('The field(s) corresponding to '+ joinComma + ' is/are not filled in.'); } } function noSpace(e, dec) { var key; var keychar; if (window.event) { key = window.event.keyCode; } else if (e) { key = e.which; } else { return true; } keychar = String.fromCharCode(key); if ((key==null) || (key==0) || (key==8) || (key==9) || (key==13) || (key==27) /*|| (key==107)*/) { return true; } else if ((("0123456789").indexOf(keychar) > -1)&& check(telnr.test(tfld))) { return true; } else if (dec && (keychar == ".")) { return true; } else return false; } </script> </head> <body> <label> *Office Telephone:</label> <input id="Text16" type="text" name="Office Telephone" onkeydown="return noSpace(event)" /> <br /> <br /> <label> *Mobile Telephone:</label> <input id="Text17" type="text" name="Mobile Telephone" onkeydown="return noSpace(event)" /><br /> <br /> <label> *Fax Number:</label> <input id="Text18" type="text" name="Fax Number" onkeydown="return noSpace(event)" /> <br /> <br /> <input id="Submit17" type="submit" value="Submit" onclick="return check()"/> </body> </html> hello i am editing a javascript game and im trying to get a heading (h1) to display the value of a variable in a javascript function however everything i have tried always causes an error. Any help will be apreciated. I wrote a script: when the same button is clicked for the first time, it should give a message "Hello World", for the second time "hello Earth". The script is not working. I don't want anybody to re-write the script, but to look at how i define variables and tell me where I am wrong. I think, this is where the main error is. my current script just outputs the message "hello world". my assumption is that functions can alter the value of a global variable. Thank you very much. Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title> title</title> <meta http-equiv="content-type" content="text/html;charset=UTF-8" /> <script type="text/javascript"> var count=0; function changePar() { if(count===0) first(); if(count===1) second(); } function first() { document.getElementById("changingParagraph").innerHTML="Hello World"; var count=1; } function second() { document.getElementById("changingParagraph").innerHTML="Hello Earth"; var count=0; } </script> </head> <body> <button onclick="changePar()">Click Here</button> <p id="changingParagraph"></p> </body> </html> Noob here. Please bear with me.http://www.codingforums.com/images/smilies/tongue.gif <span title="this is the title">....</span> I need to use variables for the title instad of text. Please advise. Thank you. I hope someone can help me! I have a website that sells a product through a third party merchant - ie a customer clicks my "buy now" button and they are transfered to the merchants payment processing page. once the transaction is complete the customer is sent back to my thank you page where I give them some extra stuff for free. All pretty normal I guess. The problem is this - The merchant sends back some url parameters when they transfer the customer to the thank you page and I would now like to use the "customer name" parameter to personalise the thank you page to test if this makes any difference to my return rate. Now, whilst I am not a complete newbie I haven't got a clue how to achieve this. What I want to do is have the page display: "Hello [customer] .....etc..." The customer name parameter is passed as "cname" and is one of about a dozen passed seperated, presumably, by "&" Thanks for any help! Paul Hi All Please could any one shed some light on the values of thirdVar fourthVar and fifthVar. Am i correct to say that value of thirdVar is o cromwell Any help and explanation would be great thanks. var firstVar = 'oliver' var secondVar = 'cromwell' var thirdVar = firstVar.charAt (0) + '. ' + secondVar var fourthVar = thirdVar.length var fifthVar = 'The last character is' + thirdVar.charAt (fourthVar) + '!' can anyone tell me why this doesn't work please: <html> <head> </head> <body> <input type="hidden" name="ba1r1c1" value="hello"> <script language="text/javascript"> ba1r1c1.value = "goodbye"; document.write(ba1r1c1.value); </script> </body> </html> thanks Hello, Does anyone know how to list all declared variables in JavaScript ? tnx Hello, I am using javascript to dynamically edit a form and have run into some problems. In this excerpt of code "x" is already defined, "num" is already defined, and "eval(q)" is just pointing to the proper field in the proper form. Code: eval(q).onkeydown=function onkeydown(event) { checkLength(event,x,num,5); }; Now the problem is, it is literally calling the function with "x" and "num" instead of their values. I tried "eval(x)" and "eval(num)" but that literally calls it with that whole statement as the parameter. How can I call this with the actual values inside of x and num? Thank you. I have this code, (a snippet of it below) which works, but how can I simplify it instead of repeating all the same code for the 12 different checks I have to run. If whatColor == A1 I need the search variable to equal fashion If whatColor == A2 I need the search variable to equal photography etc. Thanks Code: if (whatColor == 'A1') { /* search: 'fashion', */ new TWTR.Widget({ version: 2, type: 'search', search: 'fashion', interval: 2000, title: '', subject: '', width: 310, height: 240, theme: { shell: { background: '#edecee', color: '#444444' }, tweets: { background: '#edecee', color: '#444444', links: '#e80f45' } }, features: { scrollbar: true, loop: false, live: true, hashtags: true, timestamp: true, avatars: true, behavior: 'all' } }).render().start(); } else if (whatColor == 'A2') { /* search: 'photography', */ new TWTR.Widget({ version: 2, type: 'search', search: 'photography', interval: 2000, title: '', subject: '', width: 310, height: 240, theme: { shell: { background: '#edecee', color: '#444444' }, tweets: { background: '#edecee', color: '#444444', links: '#e80f45' } }, features: { scrollbar: true, loop: false, live: true, hashtags: true, timestamp: true, avatars: true, behavior: 'all' } }).render().start(); The Code, is from a twitter widget that pulls a twitter feed based on the search variable. This is the code straight from twitter. Code: <script src="http://widgets.twimg.com/j/2/widget.js"></script> <script> new TWTR.Widget({ version: 2, type: 'search', search: 'photography', interval: 2000, title: '', subject: '', width: 310, height: 240, theme: { shell: { background: '#edecee', color: '#444444' }, tweets: { background: '#edecee', color: '#444444', links: '#e80f45' } }, features: { scrollbar: false, loop: false, live: true, hashtags: true, timestamp: true, avatars: true, behavior: 'all' } }).render().start(); </script> Hi there, Greetings, I have limited knowledge on Javascript. I wish someone could help me out. Thanks. I have actually found a free script named "Image Flow" (http://finnrudolph.de/ImageFlow/Examples) on the website. Then, I have uploaded it to my web server. Everything was fine and functioning well. I would like to add in new Var (to make new window appears after clicking) according to the codes given but failed to do so. The codes given are A) Code: var target_1 = new ImageFlow(); target_1.init({ ImageFlowID: 'target_1,' onClick: function() {window.open(this.url, '_blank');} }); Then, I just added the above code into imageflow.JS and imageflow.packed.JS. (I have attached the file below) Original: Code: domReady(function() { var instanceOne = new ImageFlow(); instanceOne.init({ ImageFlowID:'myImageFlow' }); }); After amendment: Code: domReady(function() { var instanceOne = new ImageFlow(); instanceOne.init({ ImageFlowID:'myImageFlow' }); var target_1 = new ImageFlow(); target_1.init({ ImageFlowID: 'target_1,' onClick: function() {window.open(this.url, '_blank');} }); }); However, no pictures were loaded after that. Does it involve more than just "copy and paste"? Or what have I done incorrectly? Sorry to disturb you. Ok i'm really new at this so i apologize beforehand if i ask a stupid question or anything. I'm working on a project that displays a GUI asking for a name as well as grades. when you enter them all it runs the grades through a formula and opens another frame with the results. I don't need any help building the GUI what i need help on is I cannot for the life of me find out how to access the variable from another frame. Everything i've seen online tells me to set the variable outside the class but i need to run the formula inside because the grades come from the user. Sorry if my code is messy, like i said i'm very new at this Code: // Loads all neccesary plugins import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SInfo extends JPanel { // Setting all text fields, labels and button public JButton submitInfo; public JLabel SNamel, Asign, Asignl, Asign1l, Asign2l, Asign3l, Asign4l, Asign5l, Asign6l, Asign7l, Asign8l, Asign9l, Asign10l, Folderl, Projectl, Project1l, Project2l, Project3l, Project4l, GProjectl, blank, blank1, Sname, AsgnAvg, ProjectAvg, TotalAvg; public JTextField SName, Asign1, Asign2, Asign3, Asign4, Asign5, Asign6, Asign7, Asign8, Asign9, Asign10, Folder, Project1, Project2, Project3, Project4, GProject; double a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, p1, p2, p3, p4, gp, fldr, asgnAvg, projectAvg, totalAvg; public SInfo() { setLayout (new GridLayout (20,2)); // Sets the text for the labels { blank = new JLabel (""); blank1 = new JLabel (""); SNamel = new JLabel ("Student Name: "); Asign = new JLabel (""); Asignl = new JLabel ("--------Assignment Grades--------"); Asign1l = new JLabel ("Assignment 1: "); Asign2l = new JLabel ("Assignment 2: "); Asign3l = new JLabel ("Assignment 3: "); Asign4l = new JLabel ("Assignment 4: "); Asign5l = new JLabel ("Assignment 5: "); Asign6l = new JLabel ("Assignment 6: "); Asign7l = new JLabel ("Assignment 7: "); Asign8l = new JLabel ("Assignment 8: "); Asign9l = new JLabel ("Assignment 9: "); Asign10l = new JLabel ("Assignment 10: "); Folderl = new JLabel ("Class Folder Grade: "); Projectl = new JLabel ("--------Project Grades--------"); Project1l = new JLabel ("Project 1: "); Project2l = new JLabel ("Project 2: "); Project3l = new JLabel ("Project 3: "); Project4l = new JLabel ("Project 4: "); GProjectl = new JLabel ("Group Project Grade: "); } // Button text and sets listener for it { submitInfo = new JButton ("Submit"); submitInfo.addActionListener (new SubmitListener()); } // Tells the program how long to make the textfield { SName = new JTextField (20); Asign1 = new JTextField (5); Asign2 = new JTextField (5); Asign3 = new JTextField (5); Asign4 = new JTextField (5); Asign5 = new JTextField (5); Asign6 = new JTextField (5); Asign7 = new JTextField (5); Asign8 = new JTextField (5); Asign9 = new JTextField (5); Asign10 = new JTextField (5); Folder = new JTextField (5); Project1 = new JTextField (5); Project2 = new JTextField (5); Project3 = new JTextField (5); Project4 = new JTextField (5); GProject = new JTextField (5); } // Adds the objects to the Window { add (SNamel); add (SName); add (Asign); add (Asignl); add (Asign1l); add (Asign1); add (Asign2l); add (Asign2); add (Asign3l); add (Asign3); add (Asign4l); add (Asign4); add (Asign5l); add (Asign5); add (Asign6l); add (Asign6); add (Asign7l); add (Asign7); add (Asign8l); add (Asign8); add (Asign9l); add (Asign9); add (Asign10l); add (Asign10); add (Folderl); add (Folder); add (blank1); add (Projectl); add (Project1l); add (Project1); add (Project2l); add (Project2); add (Project3l); add (Project3); add (Project4l); add (Project4); add (GProjectl); add (GProject); add (blank); add (submitInfo); } // sets size and color of the window { setPreferredSize (new Dimension(400,450)); setBackground (Color.gray); } } public class SubmitListener implements ActionListener { // Performs calculation and saves when button is clicked public void actionPerformed (ActionEvent event) { // Sets variables for the text fields Sname = new JLabel ("Student Name: " + SName); AsgnAvg = new JLabel ("Average of Assignments: " + asgnAvg); ProjectAvg = new JLabel ("Average of Individual Projects: " + projectAvg); TotalAvg = new JLabel ("Total Average for the year: " + totalAvg); // Assignments { String asgn1 = Asign1.getText(); a1 = Double.valueOf(asgn1); String asgn2 = Asign2.getText(); a2 = Double.valueOf(asgn2); String asgn3 = Asign3.getText(); a3 = Double.valueOf(asgn3); String asgn4 = Asign4.getText(); a4 = Double.valueOf(asgn4); String asgn5 = Asign5.getText(); a5 = Double.valueOf(asgn5); String asgn6 = Asign6.getText(); a6 = Double.valueOf(asgn6); String asgn7 = Asign7.getText(); a7 = Double.valueOf(asgn7); String asgn8 = Asign8.getText(); a8 = Double.valueOf(asgn8); String asgn9 = Asign9.getText(); a9 = Double.valueOf(asgn9); String asgn10 = Asign10.getText(); a10 = Double.valueOf(asgn10); } // Projects { String proj1 = Project1.getText(); p1 = Double.valueOf(proj1); String proj2 = Project2.getText(); p2 = Double.valueOf(proj2); String proj3 = Project3.getText(); p3 = Double.valueOf(proj3); String proj4 = Project4.getText(); p4 = Double.valueOf(proj4); String gproject = GProject.getText(); gp = Double.valueOf(gproject); String Sname = SName.getText(); // Folder String folder = Folder.getText(); fldr = Double.valueOf(folder); } // Math Formula { // asgnAvg = 20% // projectAvg = 45% // fldr = 10% // gp = 25% asgnAvg = (a1 + a2 + a3 + a3 + a5 + a6 + a7 + a8 + a9 + a10) / 10; projectAvg = (p1 + p2 + p3 + p4) / 4; totalAvg = (asgnAvg * .20) + (projectAvg * .45) + (fldr * .10) + (gp * .25); } { JFrame frame = new JFrame ("Student Average"); frame.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(new SInfo2()); frame.pack(); frame.setVisible(true); // Show the frame frame.setSize(300, 300); setBackground (Color.gray); frame.setVisible(true); } } } } And this is the second frame i am trying to open i haven't really done anything for the GUI i'm just working on it reading the variables now Code: // Loads all neccesary plugins import java.awt.*; import java.awt.event.*; import javax.swing.*; public class SInfo2 extends SInfo { // Setting all text fields, labels and button public JLabel Sname, AsgnAvg, ProjectAvg, TotalAvg; public SInfo2() { setLayout (new GridLayout (4,2)); { Sname = new JLabel (Sname); // These are the 4 I cannot retrieve AsgnAvg = new JLabel (asgnAvg); // These are the 4 I cannot retrieve ProjectAvg = new JLabel (projectAvg); // These are the 4 I cannot retrieve TotalAvg = new JLabel (totalAvg); // These are the 4 I cannot retrieve add (Sname); add (AsgnAvg); add (ProjectAvg); add (TotalAvg); } } } Thank you in advance for anyone who even looks at it |