JavaScript - Sending Arrays To Method Help
I cannot figure out how to return the array back to the main method!
what am I doing wrong?? import java.util.*; //lab 3 public class Prices { public static void main(String[] args) { double []array; array = new double[10]; double fullPrice; fullPrice = fillPrices(array); System.out.println("testing"); } public static double fillPrices(double []tenValues) { Scanner input = new Scanner(System.in); double prices; System.out.println("Please enter 10 prices: "); for (int i = 0; i < 10; i++) tenValues[i] = input.nextDouble(); return tenValues; } } I thought you return an array by simply return (array name); Am i missing something? Thanks a bunch for whoever takes the time to help me! Similar TutorialsI'm a newbie of JS and don't know if I have got the right terms in my question. I want to lowercase all the arrays: Code: <script> var txt = [ ["Cats","Dogs","Rabbits"], ["Fish","Bones","Carrots"] ] document.write(txt[0][1] + " love eating " + txt[1][1]); </script> I know I can do something like this: Code: document.write(txt[0][1].toLowerCase() + " love eating " + txt[1][1].toLowerCase()); // or var txt1 = txt[0][1] + " love eating " + txt[1][1]; document.write(txt1.toLowerCase()); But if I will loop through all the arrays and print them out, I am bothered with appending .toLowerCase(0 after each array one by one, so is there any way to bind that method at one go? I hope my question is understandable. Maybe I've used wrong terms of JS. Thank you. You've probably seen this many times with two dynamic linking select boxes that deals in form or another deal with countries and then cities for the second one or something similar well I have another question about that. I've looked at a few others and well their coding is so different then mine that I don't want to use code for my own project that I don't understand in case I need to reuse it for some other reason down the road. The user selects a country and with the users selection it passes the countryid as a variable through jquery's ajax fuction as a post parameter to a php process page in which it goes to a table and matches the country id with the db field called country_id in the arenas table. With all the records that matches that countryid it selects the arena name and city that the arena is in and displays it as an option tag now I'm trying to figure out with muliple entries how can I pass the results back to the form page and insert it into the arenas dropdown box. Following is my coding separated out for you. I only included the necessary parts. All help would be greatly appreciated. form page Code: $('#countryid').change(function() { var countryid = $("select#countryid").val(); var dataString = 'countryid='+ countryid; $.ajax({ type: "POST", url: "processes/booking.php", data: dataString, success: function() { } }); }); <div class="field required"> <label for="countryid">Country</label> <select class="dropdown" name="countryid" id="countryid" title="Country"> <option value="0">- Select -</option> <?php $query = 'SELECT id, countryname FROM countries'; $result = mysqli_query ( $dbc, $query ); // Run The Query while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) { print "<option value=\"".$row['id']."\">".$row['countryname']."</option>\r"; } ?> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> <div class="field required"> <label for="arena">Arenas</label> <select class="dropdown" name="arenas" id="arenas" title="Arenas"> </select> <span class="required-icon tooltip" title="Required field - This field is required, it cannot be blank, and must contain something that is different from emptyness in order to be filled in. ">Required</span> </div> php process page PHP Code: $countryid = (int)$_GET['countryid']; $query = "SELECT * FROM `arenas` WHERE `country_id` = '$countryid'"; $result = mysqli_query ($dbc, $query); while ($row = mysqli_fetch_array($dbc, $result)) { echo '<option value="'.$row['arena'].'">'.$row['arena'].' - '.$row['city'].'</option>\n'; } Why is the callwhy is the slice method only a method of an Array instance? The reason why I ask is because if you want to use it for the arguments property of function object, or a string, or an object, or a number instance, you are forced to use Array.prototype.slice.call(). And by doing that, you can pass in any type of object instance (Array, Number, String, Object) into it. So why not just default it as a method of all object instances built into the language? In other words, instead of doing this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; console.log(typeof arguments);//Object console.log(arguments instanceof Array);//false var args1 = Array.prototype.slice.call(arguments); console.log(args1); var args2 = Array.prototype.slice.call(obj); console.log(args2); var args3 = Array.prototype.slice.call(num); console.log(args3); var args4 = Array.prototype.slice.call(string); console.log(args4); Core('dom','event','ajax'); Why not just be able to do this: Code: function Core(){ var obj = {a : 'a', b : 'b'}; var num = 1; var string = 'aff'; var args = arguments.slice(0); var args2 = obj.slice(0); var args3 = num.slice(0); var args4 = string.slice(0); //right now none of the above would work but it's more convenient than using the call alternative. } Core('dom','event','ajax'); Why did the designers of the javascript scripting language make this decision? Thanks for response. I need to loop the alphabet and numbers 0-9 to initialize a few thousand arrays. This is for my site and is truly needed. http://www.thefreemenu.com I currently have every array written out and it takes up to much space in my .js file. The majority of my variables are empty but necessary and need to be there (including empty) for my site to work properly. Question is the last part Here's where I'm at. Code: var NewVarLetterOrNum = "a"; eval("_oneofseveralnames_" + NewVarLetterOrNum + "='this part works';"); alert(_oneofseveralnames_a); This creates the variable _oneofseveralnames_a='this part works' Code: var newArrayLetterOrNum = "a"; eval("_oneofseveralnames_" + newArrayLetterOrNum + "= new Array();"); alert(_oneofseveralnames_a) This creates the Array _oneofseveralnames_a=new Array(); and all the values in the array are null, but, now a variable like _nl_a[1]='something' can be used elsewhere because the array exists. This is all that is necessary for now because I can probably set all the variables to be blank with something like Code: i=1 while(i<=20){ _oneofseveralnames_a[i]="1-20"; i++ } alert(_oneofseveralnames_[20]); So now you have what I came to understand in the first few hours. Now to the hard part : ( I can't make multiple array's dynamically. I dont' know if its because I don't understand loops or arrays or what and its very fustrating. As for any answer you might be so kind as to provide, if you could dumb it down that would be greatly appreciated. Code: var newArray =new Array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z') i=1 while(i<=26){ eval("_nl_" + newArray[i] + "= new Array();"); i++ } alert(newArray[1]) // Is b, but alert(_nl_b) //I can't get _nl_b to exist, I tried everything including taking away the quotes around the letters in every test */ var _nl_a =new Array() var _img_a =new Array() var _h_a =new Array() var _r_a =new Array() var _m_a =new Array() var _yt_a =new Array() var _i_a =new Array() The above arrays are all the array _name_ parts I need but for example, a has 10 parts, a,p2_a,p3_a,.. p10_a. I need 10 pages for each letter of the alphabet and numbers 0-9 and a special all1, p2_all1 ... p10_all1. Overall 2200 arrays that need to be declared. Currently they are all written out. /* So I'm new around here, and to web dev in general, but I've got a (hopefully) short question. I am trying to call a function (nextMonth()) every second from the time that the cycle method gets called, until it is called again. As of now I am trying to use setInterval, (and I previously tried with setTimeout and using a callback argument but maybe I wasn't doing that properly). The problem is that after running the cycle() method for 5 or 6 seconds, the entire browser freezes up and you have to kill it and restart it. Here is my code as of now: Code: function cycle() { if(CYCLEINT != null) //STOP THE CYCLE LOOP { window.clearInterval(CYCLEINT); CYCLEINT = null; document.getElementById("cycle").innerHTML = "Cycle Months"; } else //LOOP IS NOT RUNNING, INITIATE AND CONTINUE INTERVAL. { CYCLEINT = self.setInterval("nextMonth()", 1000); document.getElementById("cycle").innerHTML = "Pause"; } } function prevMonth() { var dVal = $( ".slider" ).slider( "option", "value"); if(dVal > 1) { dVal--; $( ".slider" ).slider( "option", "value", dVal ); refresh(); } } function nextMonth() { var dVal = $( ".slider" ).slider( "option", "value"); if(dVal < dateMax) { dVal++; $( ".slider" ).slider( "option", "value", dVal ); refresh(); } if(CYCLEINT != null && dVal >= dateMax) { cycle(); } } I am using javascript for adding and removing rows from table as per user require ment like if we press ADDROW button it adds extra row to table and if we pressREMOVEROW it delets the last row.. Now i want to access the data from textbox like this.. var crpt = document.getElementById("itrtr2").value; //no. of rows for(var k=1;k<=crpt;k++) { qtyc = document.getElementById("txtRowc3"+k).value; unit_pricec = document.getElementById("txtRowc5"+k).value; alert('QTYC:'+qtyc+' UPC:'+unit_pricec); cttl = qtyc * unit_pricec; document.getElementById("txtRowc6"+k).value = cttl.toFixed(2); csbttl = csbttl + cttl; } document.getElementById("subttlC").value=csbttl.toFixed(2); it shows the value of textRowc3i in qtyc in alert box but also givs error document.getElementById("txtRowc3"+k) is null.. I tried for this but problem is not solved please help... Thank You... I'm trying to write a method called printPowersOfN that accepts a base and an exponent as arguments and prints each power of the base from base0(1) up to that maximum power, inclusive. For example, I'm trying: printPowersOfN(4, 3); printPowersOfN(5, 6); printPowersOfN(-2, 8); which should give me: 1 4 16 64 1 5 25 125 625 3125 15625 1 -2 4 -8 16 32 64 -128 256 but I only get: 64 15625 256 Here's my code: Code: public class Powers { public static int printPowersOfN (int base, int exponent) { int answer = 1; for (int i=1; i <= exponent; i++) { answer*=base; } return answer; } public static void main(String[] args) { System.out.println(printPowersOfN(4, 3)); System.out.println(printPowersOfN(5, 6)); System.out.println(printPowersOfN(-2, 8)); } } What should I change so that it does all of the powers? Sup gents. Im having problems with the link method. Its tied up to a button in the form. The link method sees the "global" variable and determines if its 1 or 0. If its 1 it gives a certain msg and if its 0 another one. Problem its always reading the variable as 0 and giving me the same message regardless of the fact that im typing the username and password correc Code: <html> <head> <script type ="text/JavaScript"> var counter = 0; var counter2 = 0; var arraynumb = 0; var arraynumb2 = 0; var global; var array = ['Mohamad', 'Karim', 'Anthony', 'Rami', 'Natalia', 'Sarah', 'Samer', 'Violette', 'Plume', 'Sharshabil']; var array2 = ["1000", "1001", "1002", "1003", "1004", "1005", "1006", "1007", "1008", "1009"]; function pass(){ var searchKey = document.searchform.inputVal.value; for (var i = 0, len = array.length; i < len; i++){ if (array[i] == searchKey){ counter = 1; arraynumb = i; } } } function pass1(){ var searchKey2 = document.searchform.inputVal2.value; for (var i = 0, len = array2.length; i < len; i++){ if (array2[i] == searchKey2){ counter2 = 1; arraynumb2 = i; } } } function access(global) { if (counter == 1 && counter2 == 1 && arraynumb == arraynumb2) { window.alert("You may now access the website"); global = 1; } else window.alert("You may not access the website"); global = 0; } function link(global) { if (global == 1) { window.alert("you may proceed to the link"); } else window.alert("you are not signed in, please do so"); } </script> </head> <body> <form name = "searchform" action = ""> <p>Enter username<br/> <input name = "inputVal" type = "text" size = "30"/> <input name = "search2" type = "button" value = "Search" onclick = "pass()"/> </p> <p>Enter password<br/> <input name = "inputVal2" type = "password" size = "30"/> <input name = "search" type = "button" value = "Search" onclick = "pass1()"/> <input name = "Access site" type = "button" value = "Access" onclick = "access()"/> <input name = "link to" type = "button" value = "link" onclick = "link()"/> <br/> </p> <br/> <p></p> </form> </body> </html> Have the code check that the statement has at least one character. You can do this by using the trim method to remove spaces from the beginning and end, and then checking the length of the trimmed string. If there are no characters, the response should tell the user to enter something. For example, a possible statement and response would be: Statement: Response: Say something, please. Could someone help me with this? I'm not sure how to make it check to see if the user input has 0 characters. Im working on learning JavaScript with the help of a text book, below is the current script I am working on regarding handling forms. This script should populate the "Days" field depending on the Month selected. I understand most of it except for the parseInt function. Could anyone help describe it to me? I understand it turns a String into a Value...hmm Code: window.onload = initForm; function initForm() { document.getElementById("months").selectedIndex = 0; document.getElementById("months").onchange = populateDays; } function populateDays() { var monthDays = new Array(31,28,31,30,31,30,31,31,30,31,30,31); var monthStr = this.options[this.selectedIndex].value; if (monthStr != "") { var theMonth = parseInt(monthStr); document.getElementById("days").options.length = 0; for(var i=0; i<monthDays[theMonth]; i++) { document.getElementById("days").options[i] = new Option(i+1); } } } Thank you! I am very interested in learning this and would love any help! Write a public static method named starPrinter that will take an int as a parameter and print lines of stars as shown below. The header of the method will be public static void starPrinter(int n) . This is what it should look like: Please help! I am trying to impliment Javascript code to replace the MS Tabular data control. How do I go about creating a Fields collection object that has a default method of Item(idx) ie. myrs.Fields.Item(4).name is the same as myrs.Fields(4).name i want to write a code which would prompt the user for his first name and last name with space in between them.The full name must be entered in the same prompt box.Using the charCodeAt() method i wanna test the first character of the user's first name as well as last name.If the first character of first name is in lowercase then it should alert the user as "first name must start with uppercase".And if the first character of second name is in uppercase then it should alert the user as "second name must start with lowercase". ..plzzzz help me and give me some code for this..i m a beginner in javascript..
Hi there I'm trying to figure out what the following syntax for split means in the following line of the code arrTest[0].split('/')[0] what does ('/')[0] means in split('/')[0]? please can anyone explain When you use a form and submit it the URL bar changes to what the submitted values are. So can anyone explain how to use this?
If anyone could help me, I would soooo appreciate it. I'm writing this program and I can't seem to figure out what the problems is. I'm new to this and really bad at it. public class Points { int ycoordinate; int xcoordinate; public Points(){ ycoordinate=0; xcoordinate=0; } public Points(int xcoord, int ycoord) { xcoordinate=xcoord; ycoordinate=ycoord; } public int getxcoordinate() { return xcoordinate; } public int getycoordinate() { return ycoordinate; } public void setxcoordinate(int xcoord) { xcoord=xcoordinate; } public void setycoordinate(int ycoord) { ycoord=ycoordinate; } public int distanceFromOrigin() { int point1=(xcoord-0)*(xcoord-0); int point2=(ycoord-0)*(ycoord-0); int distance=Math.sqrt(point1+point2); } public String Points() { String str="The distance between the coordinates is:"+""+distance; return str; } } I am using this method inside a if and whenever controller come to this point it is throwing an undefined exception intead it should check if null or anything present. How to handle this?
Hello Everybody, As all coders have no time I will bring it up directly. 1- We are launching a new website at a small ceremony. 2- The website will have initial page that has a button says "Launch Me". 3- When the official presses the Launch Me button we need it to rename the index file with the official page for the full website we created. We thought about coding a batch file that will have the FTP details and commands to rename the index file with the Official page, but the problem here is that we don't know how to create such a button that will execute the .bat file on the server side. All what we need is a button or any way that will rename the index file with the official one by pressing a button. Any tips people? Thanks in-advance. Hello everyone, I'm working with the insertBefore method and am having a slight issue that l'm sure is very easy to fix but l can't figure it out. If you look at the following page and click the "add game" button you'll see that extra "game" tables are added to the page. http://www1.theworldlink.com/test/insertBefore.php In the above example the <div id="box_scores"></div> tag is found directly before the closing <body> tag (and l need it inside of a form element). however on this example: http://www1.theworldlink.com/test/insertBefore2.php I have the <div id="box_scores"></div> div inside of a form element as apposed to directly before the closing <body> tag and the script fails to work. Here is the JS code that l'm using: Code: newDiv = document.createElement("div"); newDiv.innerHTML = 'test test test'; my_div = document.getElementById("box_scores"); document.body.insertBefore(newDiv, my_div); and l'm certain the problem is he document.body.insertBefore(newDiv, my_div); I've tried: document.body.forms[0].insertBefore(newDiv, my_div); and several other varients but l can't figure it out.... any help would be greatly appreciated!!!! not sure anything wrong with my IE8 browser or 'createTextNode' method. here comes the bug: if you directly do this document.body.appendChild(document.createTextNode(" "+"a")), then there won't be any spaces before 'a' however, if the argument of that method is changed to "a"+" "+"a", this time it will be ok. why it cannot create the leading spaces before any non-whitespace string? thx in advance. |