JavaScript - Retrieve Integer From Database
Similar TutorialsOVERVIEW of main webpage: when a user logs in, they will be directed to the main page of the website; and will see images displayed according to a value that was stored in the database. the main page preloads an image array: Code: <script type="text/javascript"> var img_FILE = [ 'images/house.png', 'images/car.png', 'images/boat.png' ]; </script> easy enough the database holds a column of integers that are used to access the proper image in the array. i can successfully pull the integer value i need from the db. what i want to do is when the main page loads, i want the value that was pulled from the database to be used to display the correct image. example: lets say i pulled the value 2 from the db. then i want to display img_FILE[2] on the main page when the page "loads". Code: <body> <div id="quadrantOne"> <img id="firstImg" src="images/blankImg.png" width="190" height="235" /> <script type="text/javascript"> $.post('imageScript.php', 'data=0', function(data,status){ if (status == 'success') { imgValue = data } else { imgValue = 'error' } document.getElementById('firstImg').src=img_FILE[imgValue]; }); </script> </div> </body> i debugged imgValue and it is correctly assigned the value coming from the db. but..........the image won't appear on the main page. any ideas how to get this to work? thanks, Paul Williams Frustrated by the fact that you don't have the integer division operator in JavaScript? Here's a surprisingly little known method: parseInt(19/4) = 4 Now when a VBguru or vbscripter says "ha ha, I can integer divide and you can't!" You now know better. Can someone point me in the right direction for using Javascript to increase a number over time without refreshing the page? I also need it to continually go up, and not start at 0 on every refresh. Is this possible? Blockis Hi all, this is my first post to this great useful forum. I have a javascript 2d array [x,y] that contains integer values like this: [0,0], [0,1], [0,2], [0,3], [1,0], [1,1], [1,2], [2,0], [2,1], [2,2], [0,-1], [0,-2], [0,-3], [1,-1], [1,-2], [2,-3] my question is how to get the max,min y value for each x. for the sample above it should give me another array with the following results [0,3],[0,-3],[1,2],[1,-2],[2,2],[2,-3] your help is highly appreciated Regards Omran In some cases toPrecision(X) will result in an integer value, which is the expected result. However, it is typical in some fields to always follow the integer value with a decimal and zero (i.e 522 --> 522.0). Technically, this would be incorrect since it would imply an extra digit of precision that does not exist. However, this is often disregarded, provided there are sufficient number of digits (i.e. precision of 5+). That said, is there any way to force an integer result to have a trailing ".0"? Does JavaScript have an easy of converting an ordinary integer like 135 into a time format like 02:15? I'm working on a timer that handles the backend with just a plain integer that counts down every second but it needs to output looking like a clock.
Hi all, I am having a problem converting a physical string to a integer. I have a dropdown list of a few items but are numbers though in chracters. I ned to output the value and the text of the selected item. As I cannot use a if-else statement, any help would be great. Code: <select id="std_num" onchange="displayValue()"> <option value="Two">Two</option> <option value="Zero">Zero</option> <option value="Five">Five</option> <option value="Three">Three</option> <option value="Two">Two</option> <option value="Zero">Zero</option> </select> Code: function displayValue() { alert(document.getElementById('std_num').value); var c = (document.getElementById('std_num').value); } Hi, I was hoping you could help me, I was wanting to write text to the screen but without re-writing the whole screen (e.g. document.write();. I wish to take text and put it in a function, modify it, then display it. So far I have: Code: <script type = "text/javascript"> function calculate(text){ var x = "10.0"; var gpa = text.replace(/0.0/g,x); document.getElementById("text").innerText=gpa; } </script> <p id = text >Your Grade Point Average (GPA) is: 0.0</p> <button type="button" onclick="calculate(text)">Calculate</button> Your help would be really appreciated Another homework assignment that I can't quite seem to get to work... I've been asked to do the following using javascript: -Create a function named randInt() with one parameter of "size". Declare a variable named "rNum" equal to a random integer between 1 and the value of the size variable. Return the value of the "rNum" varialbe from the function. -Create a function named getQuote() with one parameter anemd "qNum". The function should create an array named mtQuotes with five quotes; there should be no quote for the array index "0". Return the value of the mtQuotes array for the qNum index. - In the div element of "quotes" insert a script with the following commands: Declare a variable named "randValue" which is euqal to a random integer between 1 and 5 (use the randInt() function). Declare a variable named "quoteText" containing the quote whose array index value is equal to randValue. Write the value of quoteText to the web page. Here is what I have...it returns undefined. thanks. Code: <html> <head> <script type="text/javascript"> function randInt(size) { var rNum=Math.ceil(Math.random()*5); return(rNum); } </script> <script type="text/javascript"> function getQuote(qNum); var mtQuotes = new Array(); mtQuotes[0] = ""; mtQuotes[1] = "I smoke in moderation, only one cigar at a time."; mtQuotes[2] = "Be careful of reading health books, you might die of a misprint."; mtQuotes[3] = "Man is the only animal that blushes or needs to."; mtQuotes[4] = "Clothes make the man. Naked people have little or no influence on society."; mtQuotes[5] = "One of the most striking differences between a cat and a lie is that a cat has only nine lives."; return mtQuotes[qNum]; </script> </head> <body> <div id="quotes"> <script type="text/javascript"> var randValue=randInt(5); var quoteText=getQuote(randValue); document.write(quoteText); </script> </div> Well I have an array and a button to select a random integer from the array, how do I make it so that it selects every integer once til all are selected, then it starts over again? For example, an array has these: A B 1 2 Q F So you press the button a number of times, and you get: Q B 1 F A 2 Instead of: 1 Q A 1 B A I have some asp:radiobutton lists that need to update a label with the sum of their values each time a user selects a new value. I am brand new to javascripting and would like some insight on how to get this done. I have inserted my code below. Code: <asp:Label runat="server" Text="Greeting:" /> <asp:Label runat="server" ForeColor="Red" ID="lbl_GreetingScore" Text="0" /> <asp:RadioButtonList ID="rdb1_1" runat="server" RepeatDirection="Horizontal"> <asp:ListItem Selected="True" Text="N/A" Value="4" /> <asp:ListItem Text="Yes" Value="4" /> <asp:ListItem Text="No" Value="0" /> </asp:RadioButtonList> Hi guys can help me are very little versed in javascript ... I explain my problem! I have a table where they passed the results of a query ... The table field is called Article and consists of about 500 characters, but the substring in the table with a step the first 40 characters, and now the question arises ... I would click on the text of the article and see the page the entire article ... Code: query="SELECT * FROM Articolo ORDER BY titolo DESC"; ResultSet r = stmt.executeQuery(query); %> <table border="1"> <tr><td> titolo </td> <td> articolo </td> <td> data inser </td></tr> <% while(r.next()) { Tot = r.getString("titolo"); Art = r.getString("articolo"); dat = r.getString("data_inserimento"); String meta = ""; String metadata = ""; meta = Art.substring(0,40); metadata = dat.substring(0, 10); StringBuffer sb = new StringBuffer(meta); sb.replace(37,40, "..."); String s2 = sb.toString(); %> <tr> <td> <%= Tot %> </td> <td> <a href="#" onClick="this.innerText = '<%= Art %>';"><%= s2 %></a> </td> <td> <%= metadata %> </td> </tr> <% } %> </table> I have been able to use javascript to place the last modified date in the bottom left corner of my document however I do not need the time with it. How do I use the substring() method on the lastModified property? Here is what it looks like. Code: <script type="text/javascript"> <!--Hide from old browsers var today = new Date() var dayofweek = today.toLocaleString() dayLocate = dayofweek.indexOf(",") weekDay = dayofweek.substring(0, dayLocate) newDay = dayofweek.substring() dateLocate= newDay.indexOf(",") monthDate = newDay.substring(0, dateLocate+1) yearLocate = dayofweek.indexOf("2011") year = dayofweek.substr(yearLocate, 4) document.write("<p style='font-family:bold, Arial, Helvetica, sans-serif; font-size:xx-small; color:#000000'>") document.write("Copyright the Huysken Performing Arts Center. ") document.write("<br />This document was last modified "+document.lastModified+"</p>") The text book says to use a substring() method on the lastModified property, but I am uncertain on how to do that. Any help is greatly appreciated, Thank you. hi all, as i am very stupid in javascript.... supposing i had a select box on a page with an id of "select1" and name of "select1" as well... using javascript how would i access the select box's selected value and how would i print it out on the screen.... thanks in advance.... cheers sanjeev Hi guys, i need to retrieve the url created in the following script and embed it in the player below. Here is what i have. You can see how it works (and doesn't) here http://www.brittv.co.uk/template.php...ws.stream_360p Code: <html> <head> <title>...</title> <?php $URL_GETKEY="http://www.uktvlive.com/tvc/key.php"; function doCurl($url) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); return $output; } $a=doCurl($URL_GETKEY); $split=explode("<split>",$a); ?> <script type="text/javascript"> // parse the querystring and create a dictionary of terms for later use: var qs = [ ]; // where the dictionary goes if ( location.search.length > 1 ) { var pairs = location.search.substring(1).split("&"); for ( var p = 0; p < pairs.length; ++p ) { var pair = pairs[p].split("="); qs[pair[0]] = unescape( pair[1] ); } } // do the replacements *after* page is loaded, for simplicity: function doReplacements( ) { var link = document.getElementById("link1"); link.href = "rtsp://81.104.67.230/"+ qs["host"] + "/" + qs["stream"] + "?userID=" + "<?php echo $split[5];?>" + "&accessKey=" + "<?php echo $split[6];?>" + "&sdp=alt&device=mobile"; link.innerHTML = qs["page"]; // and of course you could do any other replacements, too. } window.onload = doReplacements; </script> </head> The following part produces the url Code: <body> <br/><br/> <a id="link1">Generic Link</a> <br/><br/> Lastly we have the player embed code, this is where im stuck im afraid Code: <script type="text/javascript"> var url = qs["link1"]; // or whatever name it was passed by document.write('<OBJECT CLASSID="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B" ' + ' WIDTH="300" HEIGHT="160" ' + ' CODEBASE="http://www.apple.com/qtactivex/qtplugin.cab">\n' + '<PARAM name="SRC" VALUE = "http://www.tvpc.com/images/image1.gif" >\n' + '<PARAM name="QTSRC" VALUE = "' + url +'" >\n' + '<PARAM name="HREF" VALUE = "' + url + '" >\n' + '<PARAM name="AUTOPLAY" VALUE = "true" >\n' + '<PARAM name="CONTROLLER" VALUE = "true" >\n' + '<PARAM name="TYPE" VALUE = "video/quicktime" >\n' + '<PARAM name="TARGET" VALUE = "myself" >\n' + '<EMBED \n' + ' SRC = "#" \n' + ' QTSRC = "' + url + '" \n' + ' HREF = "' + url + '" \n' + ' TARGET = "myself"\n' + ' CONTROLLER = "true"\n' + ' WIDTH = "300" \n' + ' HEIGHT = "160" \n' + ' LOOP = "false" \n' + ' AUTOPLAY = "true" \n' + ' PLUGIN = "quicktimeplugin" \n' + ' TYPE = "video/quicktime" \n' + ' CACHE = "false" \n' + ' PLUGINSPAGE= "http://www.apple.com/quicktime/download/" >\n' + '</EMBED>\n' + '</OBJECT>\n' ); </script> </body> </head> Thanks in advance guys Hi, I know there are several ways to do this- but which way is best practice? I can access a variable from one function by making it a global variable, but I read that this isn't the most ideal way, and is a last resort. So for example if I have this: Code: function num1(){ var firstNum = 35; return firstNum; } function num2(){ var secNum = 52; return secNum; } function addNums(x,y){ var f = num1(x); var s = num2(y); var total = f + s; alert(total); } Then I call this function with a button. Now, I know this works, but it doesn't seem like a very good way to do what I'm after. Or is it? Any help/ tips would be great. edit: The idea is that the functions won't just return a single value and that's it. They will return a users choice in a given scenario, so they might return the user's age from the first function, then their location in the next etc etc, then I want to use this information in a separate function. Hello I am trying to iterate out the values of an xml file. I have got the file to load though I have not yet been able to extract the values. Considering that theXml is an xml file and 'coords' are tags containing a coordinate how would I extract the value. Here is the code I am using Code: var coordTags = theXml.getElementsByTagName( 'coords' ); var len =coordTags.length;///this works var coord =coordTags[0].value;///this doesn't work var coord =coordTags[0].text;///this doesn't work var coord =coordTags[0].innerText;///this doesn't work parent.document.receiver.theres.value = coord; I am sure for some of you this is a really simple question so please someone help!! Hi there I am trying to retrieve xml data using the prototype Ajax.Request. I think I am getting the xml though I am unsure as to how to retrieve the text from the nodes here is the function I am using to try and populate a text field Code: function makeMarkerXml() { new Ajax.Request('coords.xml', { method:'post', onSuccess: function(transport){ ////this will not work///////// var coord = transport.responseXML.childNodes(0).childNodes(0).firstChild.text; /////////////////////////////// }, onFailu function(){ alert('Call failed') } }); } can anyone help? Hi, I have several input text boxes in a <FIELDSET> tag. I would like to load id attributes of the <FIELDSET> tag into an array and then process the array. My code example is below my signature. Thank You in Advance for Your Help, Lou 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" xml:lang="en" lang="en"> <HEAD> <SCRIPT LANGUAGE="JavaScript"> function DisplayDetails(obj_id) { alert("DisplayDetails(" + obj_id + ")"); var form_object = new Array(document.getElementById(obj_id)); var form_elements = form_object.elements; alert(form_object[0]); } </SCRIPT> </HEAD> <BODY> <font size="4" face="Arial" color='Black'> Hi Barney <form> <fieldset id="Person1"> <legend>Person 1:</legend> Name: <input type="text" id="name1" size="30" /><br /> Email: <input type="text" id="email1" size="30" /><br /> Date of birth: <input type="text" id="dob1" size="10" /> </fieldset> </form> </font> <button type="button" onclick="DisplayDetails('name1')">Click Me!</button> </html> |