JavaScript - Show All Variables
Hello,
Does anyone know how to list all declared variables in JavaScript ? tnx Similar TutorialsHow do I show the default icon for pdf, doc, etc... else show the image? Code: Show the default icon for pdf, doc, etc... else show image. Default icon: '<img alt="" src="images/icons/' + sIcon + '.gif" width="16" height="16" border="0"><\/a>' + The image: '<img alt="" src="' + fileUrl.replace( /'/g, '\\\'') + '" height="36" border="0"></a>' + Attempted javascript onError but only certain browsers support that or it's my code. Code: '<img alt="" src="' + fileUrl.replace( /'/g, '\\\'') + '" height="36" border="0" onerror="this.src=images/icons/' + sIcon + '.gif"></a>' + Any ideas? 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) + '!' 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 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> 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 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. Hi all Is there a way in Javascript to store a value to different variables in 1 command, something like: Code: Store 50 to nHeight,nWidth,nTop; or nHeight=nWidth=nTop=50; What I try to do is avoid errors by typing the value only once in code. I could do the following, but thought there might be a more direct way: Code: var nValueToStore = 50; nHeight = nValueToStore ; nWidth = nValueToStore ; nTop = nValueToStore ; Hello to all! Can I have 2 variables upon one select? The code below is created dinamicly with php from a database, and displays a dropdown select box, the only thing is that the values: Oliver Franchis, Pedro pastor, Maria China... have unique ID's and when the name is selected I would like the ID allso to be. Code: <!-- Populate list with friends START--> var newTextbox = document.createElement('select'); newTextbox.className = 'fn-select'; newTextbox.name = "opcion"; //First user in the populated select menu is the person Loged in var op1 = new Option("", "Oliver Franchis"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Me | Oliver Franchis'); op1.appendChild(txt1); //Next users are my friends in the database var op1 = new Option("", "Pedro pastor"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Pedro pastor'); op1.appendChild(txt1); var op1 = new Option("", "Maria China"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Maria China'); op1.appendChild(txt1); var op1 = new Option("", "Juan Testing"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Juan Testing'); op1.appendChild(txt1); var op1 = new Option("", "Carmen Hernandez"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Carmen Hernandez'); op1.appendChild(txt1); var op1 = new Option("", "Eduardo Palote"); newTextbox.appendChild(op1); var txt1 = document.createTextNode('Eduardo Pajote'); op1.appendChild(txt1); editAreaText.appendChild(newTextbox); editArea.appendChild(editAreaText); <!-- Populate list with friends END--> This is the function on the index.php page: Code: function saveNote (note) { resetAjax(); var photoId = note.container.element.id; ajax.setVar('action', 'save'); ajax.setVar('photo_id', photoId); ajax.setVar('note_id', note.id); ajax.setVar('left', note.rect.left); ajax.setVar('top', note.rect.top); ajax.setVar('width', note.rect.width); ajax.setVar('height', note.rect.height); ajax.encVar('text', note.gui.TextBox.value); ajax.runAJAX(); var statusDiv = document.getElementById('PhotoNoteStatus'); ajax.onCompletion = function () {statusDiv.innerHTML = "<p>Note saved.</p>"; } return 1; } All, I have the following code: Code: var http_request = false; function makePOSTRequest(url, parameters) { alert(parameters); http_request = false; if (window.XMLHttpRequest) { // Mozilla, Safari,... http_request = new XMLHttpRequest(); if (http_request.overrideMimeType) { // set type accordingly to anticipated content type //http_request.overrideMimeType('text/xml'); http_request.overrideMimeType('text/html'); } } else if (window.ActiveXObject) { // IE try { http_request = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { http_request = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } } if (!http_request) { alert('Cannot create XMLHTTP instance'); return false; } http_request.onreadystatechange = alertContents; http_request.open('POST', url, true); http_request.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); http_request.setRequestHeader("Content-length", parameters.length); http_request.setRequestHeader("Connection", "close"); http_request.send(parameters); } function alertContents() { if (http_request.readyState == 4) { if (http_request.status == 200) { result = http_request.responseText; document.getElementById('myspan').innerHTML = result; } else { alert('There was a problem with the request.'); } } } function getjob(obj) { var poststr = "job_id=" + encodeURI( obj ); makePOSTRequest('getnextjob.php', poststr); } I call the getjob but doing the following: echo "<li><a href=\"#\" onclick=\"javascript:getjob($resultsetjob[job_id]); return false;\">$resultsetjob[name]</a></li>"; It's weird, only sometimes does it pass the variable and other times it doesn't. Is there a better way to do this?? Thanks in advance. Hi, I'm looking to use the document function in javascript to change the TYPE of an INPUT. However I want to change the TYPE of the INPUT according to a variable passed to the javascript button, so i use: document.formname.inputname.value="newvalue"; I want to be able to change what inputname is depending on what is passed to the function, but right now firefox is telling me that it's undefined. Is there any way I can do this? Thanks in advance, Daniel Hi, Ive got a iphone based website im writing in html/javascript, it all works perfectly well apart from an issue with a javascript variable and i cant figure out what im doing wrong At the start of the code i declare a variable var jpgname='blank'; - its blank for testing I then have a href which attempts to change this variables value when clicked <li class="flip"><a onClick="jpgname='test'" href="#page">Cars</a></li> If i replace the jpgname='test' with confirm('test) i get a popupbox so i know its running this code under my #page section (just a div named section) i have [<h1><script>document.write(jpgname);</script></h1> however this always has the value 'blank' Im sure im doing something stupid but im not sure what Any help gratefully recieved thanks Mike I need to add onclick event to an element => myFunction(myVariable) but instead of the myVariable I need it's value to be set as an attr. As in: Code: <!html> <head> </head> <body> <input type="button" id="element" value="click me!"> <script type="text/javascript"> var myVariable = "myvalue"; document.getElementById('element').onclick = function () { showIt(myVariable); } myVariable = "myvalue2"; function showIt(msg){ alert(msg); } </script> </body> </html> Now i need the "click me!" input to alert "myvalue" and not "myvalue2". hello all I am working on a keyword filter and am stuck on something that I am hoping someone has more experience with my problem is that I am trying to pass a regular expression as a variable to the RegExp() function in javascript but it does not seem to be working example below Code: var X = '^(?=.*?('; var Y = 'dog))(?=.*?(cat))(?=.*?(mouse'; // this gets created dynamically var Z = ')).*$'; var A = X + Y + Z; // result is ^(?=.*?(dog))(?=.*?(cat))(?=.*?(mouse)).*$ and is a valid and tested expression var B = new RegExp(A, 'i'); I want to pass B to a search() function but it does not seem to be accepted as a valid expression anymore thanks for any help Hi, I haven't used variable variables before and I'm still trying to get my head around it. I think I'm going OK but I have run into a fairly obscure little problem that I thought I'd throw out there to see if anyone has any ideas... The plan: to make a distance calculator that measures a line made by clicking on a google map. Overall distance is shown at the side, but segment length is shown in tooltip-like labels called Elabels. Segments can get dragged and segment length is updated as dragging occurs. Being that the number of segments (and labels) depends on the number of user clicks, I thought it would be a good idea to use the variable variable to keep all the references unique. If there's a better way to do this, I'd love to hear about it. The problem: it all works fine, except that, if you consider that dragging a point on a line changes two line lengths (let's say A is the start, B is the drag point and C is the end), only one length is updating - the A to B section. What I want is for the Elabel at C to reflect the change in the B to C line length as well. Anyway. Here's the page I'm working on. The relevant code is below. I've tried duplicating it and adding +1 to the variables (and every permutation thereof) but no dice. All I need really is for exactly what's happening now to be happening in the next Elabel along in the array. Any suggestions much appreciated. Code: function leftClick(overlay, point) { count++; var mar1= count-2; var mar2= count-1; var mar3= count; var mar4= count+1; window["label" + mar2]=new ELabel(point, dist ,"labelstyle",new GSize(10,10)); labels2.push(window["label" + mar2]); map.addOverlay(window["label" + mar2]); // Drag listener GEvent.addListener(marker, "drag", function() { drawOverlay(); window["marker" + mar2]=markers[mar1]; window["marker" + mar3]=markers[mar2]; window["marker" + mar4]=markers[mar3]; line = [window["marker" + mar2].getPoint(),window["marker" + mar3].getPoint()]; dist2=window["marker" + mar2].getPoint().distanceFrom(window["marker" + mar3].getPoint()); dist2="Segment<br> length:<br>"+dist2.toFixed(0)+"m"; if(parseInt(dist2)>10000){dist2=(parseInt(dist2)/1000).toFixed(1)+"km";} window["label" + mar2].setPoint(marker.getPoint()); window["label" + mar2].setContents(dist2); } I am perplexed about this one. Not sure if php is the best solution or maybe javascript. ( or both.) I am writing a litle script that will go to my mysql table and take out 20 rows ( from about 10,000 rows ) based on the WHERE statement. Then I want to step through these 20 rows displaying just two filds in this fashion: First, I want to display one field in a "box" ( using divs and css ) then wait for a form input. Then while keeping the first displayed box and field display the second field in a similar box a fee lines below. Wait for a form input update some data. Then onto the next row. If I use javascript then I could keep all the processing on one page and not have to have server refreshes. But how do I get these those array elements from $row['field1'] and $row['field2'] into javascript vars ? Is this the best way to do this ? Or would php and having a couple of extra trips to the server for form processing be better ? Thanks for any input. . Hey, I'm new here, have always browsed but never created an account until now. I am an avid PHP programming but Javascript is not my thing. I am working on a module for a website of mine and I can't seem to figure thing one thing out. I have a module that competes a telephone verification and I would normally just use PHP but I am limited to the fact that I cannot alter or refresh the web page. I have a javascript module currently that people click a button and AJAX calls a serverside PHP script (which outputs a a random 4 digit code that it tells the user). That random 4 digit code is assigned to a global variable and then updating using the code ... verification_code=page_request.responseText (Output of my PHP document through AJAX) And then I have a textbox in which users input the 4 digit code (that the telephone script tells them). I have a variable called verification_input which is equal to the value of the textbox. I've been debugging this for awile now, If i write something like this Code: alert (verification_input + " code: " + verification_code); if(verification_code==verification_input){ alert('success?'); } everything works except for the success alert. The only weird thing I notice is the output of the first alert will be something like 2637 code : 2637 which the second set of numbers being on the next line. Any help would be appreciated. It's probably something simple Lately I've been doing some modding for a game called Minecraft which requires some programming in Java. I've been doing a lot of research but because I can't think of a simplified version of my questions it's hard to get any results from Google. So I'm hoping someone could answer these for me. If you can't, I would even appreciate being pointed in the right direction or led to some reading material that would answer these questions for me. 1) How can I add the value of a variable onto the name of another variable. For instance, I have this line of code Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); and this variable that will always be a number Code: private int numberA; I would like to add the value of numberA onto entityitem. So if numberA was 1 entityitem would become entityitem1. 2) What is the best variable type to store values such as Item.coal, which is an object within the game? Would a String type suffice? 3) Using the same code above: Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(Item.ingotIron)); How could I use a variable's value where Item.ingotIron is? I tried some different things but the compiler threw "ItemStack doesn't exist" or some error along those lines at me. For instance if variableA's value is Item.coal, how could I use that variables value where Item.ingotIron is. Code: EntityItem entityitem = new EntityItem(world, (float)i + f2, (float)j + f3, (float)k + f4, new ItemStack(variableA)); I appreciate your time and help on this issue and anything you can provide will be greatly appreciated. Hi, I'm trying to make a calculator app; with a few differences. I have a text field with a numberpad below it, I got the numbers to show up in the text field, but am unsure as to how when I hit the enter button - it would store them in a variable?...I am also wondering as to how it would store current value and then allow me to input another value(maybe on the next page) and either subtract or add to it(the first value that is stored). I am also wondering how to get a decimal point in place(need it for currency). Any help would be greatly appreciated! Here is my code: Code: <html> <head> <script type = "text/javascript"> function decPoint(str){ if (str.indexOf('.') == -1) str += "."; var decNum = str.substring(str.indexOf('.')+1, str.length); if (decNum.length > 2) { alert("Invalid more than 2 digits after decimal") } else { alert("Valid no") } } var ent = document.write(document.getElementById("curamt").value); </script> </head> <body border = "1"; color = "blue";> <div id = "cur"> <p>amount is: <script>document.getElementById("amount").innerHTML = ent);</script> </p> <b>Please type in price of item:</b> <form name = "calculator"> <table border = "1"; color = "blue";> <tr> <td colspan = "3" width="75%" align = "center"> <input type = "tel" id = "curamt" name = "tinput" maxlength="4" size="6"> </td> </tr> <table> <tr> <td><input type = "button" name = "one" value = " 1 " onclick = "calculator.tinput.value += '1'"></td> <td><input type = "button" name = "two" value = " 2 " onclick = "calculator.tinput.value += '2'"></td> <td><input type = "button" name = "three" value = " 3 " onclick = "calculator.tinput.value += '3'"></td> </tr> <tr> <td><input type = "button" name = "four" value = " 4 " onclick = "calculator.tinput.value += '4'"></td> <td><input type = "button" name = "five" value = " 5 " onclick = "calculator.tinput.value += '5'"></td> <td><input type = "button" name = "six" value = " 6 " onclick = "calculator.tinput.value += '6'"></td> </tr> <tr> <td><input type = "button" name = "seven" value = " 7 " onclick = "calculator.tinput.value += '7'"></td> <td><input type = "button" name = "eight" value = " 8 " onclick = "calculator.tinput.value += '8'"></td> <td><input type = "button" name = "nine" value = " 9 " onclick = "calculator.tinput.value += '9'"></td> </tr> <tr> <td><input type = "reset" name = "clear" value = " c " onclick = "calculator.tinput.value = ''"></td> <td><input type = "button" name = "zero" value = " 0 " onclick = "calculator.tinput.value += '0'"></td> <td><input type = "submit" id = "amount" name = "enter" value = " e " onsubmit = "ent(); return false;"></td> </tr> </table> </table> </form> </div> </body> </html> Hello everyone. I am new to this forum and hope to become a good addition. Thanks in advance to whom ever might help. I am having trouble concatenating variables in the alert box. The alert will basically be: Sum of the numbers from 1 through 5 is 15. But the 5 is the var = userEntry and the 15 is the var = sumOfNumbers. Of course, the numbers 5 and 15 will be replaced by the userEntry and the calculated sumOfNumbers. I have been able to make the first variable work, but cannot get the second one. For example: alert (" Sum of the numbers from 1 through " + userEntry);. I just cannot figure out how to concatenate a second variable into the message. I hope I am making sense. I am new to javascript and working off of Murach's Javascript and jQuery. Thanks again! I have this code: Code: var player = 100; var part1 = ('ctl00_cphRoblox_TabbedInfo_GamesTab_RunningGamesList_RunningGamesListView_ctrl0_ctl00_PlayersRepeater_ct'); var part2 = ('_PlayerImage1'); var final = part1 + player + part2; var name = document.getElementById(final) The variable (name) turns up null when I try to see what it is. But, it is, infact, an element on the page, and when I do it manually it works. Help? |