From junado at junado.com Mon Aug 1 17:01:19 2005 From: junado at junado.com (Julien Nadeau) Date: Mon, 01 Aug 2005 18:01:19 -0400 Subject: [Javascript] onclick - unobtrusive javascript In-Reply-To: <42E1A7ED.1060800@timburgan.com> References: <42E1A7ED.1060800@timburgan.com> Message-ID: <1CEE8A80-1989-4152-BEFD-51813FB914B8@junado.com> I'm not exactly sure why, but here's my thoughts and a working solution. Since you're applying a function to an onclick event that refers to the item itself, you have to refer to it as you normally would if it was inline. Therefore, changing the line: links[i].style.color = 'red'; to this.style.color = 'red'; works for me in Firefox 1.0.4 and Safari 2.0 on Tiger, so I guess it will work everywhere else. Julien Nadeau junado at junado.com Le 05-07-22 ? 22:14, Tim Burgan a ?crit : > Hello, > > I'm trying to use some unobtrusive Javascript by separating > behavior from structure. > > When an element is clicked, I am unable to change it's text color > to red. > But for the same element, the code does work if I choose to open a > new window on click. > > Is there any particular reason why I can't get this to work? My > code is attached below. > > Thanks > > Tim > > > > > > > Use another address > > > _______________________________________________ > Javascript mailing list > Javascript at LaTech.edu > https://lists.LaTech.edu/mailman/listinfo/javascript > > > -------------- next part -------------- An HTML attachment was scrubbed... URL: From mike at screenflicker.com Tue Aug 2 14:43:59 2005 From: mike at screenflicker.com (Mike Stickel) Date: Tue, 2 Aug 2005 13:43:59 -0600 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) Message-ID: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> Good day all, I'm fairly new to Javascript but was hoping at least someone could point me in the right direction. I'd like to try and set up a random quote box on a client's site using Javascript (typepad doesn't allow PHP otherwise I'd be using that). After some thought I was considering using XMLHttpRequest to call an XML file with the list of quotes. The quote box would be limited to showing one quote at a time but there would be links to show another quote. I guess my first question would be, is this possible? Searching through the web-o-sphere I've seen many tutorials on XMLHttpRequest and looked through a good many of them. Trying to apply their logic and examples to this particular case have gotten me thoroughly confused though. Maybe what would help is if a kind soul could write out, in plain english, the flow of how the js should work then I can at least take a stab at writing the functions. You know the old adage, learn by doing and all that. Thanks for your time, Mike Stickel Screenflicker Developments www.screenflicker.com p: 403-923-7667 e: mike at screenflicker.com From mwarden at gmail.com Tue Aug 2 15:08:48 2005 From: mwarden at gmail.com (Matt Warden) Date: Tue, 02 Aug 2005 16:08:48 -0400 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) In-Reply-To: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> References: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> Message-ID: <42EFD2D0.6020408@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mike Stickel wrote: > Searching through the web-o-sphere I've seen many tutorials on > XMLHttpRequest and looked through a good many of them. Trying to apply > their logic and examples to this particular case have gotten me > thoroughly confused though. Maybe what would help is if a kind soul > could write out, in plain english, the flow of how the js should work > then I can at least take a stab at writing the functions. You know the > old adage, learn by doing and all that. http://www.devx.com/webdev/Article/28695 There is an example of simple DOM manipulations based on the XML content received in the downloadable code. If you have questions, let me know. - -- Matt Warden Miami University Oxford, OH, USA http://mattwarden.com This email proudly and graciously contributes to entropy. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFC79LQAQ0d4HGyPE8RAiAeAJ9voiRu6/zvbsMW2y+BTGpsnlKkBACfZ6BO 0fmpLieYSQtzin7w0n+sEJ0= =yb1o -----END PGP SIGNATURE----- From flavio at economisa.com.br Tue Aug 2 15:20:00 2005 From: flavio at economisa.com.br (Flavio Gomes) Date: Tue, 02 Aug 2005 17:20:00 -0300 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) In-Reply-To: <42EFD2D0.6020408@gmail.com> References: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> <42EFD2D0.6020408@gmail.com> Message-ID: <42EFD570.4060103@economisa.com.br> Would it be a big problem if you simply downloaded all the quotes to the user in an array and then choose one randomly through "myQuotes[Math.floor(Math.random() * myQuotes.length)]". ================================================ //Example myQuotes = new Array(); myQuotes[myQuotes.length] = "Something"; myQuotes[myQuotes.length] = "Kinda"; myQuotes[myQuotes.length] = "Nice"; myQuotes[myQuotes.length] = "May"; myQuotes[myQuotes.length] = "Happen"; for (x=0; x< 25; x++) { myIndex = Math.floor(Math.random() * myQuotes.length); document.write(myIndex + ': ' + myQuotes[myIndex] + '
'); } ================================================ Yeah, it's f**king newbie stuff.. T_T But soooo pretty much crossbrowser and stuff Hope to Help, -- Flavio Gomes flavio at economisa.com.br Matt Warden wrote: >Mike Stickel wrote: > > >>Searching through the web-o-sphere I've seen many tutorials on >>XMLHttpRequest and looked through a good many of them. Trying to apply >>their logic and examples to this particular case have gotten me >>thoroughly confused though. Maybe what would help is if a kind soul >>could write out, in plain english, the flow of how the js should work >>then I can at least take a stab at writing the functions. You know the >>old adage, learn by doing and all that. >> >> > >http://www.devx.com/webdev/Article/28695 > >There is an example of simple DOM manipulations based on the XML >content received in the downloadable code. If you have questions, let >me know. > >- -- >Matt Warden >Miami University >Oxford, OH, USA >http://mattwarden.com > > From wdlists at triche-osborne.com Tue Aug 2 16:59:28 2005 From: wdlists at triche-osborne.com (Triche Osborne) Date: Tue, 02 Aug 2005 16:59:28 -0500 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) In-Reply-To: <42EFD2D0.6020408@gmail.com> References: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> <42EFD2D0.6020408@gmail.com> Message-ID: <42EFECC0.4050609@triche-osborne.com> Matt Warden wrote: > > http://www.devx.com/webdev/Article/28695 > Thanks for the link, Matt. I've been looking for information on AJAX, too. Now could someone tell me what the @ signs in the code under "Step 2" in the link below is for? In PHP it's used for error suppression, but I've never seen it used in a JavaScript before: http://www.devx.com/webdev/Article/28456/0/page/2 Triche Osborne From mike at screenflicker.com Tue Aug 2 17:03:25 2005 From: mike at screenflicker.com (Mike Stickel) Date: Tue, 2 Aug 2005 16:03:25 -0600 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) In-Reply-To: <42EFD570.4060103@economisa.com.br> References: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> <42EFD2D0.6020408@gmail.com> <42EFD570.4060103@economisa.com.br> Message-ID: On Aug 2, 2005, at 2:20 PM, Flavio Gomes wrote: > Would it be a big problem if you simply downloaded all the quotes > to the user in an array and then choose one randomly through > "myQuotes[Math.floor(Math.random() * myQuotes.length)]". > Yeah, it's f**king newbie stuff.. T_T > But soooo pretty much crossbrowser and stuff Flavio, hat may be what I fall back on but right now the list of quotes is about 50+ and it will only get bigger. I'd rather the client played around in an XML file than the Javascript file when adding new quotes. > http://www.devx.com/webdev/Article/28695 > > There is an example of simple DOM manipulations based on the XML > content received in the downloadable code. If you have questions, let > me know. > > - -- > Matt Warden Matt, this helps a little bit but I'm still confused. I've modified the Apple developer example[1] to work with my data/XML file but I don't want the user to have to click on the lists for the quote to show. I'd like one quote to show up right away and then use next/ previous links to change the quotes. I may be way off base in this type of application of Javascript but then again, that's why I'm asking the questions. [1] http://developer.apple.com/internet/webcontent/xmlhttpreq.html Mike Stickel Screenflicker Developments www.screenflicker.com p: 403-923-7667 e: mike at screenflicker.com From peter at brunone.com Tue Aug 2 18:17:39 2005 From: peter at brunone.com (Peter Brunone) Date: Tue, 2 Aug 2005 18:17:39 -0500 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) In-Reply-To: Message-ID: <003901c597b8$60ab41a0$0500a8c0@monkeyhouse> If your only worry is that the client will have to edit these by hand, couldn't you still do JS and then load all the values in a server-side include? Just a thought... Peter -----Original Message----- From: javascript-bounces at LaTech.edu On Behalf Of Mike Stickel On Aug 2, 2005, at 2:20 PM, Flavio Gomes wrote: > Would it be a big problem if you simply downloaded all the quotes > to the user in an array and then choose one randomly through > "myQuotes[Math.floor(Math.random() * myQuotes.length)]". > Yeah, it's f**king newbie stuff.. T_T > But soooo pretty much crossbrowser and stuff Flavio, hat may be what I fall back on but right now the list of quotes is about 50+ and it will only get bigger. I'd rather the client played around in an XML file than the Javascript file when adding new quotes. > http://www.devx.com/webdev/Article/28695 > > There is an example of simple DOM manipulations based on the XML > content received in the downloadable code. If you have questions, let > me know. > > - -- > Matt Warden Matt, this helps a little bit but I'm still confused. I've modified the Apple developer example[1] to work with my data/XML file but I don't want the user to have to click on the lists for the quote to show. I'd like one quote to show up right away and then use next/ previous links to change the quotes. I may be way off base in this type of application of Javascript but then again, that's why I'm asking the questions. [1] http://developer.apple.com/internet/webcontent/xmlhttpreq.html Mike Stickel Screenflicker Developments www.screenflicker.com From mwarden at gmail.com Tue Aug 2 19:15:20 2005 From: mwarden at gmail.com (Matt Warden) Date: Tue, 02 Aug 2005 20:15:20 -0400 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) In-Reply-To: <42EFECC0.4050609@triche-osborne.com> References: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> <42EFD2D0.6020408@gmail.com> <42EFECC0.4050609@triche-osborne.com> Message-ID: <42F00C98.4050003@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Triche Osborne wrote: > Matt Warden wrote: > >> >> http://www.devx.com/webdev/Article/28695 >> > Thanks for the link, Matt. I've been looking for information on AJAX, too. > Now could someone tell me what the @ signs in the code under "Step > 2" in the link below is for? In PHP it's used for error suppression, but > I've never seen it used in a JavaScript before: > > http://www.devx.com/webdev/Article/28456/0/page/2 JScript conditional execution. I tend to stay away from it, as it's browser-specific (IE). And there really is no reason to ever use it if you use objects/feature detection instead. - -- Matt Warden Miami University Oxford, OH, USA http://mattwarden.com This email proudly and graciously contributes to entropy. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFC8AyYAQ0d4HGyPE8RAhRsAJ9lRKltcDPeZxWsnTutIdctjmup9wCfZJJN DgJAUKTHrnfi2BXahuVJcS4= =3H1H -----END PGP SIGNATURE----- From mwarden at gmail.com Tue Aug 2 19:25:17 2005 From: mwarden at gmail.com (Matt Warden) Date: Tue, 02 Aug 2005 20:25:17 -0400 Subject: [Javascript] XMLHttpRequest help (yeah, yeah, I know) In-Reply-To: References: <107B8DDE-43F7-47FB-BA8F-9223646EF103@screenflicker.com> <42EFD2D0.6020408@gmail.com> <42EFD570.4060103@economisa.com.br> Message-ID: <42F00EED.8090302@gmail.com> -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Mike Stickel wrote: >> http://www.devx.com/webdev/Article/28695 >> >> There is an example of simple DOM manipulations based on the XML >> content received in the downloadable code. If you have questions, let >> me know. >> >> - -- >> Matt Warden > > > Matt, this helps a little bit but I'm still confused. I've modified the > Apple developer example[1] to work with my data/XML file but I don't > want the user to have to click on the lists for the quote to show. I'd > like one quote to show up right away and then use next/ previous links > to change the quotes. I may be way off base in this type of application > of Javascript but then again, that's why I'm asking the questions. I reference the Apple article just as background. Did you download the associated code? There is a JavaScript class called RemoteConnection that would make things a lot easier for you (maybe; it's really designed for a complex response type, not a number of results of a single response type). Here's what I would suggest: 1. Static XML file of quotes on the server, named quotes.xml. 2. In your web page, add a function to the window.onload (there is a function included in the downloadable code called addBodyOnload() that will handle adding an arbitrary number of functions to the onload, if that's a problem). 3. The function in window.onload initiates a request to the server using XMLHttpRequest (or RemoteConnection) for the quotes.xml file. 4. The quotes.xml file is then accessed via the request.responseXML property at teh appropriate time (see article). 5. You get a reference to the document element: var xml = request.responseXML; var root = xml.documentElement; 6. You get a nodeList (array) of quote elements: var quotes = root.getElementsByTagName('quote'); 7. Display a random quote, by accessing the index randomly. Something like: var randomQuote = quotes[Math.round(Math.random() * quotes.length)].firstChild; 8. Update the document using DOM with somethign like: document.getElementById('quotediv').appendChild(document.createTextNode(randomQuote)); Then, with prev/next links, you could simply access a new index of the array (that you saved, so you dont have to make another request). This is just off the top of my head. You'll probably have to work with it a bit. Take a look at the downloadable code. I'm not sure the method of respnose handling I suggest in the article is best for you, but the code is a decent example of how to do these operations. hth, - -- Matt Warden Miami University Oxford, OH, USA http://mattwarden.com This email proudly and graciously contributes to entropy. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (GNU/Linux) iD8DBQFC8A7tAQ0d4HGyPE8RAtnIAJ92YYOFjV0gqno1m1ZA2yZyGs4G3gCfUxTn 6YwYy/pigXXevZunwf4b7Us= =eatE -----END PGP SIGNATURE----- From howats at co.warren.oh.us Wed Aug 3 10:09:56 2005 From: howats at co.warren.oh.us (Howard, Terri S.) Date: Wed, 3 Aug 2005 11:09:56 -0400 Subject: [Javascript] onload focus without placing inside body tags Message-ID: <8C82E39337350548A57E83295439E84E31BBFB@w2kmail1.wc.local> I was out on the web yesterday and I came across some code that would put focus in the first field of my form without using the body tag and I cannot find that site now. Anyone know how to do this? Thank you, Terri Howard From kim.hoogenberg at virgil.nl Wed Aug 3 10:29:01 2005 From: kim.hoogenberg at virgil.nl (Kim Hoogenberg) Date: Wed, 03 Aug 2005 17:29:01 +0200 Subject: [Javascript] onload focus without placing inside body tags In-Reply-To: <8C82E39337350548A57E83295439E84E31BBFB@w2kmail1.wc.local> References: <8C82E39337350548A57E83295439E84E31BBFB@w2kmail1.wc.local> Message-ID: <42F0E2BD.1090306@virgil.nl> use document.myform.myfield.focus() after the form and field have been parsed by the browser. HTH, Kim >I was out on the web yesterday and I came across some code that would put >focus in the first field of my form without using the body tag and I cannot >find that site now. Anyone know how to do this? > >Thank you, >Terri Howard >_______________________________________________ >Javascript mailing list >Javascript at LaTech.edu >https://lists.LaTech.edu/mailman/listinfo/javascript > > From peter at brunone.com Wed Aug 3 10:31:19 2005 From: peter at brunone.com (Peter Brunone) Date: Wed, 3 Aug 2005 10:31:19 -0500 Subject: [Javascript] onload focus without placing inside body tags In-Reply-To: <8C82E39337350548A57E83295439E84E31BBFB@w2kmail1.wc.local> Message-ID: <008f01c59840$65f19ff0$0500a8c0@monkeyhouse> You mean like just putting that line of Javascript at the very bottom of the page? -----Original Message----- From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu] On Behalf Of Howard, Terri S. I was out on the web yesterday and I came across some code that would put focus in the first field of my form without using the body tag and I cannot find that site now. Anyone know how to do this? Thank you, Terri Howard From massimo at amila.ch Wed Aug 3 10:31:47 2005 From: massimo at amila.ch (Massimo Foti) Date: Wed, 3 Aug 2005 17:31:47 +0200 Subject: [Javascript] onload focus without placing inside body tags References: <8C82E39337350548A57E83295439E84E31BBFB@w2kmail1.wc.local> Message-ID: <000a01c59840$76af3550$2301a8c0@Massimo2000> > I was out on the web yesterday and I came across some code that would put > focus in the first field of my form without using the body tag and I cannot > find that site now. Anyone know how to do this? // Scan the current document, looking for text fields inside forms function tmt_placeFocus(){ var formNode = document.getElementsByTagName("form")[0]; if(formNode){ var inputNodes = formNode.getElementsByTagName("input"); tmt_focusFirst(inputNodes); } } // Put focus and cursor inside the first field of a node list function tmt_focusFirst(nodelist){ for(var i=0; i Alright, I have typed this email twice and have finally decided to just break it down to its simplest form: I have a two dimensional array that represents the # of days in a week in the first dimension and the total number of kids in an age group in the second dimension. So PlanPart[0][0] = [Sunday][1-2 year olds total attendance] PlanPart[1][0] = [Monday][1-2 year olds total attendance] Planpart[0][1] = [Sunday][3-5 year olds total attendance] PlanPart[0][2] = [Sunday][6-12 year olds total attendace] Etc... >From there I have three different One Dimensional arrays (could possible be a two dimensional array instead obviously) that contains the different quantites served for each different age group. So milk_array[0] = Amount of milk served for 1-2 year olds Milk_array[1] = Amount of milk served for 3-5 year olds Milk_array[2] = Amount of milk servedfor 6-12 year olds Grain_array[0-2] = Amount of Grains Served for each age group Fruit_array[0-2] = Amount of fruit served for each age group Now I need to be able to update nine different text boxes with the total quantities served of each different category of food * number of children in each age group for that particular day of the week. So what is the best way to name my textboxes and setup my arrays so that I can loop through them easily, make the calculation and assign it to the textbox's value. How can I do this when my page loads. There is a set of drop down boxes on the page for the current date. I want the totals to be shown for the current day of the week when the page is loaded. How can I trigger the totals to change when someone manually types in the total # of children for a specific age group? What event should I use and do I have to calculate all of the values on the page again or do I have to write four different functions to make this all happens properly? Or just one function that has a optional parameter that just tells the function to calculate a specific age group? Argh! I have this basically work, but my code is HUGE! I have three different forms I have to do calculations on and my total code length is in excess of 100k. Needless to say it does not load properly and I have to do something better. Thanks for the help in advance! Hopefully people understand what I am asking! Thanks, Fred Newtz Thanks, Fred Newtz From wdlists at triche-osborne.com Thu Aug 4 14:10:26 2005 From: wdlists at triche-osborne.com (Triche Osborne) Date: Thu, 04 Aug 2005 14:10:26 -0500 Subject: [Javascript] Calculating large number of different values In-Reply-To: <200508032259.j73Mxmg9010598@ensim.ev1servers.net> References: <200508032259.j73Mxmg9010598@ensim.ev1servers.net> Message-ID: <42F26822.9000006@triche-osborne.com> Hi Fred, I may be greatly over-simplifying your situation, and if so, I apologize, but there were a couple of points on which I was a bit fuzzy and you didn't include a link to the problem documents. Anyway, I made up a form and script to mimic the behavior you seemed to be describing. Here is a link to my form and a text version of the JS driving it: http://www.triche-osborne.com/testing/fred.html http://www.triche-osborne.com/testing/fred.txt There is a departure from your description of note: (1) You indicated that the set of dropdowns in your version were "for the current date." Since you did not indicate that they performed any function other than obtaining the *current* date, I obtained it from the JS Date object instead. If you are concerned that the user's machine date will be inaccurate or if they perform some other function such as allowing the user to choose a future date for calculating projections, this is not appropriate, and you will need to put the dropdown(s) back in. If this is not what you were describing, perhaps you could clarify the differences and include a link to the documents so that I/we have a better picture. Triche Osborne From fred at newtz.us Thu Aug 4 18:41:28 2005 From: fred at newtz.us (Fred Newtz) Date: Thu, 4 Aug 2005 18:41:28 -0500 Subject: [Javascript] Calculating large number of different values In-Reply-To: <42F26822.9000006@triche-osborne.com> Message-ID: <200508042337.j74Nbe5o023415@ensim.ev1servers.net> Thank you for the reply first of all. I thought I would be all on my own trying to figure this out. An oversimplification is probably what needed to happen in the first place. Sorry I did not put a code link but I have confidential data in there right now. I will move it to a different site and put dummy data in there, if I need more help. :-) The drop downs did serve the purpose to allow the user to change the date to set future meal menus. At some point it will also serve to allow them to look at previous menus also. However, that is for a later date and time. There are "potentially" different amounts of children attending for each day of the week. So when the date is changed it needs to be able to recalculate the whole form, not just one row. Obviously I can't just call the initialize form function when the user changes the date, so I think I will have to write a new function to pass the day of the week in there so it will calculate the values for the proper day? Or maybe I could just change the initialize form function to always receive a date as a parameter. I really did not expect to receive all this code. I sure do appreciate it in a very big way. I think I will be able to modify what you have here to suit my needs. You did for me in ~70 lines of code which took me ~350 lines of code. :-) If I run into another problem I will be sure to post the code for you to see. Thanks again, Fred -----Original Message----- From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu] On Behalf Of Triche Osborne Sent: Thursday, August 04, 2005 2:10 PM To: [JavaScript List] Subject: Re: [Javascript] Calculating large number of different values Hi Fred, I may be greatly over-simplifying your situation, and if so, I apologize, but there were a couple of points on which I was a bit fuzzy and you didn't include a link to the problem documents. Anyway, I made up a form and script to mimic the behavior you seemed to be describing. Here is a link to my form and a text version of the JS driving it: http://www.triche-osborne.com/testing/fred.html http://www.triche-osborne.com/testing/fred.txt There is a departure from your description of note: (1) You indicated that the set of dropdowns in your version were "for the current date." Since you did not indicate that they performed any function other than obtaining the *current* date, I obtained it from the JS Date object instead. If you are concerned that the user's machine date will be inaccurate or if they perform some other function such as allowing the user to choose a future date for calculating projections, this is not appropriate, and you will need to put the dropdown(s) back in. If this is not what you were describing, perhaps you could clarify the differences and include a link to the documents so that I/we have a better picture. Triche Osborne _______________________________________________ Javascript mailing list Javascript at LaTech.edu https://lists.LaTech.edu/mailman/listinfo/javascript From fred at newtz.us Fri Aug 5 12:24:04 2005 From: fred at newtz.us (Fred Newtz) Date: Fri, 5 Aug 2005 12:24:04 -0500 Subject: [Javascript] Calculating large number of different values In-Reply-To: <200508042337.j74Nbe5o023415@ensim.ev1servers.net> Message-ID: <200508051720.j75HKBUv032742@ensim.ev1servers.net> Well everything was going great. I integreated the code into three different pages, one for Lunch and Supper, and one for the three snacks that are served and of course one for Breakfast. I added the code to take care of the fact that there was more than one meal that could be planned for that page. However, now I am working on the infants menu planning page. I have posted a rendered (from PHP) page here: http://www.newtz.us/test.html Here is the javascript that I have started and am too confused to get much farther: http://www.newtz.us/javascript.txt So on this page there are three different age groups, 0-3 months, 4-7 months and 8-11 months. However, 0-3 month only get milk, 4-7 month get milk and cereal and 8-11 month get milk, cereal and fruit. I am assuming I am going to have to make three different for loops here. One for the 0-3 months, etc.. However, I am confused as to how I should name my textboxes now to work with my looping structure. I started trying to name my textboxes but I keep feeling that I need to make my looping structure before I make the names for the text boxes. What should come first? The field names/ids or the looping structure? What is a good way to plan for the names use and how you are looping through them? Thanks again, Fred -----Original Message----- From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu] On Behalf Of Fred Newtz Sent: Thursday, August 04, 2005 6:41 PM To: '[JavaScript List]' Subject: RE: [Javascript] Calculating large number of different values Thank you for the reply first of all. I thought I would be all on my own trying to figure this out. An oversimplification is probably what needed to happen in the first place. Sorry I did not put a code link but I have confidential data in there right now. I will move it to a different site and put dummy data in there, if I need more help. :-) The drop downs did serve the purpose to allow the user to change the date to set future meal menus. At some point it will also serve to allow them to look at previous menus also. However, that is for a later date and time. There are "potentially" different amounts of children attending for each day of the week. So when the date is changed it needs to be able to recalculate the whole form, not just one row. Obviously I can't just call the initialize form function when the user changes the date, so I think I will have to write a new function to pass the day of the week in there so it will calculate the values for the proper day? Or maybe I could just change the initialize form function to always receive a date as a parameter. I really did not expect to receive all this code. I sure do appreciate it in a very big way. I think I will be able to modify what you have here to suit my needs. You did for me in ~70 lines of code which took me ~350 lines of code. :-) If I run into another problem I will be sure to post the code for you to see. Thanks again, Fred -----Original Message----- From: javascript-bounces at LaTech.edu [mailto:javascript-bounces at LaTech.edu] On Behalf Of Triche Osborne Sent: Thursday, August 04, 2005 2:10 PM To: [JavaScript List] Subject: Re: [Javascript] Calculating large number of different values Hi Fred, I may be greatly over-simplifying your situation, and if so, I apologize, but there were a couple of points on which I was a bit fuzzy and you didn't include a link to the problem documents. Anyway, I made up a form and script to mimic the behavior you seemed to be describing. Here is a link to my form and a text version of the JS driving it: http://www.triche-osborne.com/testing/fred.html http://www.triche-osborne.com/testing/fred.txt There is a departure from your description of note: (1) You indicated that the set of dropdowns in your version were "for the current date." Since you did not indicate that they performed any function other than obtaining the *current* date, I obtained it from the JS Date object instead. If you are concerned that the user's machine date will be inaccurate or if they perform some other function such as allowing the user to choose a future date for calculating projections, this is not appropriate, and you will need to put the dropdown(s) back in. If this is not what you were describing, perhaps you could clarify the differences and include a link to the documents so that I/we have a better picture. Triche Osborne _______________________________________________ Javascript mailing list Javascript at LaTech.edu https://lists.LaTech.edu/mailman/listinfo/javascript _______________________________________________ Javascript mailing list Javascript at LaTech.edu https://lists.LaTech.edu/mailman/listinfo/javascript From charles.albrecht at gmail.com Sat Aug 6 03:33:58 2005 From: charles.albrecht at gmail.com (Charles Albrecht) Date: Sat, 6 Aug 2005 01:33:58 -0700 Subject: [Javascript] Wrestling with DOM access (artificial attributes, IE vs Firefox vs Safari) Message-ID: <3717c540050806013320c0a6d2@mail.gmail.com> An example of what I'm working with below is at: http://euonymic.com/~charlesa/test/menu_test.html I'm trying to find a more browser-neutral way to access artificial attributes I've attached to blocks in my HTML than... var node = document.getElementById("name"); oldvalue = node.artificialattribute // IE, Safari oldvalue = node.getAttributeNode("artificialattribute").value // Firefox, Safari var newvalue = oldvalue; node.artificialattribute = value; // IE, Safari node.setAttribute("artificialattribute", value); // Firefox, Safari In my case, the element I'm looking at is something like: [1] Now, I'm not particularly attached to leaving these in the HTML. (hidecount and expanded merely store state and start with default values anyway. level's more difficult, because I still need it in the generated source somewhere.) Actually, I'd probably prefer to get them out of the tag attributes so the page will come closer to validating against its doctype. I was trying to think of other ways of doing this. Perhaps trying to get the values out of the DOM into an object or series of objects (one for each of mytable.getElementsByTagName("tr")). But of course, it all needs to tie back to the DOM. As I walk through my table, I'm going to want to say, "based on the value I have stored for this node in the DOM, how should I set its state?" - in my case, a simple style.display="none" vs ="table-row". Any suggestions for getting this to work in a more javascipt-centric way without too many behavioral switches along the way (I already need one for Firefox for a "while (node = node.nextSibling)" loop)? How have others dealt with these kinds of issues in their code? Right now, the IE (Safari) version of the code [1] is along the lines of: var node = leaf; var level = leaf.level; while ((node = node.nextSibling) && (node.level > level)) { if (leaf.expanded) { node.hidecount++; } else { node.hidecount--; } if (node.hidecount > 0) { node.style.display = "none"; } else { node.style.display = "table-row"; } } leaf.expanded = ! leaf.expanded; The Firefox (Safari) version is much the same right now, but with "getAttributeNode(...).value" and "setAttribute(..., ...)". (I haven't even checked how all this behaves on WinIE yet.) -Charles charles.albrecht at gmail.com [1] http://euonymic.com/~charlesa/test/menu_test.html From rer at datacompusa.com Sat Aug 6 08:09:36 2005 From: rer at datacompusa.com (Roger Roelofs) Date: Sat, 6 Aug 2005 09:09:36 -0400 Subject: [Javascript] Wrestling with DOM access (artificial attributes, IE vs Firefox vs Safari) In-Reply-To: <3717c540050806013320c0a6d2@mail.gmail.com> References: <3717c540050806013320c0a6d2@mail.gmail.com> Message-ID: <965927d7d614bc0b9e61deaaa95b734e@datacompusa.com> Charls, On Aug 6, 2005, at 4:33 AM, Charles Albrecht wrote: > An example of what I'm working with below is at: > http://euonymic.com/~charlesa/test/menu_test.html > > I'm trying to find a more browser-neutral way to access artificial > attributes I've attached to blocks in my HTML than... > > var node = document.getElementById("name"); > oldvalue = node.artificialattribute // IE, Safari > oldvalue = node.getAttributeNode("artificialattribute").value // > Firefox, Safari > > var newvalue = oldvalue; > node.artificialattribute = value; // IE, Safari > node.setAttribute("artificialattribute", value); // Firefox, > Safari > > In my case, the element I'm looking at is something like: > > [1] > > Now, I'm not particularly attached to leaving these in the HTML. > (hidecount and expanded merely store state and start with default > values anyway. level's more difficult, because I still need it in the > generated source somewhere.) Actually, I'd probably prefer to get them > out of the tag attributes so the page will come closer to validating > against its doctype. A sample page would help us give more 'context-sensitive' help, but I often abuse the class attribute for this kind of stuff. The class attribute is a space delimited _list_ of values, so you could have something like var rowEl = document.getElementById("row512"); var aState = rowEl.className.split(" "); ... One advantage of this approach is that I almost never write rowEl.style.display = "none"; because that stuff all ends up in the css with class selectors. hth Roger, Roger Roelofs Know what you value. From wdlists at triche-osborne.com Sat Aug 6 10:41:30 2005 From: wdlists at triche-osborne.com (Triche Osborne) Date: Sat, 06 Aug 2005 10:41:30 -0500 Subject: [Javascript] Wrestling with DOM access (artificial attributes, IE vs Firefox vs Safari) In-Reply-To: <3717c540050806013320c0a6d2@mail.gmail.com> References: <3717c540050806013320c0a6d2@mail.gmail.com> Message-ID: <42F4DA2A.40506@triche-osborne.com> Charles Albrecht wrote: > In my case, the element I'm looking at is something like: > > [1] > > . . . Actually, I'd probably prefer to get them > out of the tag attributes so the page will come closer to validating > against its doctype. > > I was trying to think of other ways of doing this. Perhaps trying to > get the values out of the DOM into an object or series of objects (one > for each of mytable.getElementsByTagName("tr")). But of course, it all > needs to tie back to the DOM. I often initialize new instance properties (onload) for form validation. I know this works in Moz/FF and IE, though I've not tested in others. You could to the same with your TRs, providing it works in the browsers you're concerned about. Something like . . . function instantiate() { var rows = document.getElementsByTagName("tr"); for(var i=0; i < rows.length; i++) { rows[i].newProperty = "initialPropertyValue"; } } This attaches the property to the rows without impinging on your XHTML. Your remaining functions can alter the value of the property from there. Triche From wdlists at triche-osborne.com Sat Aug 6 15:47:29 2005 From: wdlists at triche-osborne.com (Triche Osborne) Date: Sat, 06 Aug 2005 15:47:29 -0500 Subject: [Javascript] Calculating large number of different values In-Reply-To: <200508051720.j75HKBUv032742@ensim.ev1servers.net> References: <200508051720.j75HKBUv032742@ensim.ev1servers.net> Message-ID: <42F521E1.50406@triche-osborne.com> Fred Newtz wrote: > > I started trying to name my textboxes but I keep feeling that I need to make > my looping structure before I make the names for the text boxes. What > should come first? The field names/ids or the looping structure? What is a > good way to plan for the names use and how you are looping through them? > Interesting question. It's one of those things that is easier to do than to explain because it's not a process I go through explicitly and there isn't just one way to do it. For me, the naming comes first. I generally consider 3 things: input data, output requirements and language resources and constraints. Input Data: (1) Attendance broken down by day of week per meal per age group (2) Food group (servings per child) broken down by meal per age group Output Requirements: XHTML: (1) Attendance => same as input (2) Food Group => input * Attendance Display Heirarchy: ------------------ Age Group => Meal => Food Group PHP: ? Language Resources and Constraints: XHTML ----- Resource: NAME attribute Constraint: If using NAME['arrayIndex'] format, must be accessed through DOM with getElementById or getElementsByTagName; that is, no direct access through form array. Resource: ID attribute Constraint: Cannot use array format. Invisible to PHP. Resource: CLASS attribute Constraint: Cannot use array format. Invisible to PHP. JavaScript ---------- Resource: instance property Constraint: Arrays pass by reference. Invisible to PHP. If PHP has to process edited textbox input in some way, I'm limited to using the NAME attribute for any data that must be processed by both languages, and I may need to use a single form so that the submit button processes everything. If not, then I'm free to use other attributes and break up the output into a form per age group. Since I don't know whether PHP has to get this information or not, I'm going to stick with one form and the NAME attribute. The first thing I'd try to do is to get a good match between my array names and textboxes, while at the same time trying to simplify the arrays as much as possible. The arrays can be looked at in different ways: PlanPart[day][meal][agegroup] PlanPart[day][agegroup][meal] In some cases, one may be more helpful than the other. In this case, for instance, you're using the first way, but your output hierarchy matches the second. I'd try to make them match. Suppose the first entry in your PlanPart array looked something like this: PlanPart["Monday"]['age0'] = [30, 30, 30, 30, 20, 15] That means that the first input box in the attendance column of your form could be named "age00". Since the array name and the day of the week are external to the form, this name gives you simple access to the secondary and tertiary levels of the PlanPart array. In the same way, modifying the food group arrays can do the same thing. Let's say the milk array looks something like this . . . var milk = new Array([3, 2, 2, 1, 1], [2, 2, 2, 1, 1], [2, 2, 2, 1, 1]) . . . where the primary level represents the age groups and the secondary level the meal. You could then name your first row, first column input box "milk00" (or "milk[0][0]"). In the places where the meal consists of more than one food group, I think I'd eliminate all but the primary attendance box. After all, if the child is present for the meal, he is present for all of the food groups. This eliminates complications with naming the other boxes. At this point, you can modify the original function to deal with the new levels OR (and I just thought of this as I was thinking on this), you could rewrite it to grab all of the INPUT tags, then flip through the inputs one by one, filling them out as you go. If you choose the latter, you might want to rearrange the column order to make it easy to "save" the attendance figure where it need to apply to multiple food groups within a single meal. Triche From charles.albrecht at gmail.com Sat Aug 6 19:44:58 2005 From: charles.albrecht at gmail.com (Charles Albrecht) Date: Sat, 6 Aug 2005 17:44:58 -0700 Subject: [Javascript] Wrestling with DOM access (artificial attributes, IE vs Firefox vs Safari) In-Reply-To: <965927d7d614bc0b9e61deaaa95b734e@datacompusa.com> References: <3717c540050806013320c0a6d2@mail.gmail.com> <965927d7d614bc0b9e61deaaa95b734e@datacompusa.com> Message-ID: <3717c54005080617443ea48fb5@mail.gmail.com> On 8/6/05, Roger Roelofs wrote: > Charls, > > On Aug 6, 2005, at 4:33 AM, Charles Albrecht wrote: > > > An example of what I'm working with below is at: > > http://euonymic.com/~charlesa/test/menu_test.html > > A sample page would help us give more 'context-sensitive' help, but I > often abuse the class attribute for this kind of stuff. The class > attribute is a space delimited _list_ of values, so you could have > something like > > Excellent way to get around "won't validate" issue. On 8/6/05, Triche Osborne wrote: > > I often initialize new instance properties (onload) for form validation. > I know this works in Moz/FF and IE, though I've not tested in others. > You could to the same with your TRs, providing it works in the browsers > you're concerned about. Something like . . . > > function instantiate() > { > var rows = document.getElementsByTagName("tr"); > for(var i=0; i < rows.length; i++) > { > rows[i].newProperty = "initialPropertyValue"; > } > } I'd done some stuff with this, but couldn't seem to get around it. I combined these two approaches, by attaching a single "state" object to each row in the onload phase and referencing its properties in my functions. I've added a new column to the sample page [1] using the new approach and it works well with all targets I've tested. My row now looks like: During onload, function setinitialstate(selector) { var rows = document.getElementById(selector).getElementsByTagName("tr"); var hasindent = /^indent_(\d+)$/; for(var i=0; i < rows.length; i++) { var row = rows[i]; var rowstate = new Object; rowstate.hidelevel = 0; rowstate.nextrow = rows[i+1]; var classes = row.className.split(" "); for (var j = 0; j level)) { if (hiding) { leaf.state.hidelevel++; } else { leaf.state.hidelevel--; } if (leaf.state.hidelevel > 0) { leaf.style.display = "none"; } else { leaf.style.display = ""; } } node.state.isexpanded = ! hiding; ... which works on all the browsers I've tested. Thanks for the pointers. -Charles charles.albrecht at gmail.com [1] http://euonymic.com/~charlesa/test/menu_test.html From schalk at volume4.com Sun Aug 7 10:14:37 2005 From: schalk at volume4.com (Schalk Neethling) Date: Sun, 07 Aug 2005 17:14:37 +0200 Subject: [Javascript] script no go Message-ID: <42F6255D.9060906@volume4.com> Greetings all Please have a look at the following code: function startList() { if (document.all&&document.getElementById) { navRoot = document.getElementById("nav"); for (i=0; iwindow.onload=startList; In IE it is supposed to mimic the :hover pseudo class but, as of now nothing happens. No errors are thrown either. Can anyone see why this code will not execute? Thank you in advance. -- Kind Regards Schalk Neethling Web Developer.Designer.Programmer.President Volume4.Business.Solution.Developers emotionalize.conceptualize.visualize.realize Landlines Tel: +27125468436 Fax: +27125468436 Web email:schalk at volume4.com Global: www.volume4.com Messenger Yahoo!: v_olume4 AOL: v0lume4 MSN: volume4_ at hotmail.com We support OpenSource Get Firefox!- The browser reloaded - http://www.mozilla.org/products/firefox/ This message contains information that is considered to be sensitive or confidential and may not be forwarded or disclosed to any other party without the permission of the sender. If you received this message in error, please notify me immediately so that I can correct and delete the original email. Thank you. From wdlists at triche-osborne.com Sun Aug 7 15:29:59 2005 From: wdlists at triche-osborne.com (Triche Osborne) Date: Sun, 07 Aug 2005 15:29:59 -0500 Subject: [Javascript] script no go In-Reply-To: <42F6255D.9060906@volume4.com> References: <42F6255D.9060906@volume4.com> Message-ID: <42F66F47.1070700@triche-osborne.com> Schalk Neethling wrote: > I call this code as follows: > > Split this out to: Triche From schalk at volume4.com Sun Aug 7 15:36:56 2005 From: schalk at volume4.com (Schalk Neethling) Date: Sun, 07 Aug 2005 22:36:56 +0200 Subject: [Javascript] script no go In-Reply-To: <42F66F47.1070700@triche-osborne.com> References: <42F6255D.9060906@volume4.com> <42F66F47.1070700@triche-osborne.com> Message-ID: <42F670E8.1020501@volume4.com> Thanks Triche, but unfortunately still no go. I do have the ul tagged as