ShrineDesigns
01-17-2003, 06:24 PM
*brain fart* lol
how can i fetch a string in one function so i can use it in another function ???
how can i fetch a string in one function so i can use it in another function ???
|
Click to See Complete Forum and Search --> : Passing strings between functions... ShrineDesigns 01-17-2003, 06:24 PM *brain fart* lol how can i fetch a string in one function so i can use it in another function ??? swon 01-17-2003, 06:39 PM Do you mean something like: function firstfunction() { var str = "test"; another(str); } function another(x) { alert(x); } Is it that? khalidali63 01-17-2003, 06:57 PM A tiny bit of addition to swons code. You can get a value returned be a function to, function firstfunction() { var str = "test"; str = another(str); alert(str) } function another(x) { alert(x); return x+" changed"; } you pass a string to another function mosify it return it back to firstfunction and then use it there Khalid stewie 01-17-2003, 07:16 PM does it work if you set the string as a global variable (outside and before all the functions) then you can call the variable by any function you write afterwards? var s = new String("firststring"); var t = new String("secondstring"); stewie ShrineDesigns 01-17-2003, 11:38 PM hmm... i am trying to get the strings that are for this function function largeView(dir,img,W,H) i need to get W and H for use in another function how could i do this ??? khalidali63 01-18-2003, 12:43 AM Ok I get it,you want to know to create a user defined object and then access its local variables. here take a look at the code snippet below,It creates an object largeView using a constructor that takes 4 parameters. and then creates an instance of that object and then access its local variables <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled</title> </head> <body> <script language="JavaScript1.2"> function largeView(dir,img,W,H){ this.dir=dir; this.img=img; this.W=W; this.H=H; } lvObj = new largeView("C:","arrow.gif",400,300); alert("lvObj.W = "+lvObj.W+", lvObj.H = "+lvObj.H); </script> </body> </html> Charles 01-18-2003, 06:37 AM 1 - The HTML 4.01 DOCTYPE doesn't look like that. 2 - In HTML 4.01 the SCRIPT element has no LANGUAGE attribute. 3 - In the naming convention used by JavaScript class names begin with a capitol letter. 4 - It's considered bad programming to access an internal object value directly. You are supposed to use a function. (Note, these items are in decreasing order of severity.) <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <meta name="Content-Script-Type" content="text/javascript"> <title>Untitled</title> </head> <body> <pre> <script type="text/javascript"> <!-- function LargeView(dir,img,w,h){ this.dir=dir; this.img=img; this.w=w; this.h=h; } LargeView.prototype.getW = function () {return this.w} LargeView.prototype.getH = function () {return this.h} lvObj = new LargeView("C:","arrow.gif",400,300); document.writeln('lvObj.getW() = ', lvObj.getW()); document.writeln('lvObj.getH() = ', lvObj.getH()); // --> </script> </pre> </body> </html> khalidali63 01-18-2003, 07:08 AM Thanks for pointing out some of the errors which I make using the editor and never notice them.. :-) webdeveloper.com
Copyright Internet.com Inc., All Rights Reserved. |