JavaScript - Back To School And Lost
Hello there,
I'm a 30yr old returning to school and I signed up for a CMIS102 class, thinking it be more explanatory as the syllabus let on. But I was wrong. While I do understand some of what the professor has been teaching us, like modular programming and IfElse statements, I can't wrap my head around things like While Loops. My professor has saddled us with a couple assignments, requiring us to write in pseudocode and I was wondering if anyone could explain what he wants from this assignment or even help me with it, that maybe I can finally have a grasp of it, and will know what I'm doing on the final. ~Tia P.S. I've posted the assignment question below: I need to write a pseudo-codepseudocode for the following question but don't know how: Write a program to read a list of exam scores (in the range 0 to 100) and to output the total number of grades and the number of grades in each letter=grade category. The end input is indicated by a negative score as a sentinel value. (The negative value is used only to end the loop, so do not use it in the calculations. Example: 88 93 55 77 100 -1 (The output would be) Total number of grades = 5 Number of A's =2 Number of B's = 1 Number of C's =1 Number of D's = 0 Number of F's =1 Must prompt user to run again Similar TutorialsI have to create a function that uses infoMenu(), and I am having a hard time with this. I have created a loadInfo() function, and I am supposed to follow the same steps, but for some reason I am not getting it. Below is an example of what I have done already. Code: function loadInfo(myForm) { var menuSelect=myForm.Menu.selectedIndex var menuUrl=myForm.Menu.options[menuSelect].value+".html" window.location=menuUrl } This is what I placed in my select tag to in order to go to the pages once they were selected. Code: <select name="Menu" onchange="loadInfo(this.form)"> What i am trying to do is create the infoMenu() function that uses the selectedIndex value of the moreInfo <select> list in the menuInfo<form>. Any help would be greatly appreciated This post is going to seem long because of the coding in it, but the solutions I need are simple. BASICALLY I need to know: 1) where to use the if's and else's 2)how to call the boolean method isEmpty() from the CanOfCoke class 3)how to apply methods from the other classes to the machine, bin, and can variables 4) how to check to see if an ArrayList has any content (ie if the student has any coins or not) This is complicated for me to complain because I'm a complete n00b and this is my first Java class, but I hope someone can help me because my teacher isn't all that great at explaining things. and I'm stuck on the LAST method of the LAST class of our FINAL project lol. The project has 5 classes: Coin DrinksMachine CanOfCoke GarbageDisposalUnit Student I am working on the Student class and here is the code I have so far: Code: import java.util.ArrayList; /** * Write a description of class Student here. * * @author xxx * @version Project part 5 */ public class Student { private String name; private ArrayList purse; private boolean sobbing; private DrinksMachine machine; private GarbageDisposalUnit bin; private CanOfCoke can; /** * Constructor for objects of class Student * * @ param pName The name of the studen * @ param nCoins The number of coins the student has */ public Student(String pName, int nCoins) { name = pName; purse = new ArrayList<Coin>(nCoins); sobbing = false; machine = null; bin = null; can = null; } /** * This method will set the students machine variable * * @param name of the machine */ public void setMachine(DrinksMachine aMachine) { machine = aMachine; } /** * This method will set the students garbage disposal unit * * @param name of the garbage disposal unit */ public void setBin(GarbageDisposalUnit aBin) { bin = aBin; } /** * This method will print out information about the student * */ public void displaySelf() { if (can == null) { System.out.println(name + " does not have a can of Coke."); } else { System.out.println(name + " has a can of Coke."); } if (sobbing == true) { System.out.println(name + " is sobbing."); } else { System.out.println(name + " is not sobbing."); } System.out.println(name + " has" + purse.size() + " coins in their purse."); } /** * This method will perform the actions of: * * If they have a can of coke: * The student takes a single sip from a can of Coke and puts it in the trash bin when empty. * * If they don't have a can of coke: * The student inserts a coin and obtain the can of coke and take a sip from it. * * If they can't get a can of coke: * The student sobs. * */ public void doAction() { if (can != null) { can.giveSip(); } else if (can.isEmpty()) { bin.addCan(bi); can = null; } else { if (purse != null && can != isEmpty()) { machine.insertCoin(); machine.deliverCan(); can.open(); can.giveSip(); } else { sobbing = true; } } } } This is the part I am having troubles with: [CODE public void doAction() { if (can != null) { can.giveSip(); } else if (can.isEmpty()) { bin.addCan(bi); can = null; } else { if (purse != null && can != isEmpty()) { machine.insertCoin(); machine.deliverCan(); can.open(); can.giveSip(); } else { sobbing = true; } } } } [/CODE] Here are his horrible instructions: a method with signature public void doAction() which performs the following actions: i. if the Student has a can of Coke then they take a single sip from it. If it becomes empty they put it in the bin, and cease to hold it (i.e. can is set to null). The doAction() method then exits. ii. if the Student does not have a can of coke then they insert a Coin(if they have one) into the coke machine (if it isn't empty), take the can of Coke they have paid for, and take a sip from it (after opening the can). If for any reason they are unable to get a can of Coke (machine empty, or no Coins) they begin to sob. iii. Pseudo-code for this is shown below: IF the student has a can THEN take a sip IF the can is now empty THEN add it to the bin OTHERWISE (i.e. the student does not have a can to start with) IF the student has a Coin AND the machine is not empty THEN insert a Coin into the machine reduce Coins by one get the can from the machine open the can and take a sip OTHERWISE student starts sobbing Hi, I would like to create a calculator which can help parents when they calculate their student's school fees on our school's joomla web site. Ive attached our school's fee table. Is there anyone who can help me please? Regards I have a class assignment that involves finding a simple recipe, and creating a unit conversion using JavaScript that tells me the exact unit of each item required to make x amount of servings. I have this so far, and every time I try to convert the units, the new units are the exact same as the original units. Please help! Code: <HTML> <HEAD> <TITLE>COMSC-100-1241 - Assignment #7 - Your Own Recipe Conversion Program</TITLE> <SCRIPT LANGUAGE="JavaScript"> function Convert(){ // Assign Variables servingsBase = parseFloat(document.getElementById("servingsBase").value); servingsNeeded = parseFloat(document.getElementById("servingsNeeded").value); var amount1 = parseFloat(document.getElementById("item1").value); document.getElementById("amount1").value = amount1 / servingsBase * servingsNeeded; var amount2 = parseFloat(document.getElementById("item2").value); document.getElementById("amount2").value = amount2 / servingsBase * servingsNeeded; var amount3 = parseFloat(document.getElementById("item3").value); document.getElementById("amount3").value = amount3 / servingsBase * servingsNeeded; } </SCRIPT> </HEAD> <BODY> <TABLE BORDER="1" WIDTH="700" ALIGN="center"> <TR> <TD> <DIV ALIGN="left"> <DIV ALIGN="center"> <B>BRIE BRUSCHETTA</B> <BR> <B>Recipe Website:</B> <A HREF="http://busycooks.about.com/od/appetizerrecipe1/r/briebruschetta.htm" TARGET="_blank">http://busycooks.about.com/od/appetizerrecipe1/r/briebruschetta.htm</A> </DIV> <BR> <B>Directions: </B> <OL> <LI>Under broiler or on grill, toast one side of the french bread slices. <LI>Turn slices over. <LI>Brush the untoasted side with some of the juices that result when you chop the tomatoes. <LI>Layer slices of brie on the bread. <LI>Return to broiler or grill and toast 2-3 minutes, until cheese is melted. <LI>Top with the chopped cold tomatoes and sprinkle with salt and pepper. Serve immediately! </OL> <BR> <B>Ingredients: </B> <UL> <LI>12 Slices of French Bread <LI>6 Ripe Tomatoes (chopped) <LI>8 Ounces of Brie Cheese (thinly sliced) </UL> <B>Prep Time: </B> 15 minutes <BR> <B>Cook Time: </B> 5 minutes <BR> <B>Total Time: </B> 20 minutes <BR> <B>Yield: </B> 4 servings </DIV> </TD> </TR> </TABLE> <BR> <TABLE BORDER="0" WIDTH="550" ALIGN="center"> <TR COLSPAN="4"> <DIV ALIGN="center"> <B><U>Recipe Converter</U></B> </DIV> </TR> <TR> <TD WIDTH="300"> <B>First Ingredient & Unit</B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="item1" VALUE="French Bread, slices"> </TD> <TD WIDTH="50"> <B>Amount: </B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="amount1"> </TD> </TR> <TR> <TD WIDTH="300"> <B>Second Ingredient & Unit</B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="item2" NAME="item2" VALUE="Tomatoes, each"> </TD> <TD WIDTH="50"> <B>Amount: </B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="amount2"> </TD> </TR> <TR> <TD WIDTH="300"> <B>Third Ingredient & Unit</B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="item3" NAME="item3" VALUE="Brie Cheese, ounces"> </TD> <TD WIDTH="50"> <B>Amount: </B> </TD> <TD WIDTH="100"> <INPUT TYPE="text" ID="amount3"> </TD> </TR> <TR> <TD COLSPAN="2"> <B>Recipe Makes This Many Servings: </B> </TD> <TD COLSPAN="2"> <INPUT TYPE="text" ID="servingsBase" NAME="servingsBase"> </TD> </TR> <TR> <TD COLSPAN="2"> <B>I Want To Make This Many Servings: </B> </TD> <TD COLSPAN="2"> <INPUT TYPE="text" ID="servingsNeeded" NAME="servingsNeeded"> </TD> </TR> <TR> <TD COLSPAN="4"> <DIV ALIGN="center"> <INPUT TYPE="Button" VALUE="Convert" OnClick="javascript:Convert();"> </DIV> </TD> </TR> </TABLE> </BODY> </HTML> Hey thanks in advance to anyone who can take a peak at my code and hopefully point me in the correct direction. I have been working on my final project in my javascript class for a bit, and there are a few erros I cant seem to find through firebug or error console. It is due this evening at midnight, so anyone that could help, I really need this assignment for a decent grade. Basically there are two issues so far, one needs to be solved so the other can be as well. First, line 103 - 105 should create a hyperlink to the specified id, but is doesn't return a number. so the link goes no where it is this code: PHP Code: //create hypertext link to the section heading var linkItem = document.createElement("a"); linkItem.innerHTML = n.innerHTML; linkItem.href = "#" + n.id; Next I belive there is a problem with the function expandCollapseDoc(), that might fix itself when the other problem is solved. The document should expand and collapse with the menu. Here is my javascript code: PHP Code: /* New Perspectives on JavaScript, 2nd Edition Tutorial 7 Tutorial Case Author: Mike Cleghorn Date: 2-15-10 Filename: toc.js Global Variables: sections An array contain the HTML elements used as section headings in the historic document Functions List: addEvent(object, evName, fnName, cap) Adds an event hander to object where evName is the name of the event, fnName is the function assigned to the event, and cap indicates whether event handler occurs during the capture phase (true) or bubbling phase (false) makeTOC() Generate a table of contents as a nested list for the contents of the "doc" element within the current Web page. Store the nested list in the "toc" element. levelNum(node) Returns the level number of the object node. If the object node does not represent a section heading, the function returns the value -1. createList() Goes through the child nodes of the "doc" element searching for section headings. When it finds a section heading, a new entry is added to the table of contents expandCollapse() Expands and collapse the content of the table of contents and the historic document expandCollapseDoc() Goes through the child nodes of the "doc" element determining which elements to hide and which elements to display isHidden(object) Returns a Boolean value indicating whether object is hidden (true) or not hidden (false) on the Web page by examining the display style for object and all its parent nodes up to the body element */ function addEvent(object, evName, fnName, cap) { if (object.attachEvent) object.attachEvent("on" + evName, fnName); else if (object.addEventListener) object.addEventListener(evName, fnName, cap); } addEvent(window, "load", makeTOC, false); var sections = new Array("h1","h2","h3","h4","h5","h6"); var sourceDoc; //document on which TOC is based on function makeTOC(){ var TOC = document.getElementById("toc"); TOC.innerHTML = "<h1>Table of Contents</h1>"; var TOCList = document.createElement("ol"); TOC.appendChild(TOCList); sourceDoc = document.getElementById("doc"); //generate list items containing section headings createList(sourceDoc, TOCList); } function levelNum(node) { for (var i = 0; i < sections.length; i++) { if(node.nodeName == sections[i].toUpperCase()) return i; } return -1; //node is not section heading } function createList(object, list) { var prevLevel = 0; //level of the pervious TOC entry var headNum = 0; //running count of headings for (var n = object.firstChild; n != null; n = n.nextSibling) { //loop through all nodes in object var nodeLevel = levelNum(n); if (nodeLevel != -1) { //node represents a section heading //insert id for the section heading if necessary headNum++; //create list item to match var listItem = document.createElement("li"); listItem.id = "TOC" + n.id; //create hypertext link to the section heading var linkItem = document.createElement("a"); linkItem.innerHTML = n.innerHTML; linkItem.href = "#" + n.id; //append the hypertext to the list entry listItem.appendChild(linkItem); if (nodeLevel == prevLevel) { //append the entry to the current list list.appendChild(listItem); } else if (nodeLevel > prevLevel) { //append entry to new nest list var nestedList = document.createElement("ol"); nestedList.appendChild(listItem); list.lastChild.appendChild(nestedList); //add plus/minus box beffore the text var plusMinusBox = document.createElement("span"); plusMinusBox.innerHTML = "--"; addEvent(plusMinusBox, "click", expandCollapse, false) nestedList.parentNode.insertBefore(plusMinusBox, nestedList.previousSibling); list = nestedList; prevLevel = nodeLevel; } else if (nodeLevel < prevLevel) { //append entry to a higher-level list var levelUp = prevLevel - nodeLevel; for (var i = 1; i<= levelUp; i++) {list = list.parentNode.parentNode;} list.appendChild(listItem); prevLevel = nodeLevel; } } } } function expandCollapse(e) { var plusMinusBox = e.target || event.srcElement; var nestedList = plusMinusBox.nextSibling.nextSibling; //Toggle the plus and minus symbol if (plusMinusBox.innerHTML == "--") plusMinusBox.innerHTML = "+" else plusMinusBox.innerHTML = "--"; //Toggle display of nested list if(nestedList.style.display == "none") nestedList.style.display = "" else nestedList.style.display = "none"; //expand/collapse doc to match TOC expandCollapseDoc(); } function expandCollapseDoc() { var displayStatus = ""; for (var n = sourceDoc.firstChild; n != null; n = n.nextSibling) { var nodeLevel = levelNum(n); if (nodeLevel != -1) { //determain display status of TOC entry var TOCentry = document.getElementById("TOC" + n.id); if (isHidden(TOCentry)) displayStatus = "none" else displayStatus = ""; } if (n.nodeType == 1) { //apply to current status for the node n.style.display = displayStatus; } } } function isHidden(object) { for (var n = object; n.nodeName != "BODY"; n = n.parentNode) { if (n.style.display = "none") return true; } return false; } the html was too long, so i uploaded it to my webspace you can check out the almost working version at http://www.kinetic-designs.net/final/usconst.htm Again thank you so much! Any questions just ask! Hi all, here are two pieces of javascript code, I'm trying to make them both do the same thing but I really need some help. The first code works and the second does not. Here I predefine the variable, then I give it a place to be displayed. ---- var x=(Math.floor(Math.random()*5)); document.getElementById("information").innerHTML=x; //works ---- The next code is the same thing but in reverse. Here I predefine where to displayed the variable, then I give it the variable. ---- var x=document.getElementById("information").innerHTML; x=(Math.floor(Math.random()*5)); //not working ---- Is there any way that I could get this second code to work? I realise that x is being fulled with the inner HTML of "information" and then begin replaced with the random number. I don't know how to store x with a command and not simply the result of a command. I have tryed... x="document.getElementById(\"information\").innerHTML"; ...but then it's just a string. The last line replaces what ever is being stored in x. I don't know how to tell java script that this variable is for showing where the information is going, not just another place to store that information. I was thinking it would look something like... (x)=(Math.floor(Math.random()*5)); ...because it's the contact of x that I'm interested in and not x itself. I'm a bit lost here, any help would be appreciated. Thanks for your time. Would someone look at the code in my program at http://www.ckdoublenecks.com/prorent.html . I need to make the "amt paid" column an input field and then make changes to other fields if the "amt paid" field is Not " " (?). Thanks in advance.
I am new to JavaScript and looking for its specification so I can learn from the manual. I see its made by Netscape, which is now liquidated... and cannot find a consortium for it.. so, am I correct in guessing its now a lost tribe?
Code: // Code for alternating row colors on data tables, but NOT every table.... just ones with classname="altRows" // Note: rowID comes from the JIT Variable: &&_sflalt // Note: This function is called in ovject group: *TR in the MLS Syntax File function stripeRows(rowVar) { // Need to create a var for uniquely identifying the highlighted rows var rowID = 0; // Begin the checking and writing of the HTML data if (rowVar == '') { var html = "<tr>"; document.writeln(html); } else if (rowVar == '0') { var html = "<tr class=\"rowEven\" id=\"evenRow"+rowID+"\" onmouseover=\"highlightRow('over', 'evenRow"+rowID+"');\" onmouseout=\"highlightRow('out', evenRow"+rowID+"');\">"; document.writeln(html); rowID++; } else if (rowVar == '1') { var html = "<tr class=\"rowOdd\" id=\"oddRow"+rowID+"\" onmouseover=\"highlightRow('over', 'oddRow"+rowID+"');\" onmouseout=\"highlightRow('out', oddRow"+rowID+"');\">"; document.writeln(html); rowID++; } else { var alertText = "Something went wrong with alternating row color in datasets - The function broke. Please jot down a note as to what you were doing when this dialogue box poped up, and let American Health Care Software know \n\n\n ATTN: Pat Litke"; parent.showDialog('Broken Function',alertText,'prompt'); } } // Function for modifying class attrbutes for row highlighting.. // This function will allows the currently moused-over row to highlight a different color based on its ID function highlightRow(option, theRowID) { var row = document.getElementById(theRowID); if(option == 'over') { row.className = 'rowOver'; } if(option == 'out') { row.className = 'rowEven'; } else if(option == 'in') { row.className = 'rowOdd'; } else { } } Can someone help? I can't figure out why this isn't working the way that I'm logically seeing it... The alternate rows highlight works fine, but the mouseover and mouseout events fail miserebly... When a page loads, regardless of where i mouse over, only the top two rows color in with the mouseOver color. They also don't revert to original coloring. Where am I going wrong? Note: I apologize if it's something little that I'm missing... I'm still new to js Hey, I have been using a tr onclick function in my tables to change the color of the most recently clicked row, it works fine. I have recently added sorttable http://www.kryogenix.org/code/browser/sorttable/ to my table with the simple <table class="sortable"> Making the table sortable has overwritten my tr onclick functions, which are now dead. Any ideas/thoughts? Heres a quick sample of what it looks like: Code: <table class="sortable"> <thead><th scope="col">Header 1</th> <th scope="col">Header 2</th></thead> <tr onclick="doSomething(this);"><td>Some data</td><td>Some more</td></tr> </table> Hi, I have this ajax routine... Code: function xhr_get(target_str,async){ var sync=true; if(async){sync=false;} var xhr = new XMLHttpRequest(); xhr.open('GET', target_str, sync); if(sync==false){ xhr.onreadystatechange = function () { if (xhr.status === 200) { try{ var ii =JSON.parse(xhr.responseText);} catch (exception) { } if(ii){ return ii; }else{ alert(xhr.responseText); return false; } } else { alert(xhr.status+' '+target_str);return false; } }; xhr.send(null); }else{ xhr.send(null); try{ var ii =JSON.parse(xhr.responseText);} catch (exception) { } if(ii){ return ii; }else{ alert(xhr.responseText); return false; } } } now if I alert(ii) on success the data I am looking for (specifically ii.content) shows up in the alert as expected however when calling from another javascript function, ii is false ???? please explain, Code: function call_change_val(fld,vm_id){ var str='?_f=load_edit_fld&_ctl_fld='+fld+'&vm_id='+vm_id+'&fld='+fld+'&width=80'; i = xhr_get('ajax/val_main_loader.php'+str,true); ////////////////////// alert(i); or alert(i.content) here both give be a blank popup///////////////// showdiv('c_change_'+fld); setih('c_change_'+fld,i.content); } I expected alert(i) to say Object or similar, getting nothing i have the following code which i am trying to insert a 'back button' into to go back to the previous page. i can only seem to get the button to appear either at the very top or very bottom of the page, does anyone know how i can specify the location? this script is generated from easypano tourweaver - Code: <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Virtual Tour Created By CAPITA SYMONDS</title> </head> <body leftMargin="0" topMargin="0" rightMargin="0" bottomMargin="0"> <script type="text/javascript" src="swfobject.js"></script> <div id="flashcontent"> To view virtual tour properly, Flash Player 9.0.28 or later version is needed. Please download the latest version of <a href="http://www.adobe.com/go/getflashplayer" target="_blank">Flash Player</a> and install it on your computer. </div> <script type="text/javascript"> // <![CDATA[ var so = new SWFObject("twviewer.swf", "sotester", "1024", "768", "9.0.0", "#FFFFFF"); so.addParam("allowNetworking", "all"); so.addParam("allowScriptAccess", "always"); so.addParam("allowFullScreen", "true"); so.addParam("scale", "noscale"); //<!-%% Share Mode %%-> so.addVariable("lwImg", "resources/2_area_multipix_preloading image file.jpg"); so.addVariable("lwBgColor", "255,255,255,255"); so.addVariable("lwBarBgColor", "255,186,186,186"); so.addVariable("lwBarColor", "255,153,0,0"); so.addVariable("lwBarBounds", "-512,-384,1024,768"); so.addVariable("lwlocation", "4"); so.addVariable("lwShowLoadingPercent", "false"); so.addVariable("lwTextColor", "255,0,0,0"); so.addVariable("iniFile", "config_2_Area_Multipix.bin"); so.addVariable("progressType", "1"); so.addVariable("swfFile", "resources/2_area_multipix_1_animation for tourweaver.swf"); so.addVariable("href", location.href); so.write("flashcontent"); // ]]> </script> </body> </html> here is the button code - Code: <span onclick="javascript:history.back()" style="text-decoration:underline; color:blue; cursor:hand">Back</span> Not sure how to explain this but...... Using a meta refresh to display a thankyou page for 5 seconds after a form submit, then return to form. If user clicks back to return to main page from form, returns to thankyou page instead, and has to go back to form again, then back to main page. I can have thankyou page return to main page, but would rather return to form. This is what it should do: main page -> form -> thankyou page -> form -> main page This is what it does: main -> form -> thankyou -> form -> thankyou -> form -> main Is there any way to remove thankyou page from history? Hi, I currently have a <div> with a <p> and have an edit button that when clicked will transform it into a textarea using jQuery's .html(). I also have a cancel button which allows the user to cancel the edit and return the textarea to the previous content, any ideas how I do this? JavaScript Code: // JavaScript Document jQuery(document).ready(function(e) { $('#edit_p').click(function(e){ $('#cancel_p').show(); $('#greeting').html("<textarea id='txt_greeting' cols='20'>" + $('#greeting p').text() + "</textarea>"); $(this).hide(); }); $('#cancel_p').click(function(e){ $('#edit_p').show(); $(this).hide(); }); }); HTML Code: <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title>Textarea/Button Change</title> <script type="text/javascript" src="jquery-1.7.js"></script> <script type="text/javascript" src="txt_area_jquery.js"></script> <link rel="stylesheet" type="text/css" href="txt_area_style.css" /> </head> <body> <div id="greeting"><p>Hello, today is a great day!</p></div> <input type="button" name="edit_p" id="edit_p" value="Edit" /> <input type="button" name="cancel_p" id="cancel_p" value="Cancel" /> <?php ?> </body> </html> I need an html page that when visited automatically redirects the browser to return to the previous page it was on. here is the current code I have: Code: <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> <script type="text/javascript"> function load() { history.go(-1) alert(""); } </script> </head> <body onload="load()"> <input type="button" value="Back" onclick="goBack()" /> </body> </html> this works in firefox but in IE you have to press ok in the alert box before it returns. I admit I am a javascript novice. Any suggestions overview: from my javascript, i call a function in the php block, that function successfully retrieves a value from the database, but when i pass that retrieved value back to the calling function....all is lost somehow. when i test this code by itself, it works fine and gets the correct number. <?php mysql_select_db($database_connFtH, $connFtH); $result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC"); $row_result = mysql_fetch_assoc($result); $index = $row_result['status_index']; echo $row_result['status_index']; echo $index; echo "the value of index is ".$index; ?> however, when i set this same code up as a function to be called upon globally, and to return the value of $index, it all just seems to "not work". <?php function runStatus() { mysql_select_db($database_connFtH, $connFtH); $result = mysql_query("SELECT status_index FROM cpqc_status ORDER BY row_id DESC"); $row_result = mysql_fetch_assoc($result); $index = $row_result['status_index']; return ($index); } //end function runStatus() ?> the calling function, with an alert box to check if the value of $index was passed down accurately <script type="text/javascript"> var x = runStatus(); alert(x); </script> all i want to do is call a server-script function that deals with the database and gets me a value out of the database, and pass that value back to the calling function. can't figure out what is wrong. the "return($index)" should send back the value of $index. the call to that function should receive back a value and assign it to "x". and the alert(x) should spit it out with no problem. but......something is wrong and it won't work. any ideas what is wrong? it is my understanding that a function inside the php determants can be called upon from anywhere and that function can return a value.(?) argh!! i think i know why Einstein's hair was always so messy!! thanks, Paul Williams weather today in Kalispell, MT: 7 deg this morning, got a little snow last night, only about 6 or 8 inches, not much. maybe more later. I am making a simple puzzle game on Android using Phonegap, that is HTML5, CSS3 and JavaScript. When a user fills an answer on a page, if the answer is correct, it will go to another page. However, once the user goes to the next page, he/she CANNOT return back to the previous page. I do not want the user to return back, else he/she will have to fill the answer again to go to the next page, so it's not good. Thank |