JavaScript - Creating And Writing Variable
I am working on a javascript for my blackberry. I am trying to capture the latitude and longitude of that phone. I am able to get the coordinates in an alert box but am having a little trouble writing it to a form input field. Can anyone help me with this?
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" xml:lang="en" lang="en"> <head> <title>GPS Testing</title> </head> <body> <script type="text/javascript"> if(blackberry.location.GPSSupported){ document.write("Your device supports GPS locating"); blackberry.location.onLocationUpdate(window.alert("Latitude: " + blackberry.location.latitude + " Longitude: " + blackberry.location.longitude)); var lat = blackberry.location.latitude(); var lng = blackberry.location.longitude(); blackberry.location.refreshLocation(); document.write(lat); } </script> </body> </html> I am only able to test with Blackberry. I was trying to create a couple of variables with the "var lat =" and var lng =". With this script I get the alert window and when I click ok it writes "Your device supports ..." Thanks for any help! Similar TutorialsI would like to apologize in advance if my question sounds too simple. I am a novice to Javascript and have not had any real formal training here. I am creating a webpage which utilizes a separate .xml file to populate values in my webpage. This is my webpage (links.html): and here is my xml file (links_data.xml): This is my output: I have a link at the bottom of the page that points to the device being displayed. In this case, the link should be: http://10.90.139.201 If my xml file changes, it should point to the new IP address. My question is, how do I get the link to work? Currently, my current link (<a href="http://"IP_address"">Link</a>) does not populate any information. Appreciate any guidance here... thanks. Is this possible? Code: String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, ""); } var myStr = " Hi what's up? "; myStr.trim(); alert("{" + myStr + "}"); //will result in the original string, not the trimmed version It's possible with numbers: Code: var myNum = 10; myNum++; alert(myNum); //11 Code: var x = "blahblah".indexOf("blahblah"); if (x !== -1){ // do something with x alert("Present"); } else { alert("Not present"); } Is there some syntax/code structure that allows something like this: Code: if ( (var x = "blahblah".indexOf("blahblah")) !== -1){ // do something with x alert("Present"); } else { alert("Not present"); } I'm using a form data reference, something like P-1234 for example to create a text file and a link to the file. This is during the construction of a new table or table row with javascript. I have an array of one or more references submitted via form using $_POST. On my action page I am creating a txt file P-1234. If I am creating a table ot table row using createElement(), one of the cells will have a link to the file. If the file is created as follows: PHP Code: $File = $_POST['ref'][$i] . "txt"; After creating the cell Code: var Cell = document.createElement('td'); I assign the file to a variable var File = "<?= $File ?> "; I assume the link is inserted using innerHTML? If so, do I just append the filename to the end of the file path like this? Cell.innerHTML = "http://localhost/Project/+File"; If this is not the right way can someone point me in the right direction? Very new to javascript, so I apologize in advance. I honestly tried to figure this out on my own, and I'm just not able. I'm trying to create a family tree online that has several other related family charts. I want each person's name and birth year to be stored in javascript variables, then I want to be able to just go through the tree, and put the persons name once, and have it put the appropriate name and birthyear in the little boxes that the css is creating. In the js file... I would do this for each family member. Code: var johnname = "John Smith"; var johnbirthyear = "Jan 1 1930"; var janename = "Jane Doe"; var janebirthyear = "Jan 1 1940"; var mikename = "mike wilson"; var mikebirthyear = "Jan 1 1950"; var saraname = "sara johnston"; var sarabirthyear = "Jan 1 1960"; In the HTML file... Code: <div id = "boybox"> <script type="text/javascript"> id = "john"; <!-- this is the only thing I want to have to change --> name = id+"name"; document.write(name); </script> <div id = "year"> <script type="text/javascript"> birthyear = id+"year"; document.write(birthyear); </script> </div> </div> So I thought I had it all figured out. I thought that the above would take the id of John that I added, go to the line that sets the name, add john to the word name, and then document write the variable of johnname from the js file. I know you're laughing at me because of course it instead made the value of name to johnname, then wrote the word johnname in the box. Can anyone point me in the right direction please? ultimately I want to go through and be able to just type the persons name in the html for that box once, and have it update with their appropriate info. Thanks, and sorry for such a rookie question. hi all, I am fairly new to Javascript, and am trying to "print" a var inside a script. I have this piece of script, which loads images from a gallery: Code: $(document).ready(function(){ $('title').text('G3 Ajax Gallery'); loadGallery('/gallery3/rss/feed/gallery/album/114'); }); The number 114 defines what part of the gallery to be loaded. I would like to define this with a var, but dont know how to "print" it into the url. So: loadGallery('/gallery3/rss/feed/gallery/album/114'); woulkd become something like: loadGallery('/gallery3/rss/feed/gallery/album/my_var'); Any help would be much apreciated. Thanks, Sion. Reply With Quote 01-21-2015, 12:41 PM #2 xelawho View Profile View Forum Posts Senior Coder Join Date Nov 2010 Posts 3,043 Thanks 56 Thanked 568 Times in 565 Posts PHP Code: var myvar=114; // or however you are defining it loadGallery('/gallery3/rss/feed/gallery/album/' + myvar); I need to reset the active content registry entries to the defaults when a page unloads: Code: <script> // Window Onunload, last to execute, manage registry function windowonunload(){ var WshShell = WScript.CreateObject("WScript.Shell"); WshShell.RegWrite ("HKCU\\Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_LOCALMACHINE_LOCKDOWN\\iexplore.exe\\", 1, "REG_DWORD"); WshShell.RegWrite ("HKCU\\Software\\Microsoft\\Internet Explorer\\Main\\FeatureControl\\FEATURE_LOCALMACHINE_LOCKDOWN\\Settings\\LOCALMACHINE_CD_UNLOCK\\", 0, "REG_DWORD"); } WScript.DisconnectObject(sh); WScript.Quit(); //--> </script> ...but it doesn't seem to work. What am I doing incorrectly? Thanks. Hello, I am a novice and am hoping I can get some help here. I am self taught at basic HTML and am now trying to add some "v v vroom!" to a site that I am developing. The problem I am faced with is I have a Javascript that I am using as an experiment to see how Javascript works (in the hope that I can use other more exiting Javascripts on my sight I am buliding). I have copied it onto NotePad from a self teaching book which when opened up in a browser does not work. The script in question is; <html> <head> <title>My First Javascript page</title> <script type="text/javascript"></script> <style type="text/css"> body {document.bgcolor="pink"} </style> <body> This is my first Javascript page !! So **** off! <form> <input type="button" onclick="document.bgcolor='blue'" name="change" value="blue"> <input type="button" onclick="document.bgcolor='red'" name="change" value="red"> <input type="button" onclick="document.bgcolor='yellow'" name="change" value="yellow"> <input type="button" onclick="document.bgcolor='white'" name="change" value="white"> <input type="button" onclick="document.bgcolor='fuchsia'" name="change" value="fuchsia"> </form> </body> </html> Can anyone shed any light on what I might be doing wrong, or what I can do to make it work? Thank you all in advance. David Hood. Dear friends , I tried to write in html page from text file using " <html> <head> <script type="text/javascript" language="javascript"> function Read() { var Scr = new ActiveXObject("Scripting.FileSystemObject"); var CTF = Scr .OpenTextFile("C:\\123.txt", 1, true); data = CTF .ReadAll(); document.write(data); alert(data); CTF .Close(); } </script> </head> <body onLoad="Read()"> </body> </html> " But the contains of text file getting changed , like if there is "My name is Karimkhan I love India " Then it will write like "My name is Karimkhan i love India" It ignores multiple spaces and new line character , so what should I do to prevent this...IS THERE ANYTHING LIKE <PRE> TAG IN HTML "? I want to write an xml stream to the browser using javascript. What I am currently getting is the visual data and the page source is the xml stream. What I would like to get is a visual representation of the xml as well as the underlying page source. Further information. The visual presentation wanted is: <?xml version="1.0" encoding="UTF-8" ?> - <FSResult> <FoodStampAllotment>526</FoodStampAllotment> <GrossEligible>TRUE</GrossEligible> <NetEligible>TRUE</NetEligible> <AssetEligible>TRUE</AssetEligible> </FSResult> The page source for that is: <?xml version="1.0" encoding="UTF-8" ?><FSResult><FoodStampAllotment>526</FoodStampAllotment><GrossEligible>TRUE</GrossEligible><NetEligible>TRUE</NetEligible><AssetEligible>TRUE</AssetEligible></FSResult> The page url includes: FSCalcServlet.do The other visual presentation that we want to look like the above: 150TRUETRUETRUE The other page source is: <?xml version="1.0" encoding="UTF-8" ?><FSResult><FoodStampAllotment>150</FoodStampAllotment><GrossEligible>TRUE</GrossEligible><NetEligible>TRUE</NetEligible><AssetEligible>TRUE</AssetEligible></FSResult> The other page url includes: FSCalc.html This version is written from Flex via javascript and the original is a java servlet. Hi Guys I'm struggling to find out why the iframe is not being populated with a selectbox containing the album names from an XML file. majority of the code is working fine and the "alert(s)" function works perfectly and displays exactly the html I would like it to but the bits in bold are not working and are not writing the html to the iframe. (please note, this code is only supposed to work in Javascript) . Thanks Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"> <html> <head> <script type="text/javascript"> function loadXML(docName){ if (window.XMLHttpRequest){ xhttp=new XMLHttpRequest(); } else{ xhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xhttp.open("GET",docName,false); xhttp.send(); return xhttp.responseXML; } tunesData=loadXML("music.xml"); albumsArray=tunesData.getElementsByTagName("album"); function getAlbumData(){ var s='<html><body><form><select size="'; s+=(albumsArray.length+1); s+='"><option>...Please Select An Album...</option>' for(i=0;i<albumsArray.length;i++){ s+='<option>'; s+=albumsArray[i].childNodes[1].childNodes[0].nodeValue; s+='</option>' } s+='</select></form></body></html>'; alert(s); with(document.getElementById('albumscol').contentDocument){ open(); write(s); close(); } } getAlbumData(); </script> </head> <body> <iframe id="albumscol"></iframe> </body> </html> So I need to know how I can write this more efficiently. I been told that a loop should work, but I can't figure a good way to do it. Im very new to javascript, so I was hoping someone may be able to help. Code: document.getElementById('tabButton1').onclick=function(){ document.getElementById('tabDiv1').className = 'tabActive' document.getElementById('tabDiv2').className = 'tabInactive' document.getElementById('tabDiv3').className = 'tabInactive' document.getElementById('tabDiv4').className = 'tabInactive' document.getElementById('tabButton'+1).className = 'tabActive' document.getElementById('tabButton2').className = 'tabInactive' document.getElementById('tabButton3').className = 'tabInactive' document.getElementById('tabButton4').className = 'tabInactive' }; document.getElementById('tabButton2').onclick=function(){ document.getElementById('tabDiv1').className = 'tabInactive' document.getElementById('tabDiv2').className = 'tabActive' document.getElementById('tabDiv3').className = 'tabInactive' document.getElementById('tabDiv4').className = 'tabInactive' document.getElementById('tabButton1').className = 'tabInactive' document.getElementById('tabButton2').className = 'tabActive' document.getElementById('tabButton3').className = 'tabInactive' document.getElementById('tabButton4').className = 'tabInactive' }; document.getElementById('tabButton3').onclick=function(){ document.getElementById('tabDiv1').className = 'tabInactive' document.getElementById('tabDiv2').className = 'tabInactive' document.getElementById('tabDiv3').className = 'tabActive' document.getElementById('tabDiv4').className = 'tabInactive' document.getElementById('tabButton1').className = 'tabInactive' document.getElementById('tabButton2').className = 'tabInactive' document.getElementById('tabButton3').className = 'tabActive' document.getElementById('tabButton4').className = 'tabInactive' }; document.getElementById('tabButton4').onclick=function(){ document.getElementById('tabDiv1').className = 'tabInactive' document.getElementById('tabDiv2').className = 'tabInactive' document.getElementById('tabDiv3').className = 'tabInactive' document.getElementById('tabDiv4').className = 'tabActive' document.getElementById('tabButton1').className = 'tabInactive' document.getElementById('tabButton2').className = 'tabInactive' document.getElementById('tabButton3').className = 'tabInactive' document.getElementById('tabButton4').className = 'tabActive' }; All help is appreciated. Thanks Yes, I have read the sticky about homework.. and before you call me a lazy sack, I will have to blame it all on my teacher... He knows almost nothing about the Java, and yet, he is teaching a computer programming class... This assignment is due soon, and I have no idea how you even start this..Really appreciate it if some1 can do this for me.. Assignment: Create a new 'Array' Project and create a java file that does the following. -Print your arrays going across the screen(horizontally) -Creating the arrays should be done in main -All other tasks should be in separate methods -Your arrays should be passed as a parameters -All methods should have a void return type 1.a)Create an array of 100 integers called nums. (All 1000 grades will automatically be initialized to 0) b) Fill the array with 1000 random numbers between 10 and 99. c) Print the grades forwards d) Print the grades backwards. e) Find the average of the grades and print the average 2 a) Create an array of 6 Strings called names (all 6 names will automatically be initialized to null.) b) Fill your array with 6 names (you will have to do this individually). c) Print all names that start with a vowel. Thank to so much if someone really help me with this! Hi folks. There have been several requests on this forum for subtotal/tax/total forms, but I know so little about Java scripts that I haven't been able to adapt your provided solutions to my needs. I know it seems like a cop-out to just ask someone else to do it for me, but I need to get this form functioning as soon as possible, since I'll be running business through this site (which, until now, I've designed on my own). I would like to learn JS eventually, or at least have a working knowledge of it, but I'm short on time right now. I know that a Java script should be able to do what I need it to, so if there's anyone out there who can help, I would be incredibly grateful. I hope it's not too much trouble. Here's the web page. I've kept my html nice and clean, so hopefully it's very easy to read: link What I need is to multiply the price of either size options by the quantity, add the sales tax and shipping, and the total will update automatically. The paper choice will not affect the price. Ideally, I would like the "submit request" button to send an email with all supplied information to my email address, and also send a copy to the supplied customer address. (I think that's considered a get/put script?) Again, if there's anyone who can help with this, I would be very grateful. Thanks, Jon Ok, so i need help writing a java script that will look at a bunch of numbers and output the highest one so what i need is for it to do something like this. (A is my input value) (B is my output value) the (A) value will be constantly changing and with the script has to do is look at all of those values and output them to (b) if anyone knows how to do this i would be so grateful if they could write the code for me because i'm new to coding and i really need this to work. thanks. I have a piece of code which I suppose to click on to activate: Code: <a href ="javascript:(function() { newwindow = window.open(); newwindow.document.write('<html><head><title>Your new title here</title></head>'); newwindow.document.write('<body><embed src = 'http://www.flashppt.com/images/tangramone.swf' height='100%' width='100%'></embed></body></html>'); } )();"> Run flash popup </a> I have spent a very long time looking at it but I still can't figure it out. The problem is with line with <embed> tag. My purpose is to open a swf flash in a new popup window such that it must have a Pretty title name (instead of its addresss). Since opening that SWF directly does not leave me the option of change the popup title , so I use the above method... I appreciate much if you can help ! hey guys, im trying to write whether player 1 or 2 won into the text area. see code below. thanks [CODE] <html> <head> <script type="text/javascript"> var a=1 </script> <style type="text/css"> body { background-image: url(http://fc08.deviantart.com/fs40/i/2009/018/f/8/FLOWJOB_3d_graffiti_by_UrbanCalligraphism.jpg); } h1 { font-family:"sans-serif",tahoma; background-repeat: no-repeat; color:#00ffe7; } p { color:#000000; font-family:"sans-serif",tahoma; font-weight:900; } </style> </head> <body> <center><h1>Ghetto Dice Project</h1></center> </br> </br> </br> </br> </br> </br> <center> <textarea rows="9" cols="18" id="textarea"> </textarea> </center> </br> </br> </br> </br> </br> <center> <table> <tr> <input type="text" id="playerone" size="4" value=""> <input type="text" id="playertwo" size="4" value=""> </tr> </br> <tr> <button onclick=" a=(Math.floor(Math.random()*13)); document.getElementById('playerone').value=a; "> PLAYA 1 </button> <button onclick=" b=(Math.floor(Math.random()*13)); document.getElementById('playertwo').value=b; "> PLAYA 2 </button> </tr> </table> </script> </br> </br> <p> Hand coded with care by Tanner Beck </p> </center> </body> </html> [CODE] All, I have the following code: Code: <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <title></title> <style type="text/css">body{font:62.5% Verdana,Arial,sans-serif}</style> <link href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/themes/base/jquery-ui.css" rel="stylesheet" type="text/css" /> <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script> <script> $( "#drg" ).draggable({ revert: true }); var drpOptions = { drop: function(event, ui) { $(this).append( ui.draggable.text() + "<br>" ); } }; $( "#drplist" ).children().droppable( drpOptions ); $( "button" ).button().click(function() { $( "<li>Dynamic droppable<hr></li>" ).droppable( drpOptions ).appendTo( "#drplist" ); }); </script> <style type="text/css"> #drg { background: silver; width: 100px; padding: 0.5em; text-align: center; } ul, ul li { list-style: none; margin:0 ; padding: 0; } #drplist li { width: 200px; height: 100px; margin: 1em; padding: 0.5em; background: lightgreen; } </style> </head> <body> <div id="drg"> Drag me </div> <hr> <button>Click to add a droppable</button> <ul id="drplist"> <li>Drop here<hr></li> </ul> </body> </html> Basically what I would like to happen is that when I click on the button it generates the table like it did and then I want like two checkboxes next to it with some text and a break line in between the two. How can I update my jQuery to give me this result? Thanks in advance! Javascript (inside a function that everything works except this bit): Code: var uploadedfile = "upload" + ups; document.getElementById(uploadedfile).value= file; The input element its not changing: Code: <input type="text" name="upload[]" id="upload1"/> There are four additional input elements, one for each possible fileupload, they will be set to hidden but in order to see if it was submitting the name I set it to text. Here is the live page so you can see it: http://www.sandcrawler.net/forum/sandnet.php?page=test2 What this is for is an upload script, I have all the upload bit working, but now I need to find a way to pass the filename to my php script, that will then sort the files out into two types, screenshot and compressed. Then insert them into a mysql database. I've gotten this same type of thing to work on a w3school TryIt demo, with the variables set the same way. So I can't figure out where there is an error. Opera isn't giving me one. I can post more code if needed. Thanks Hello: First post here on CS ... I am wondering why my code will not write a new line or line break. This is fine: Code: <script> document.write("Hello and welcome to javascript!"); </script> But when I try to put a message on two lines, it does not work. The book I'm reading and several websites have stated the below codes will work, but neither do: Code: <script> document.write("Hello and welcome to javascript! \n"); document.write("It is a tricky language to learn!") </script> Code: <script> document.writeln("Hello and welcome to javascript!"); document.writeln("It is a tricky language to learn!") </script> Am I missing something? |