Prev: array or list of objects of different types
Next: Collections / Static typing - was "array or list of objectsof different types"
From: tedd on 3 Apr 2010 12:23 At 4:22 PM +0100 4/3/10, Ashley Sheridan wrote: >> >I think Tedds main reason not to use Javascript is that he needs it >to be done on the server rather than the client machine. > > >ps. please use bottom posting on the list. > >Thanks, >Ash Yeah, one reason was to get this done in one operation and not step through the questions like I would have to do using javascript to approve (trigger) each step. But my main reason for posting was to see if PHP had DOM operators like javascript. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com
From: Nathan Nobbe on 3 Apr 2010 12:29 On Sat, Apr 3, 2010 at 10:18 AM, tedd <tedd(a)sperling.com> wrote: > At 8:14 AM -0600 4/3/10, Peter Pei wrote: > >> No javascript's getElementByID() won't work here. As "question" is a >> class, not an ID. But like what was mentioned here, you can use >> getElementByClass() with Opera, and that will work. >> > > Sort of. > > Like I said, the folling will work: > > document.getElementById("question").innerHTML; > > While you are using a getElementById, which returns an ID, but adding > .innerHTML will return the class value. > > Try it. > i did, and just like i thought, it doesnt work. why, .innerHTML is executed *after* document.getElementById("question"), meaning if that returns nothing; which in this case it does, then there is nothing for innerHTML to operate on. i in fact had to wrap the call in an exception just to get it from blowing up in firefox. <html> <head> </head> <body> <p class="question"> Who is Roger Rabbit? </p> <script type="text/javascript"> <!-- try { var oQuestion2 = document.getElementById('question').innerHTML; } catch(e) { alert(e); } --> </script> </body> </html> heres what firefox says on my box: TypeError: document.getElementById("question") is null and btw, i think after seeing your solution we can see why i like the xpath approach so much more :P -nathan
From: tedd on 3 Apr 2010 12:29 At 9:14 AM -0600 4/3/10, Peter Pei wrote: >>>Somejavascript engine already support GetElementByClass, for >>>example Opera does. >> >>My example shows how, namely: >> >>document.getElementById("question").innerHTML; >> >>will return the value within the class. >> >>Cheers, >> >>tedd >> > >In your original post, you said the data you had was: > ><p class="question"> > Who is Roger Rabbit? ></p> > >Does that still stand? or there was a typo, and class should really be ID? You're right -- I re-looked at the code to solve a similar problem and it is indeed ID and not class. I was using the wrong example. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com
From: tedd on 3 Apr 2010 12:30 At 12:18 PM -0400 4/3/10, tedd wrote: >At 8:14 AM -0600 4/3/10, Peter Pei wrote: >>No javascript's getElementByID() won't work here. As "question" is >>a class, not an ID. But like what was mentioned here, you can use >>getElementByClass() with Opera, and that will work. > >Sort of. > >Like I said, the folling will work: > >document.getElementById("question").innerHTML; > >While you are using a getElementById, which returns an ID, but >adding .innerHTML will return the class value. > >Try it. > >Cheers, > >tedd >-- Nope, I was wrong here. I was looking at the wrong example. Cheers, tedd -- ------- http://sperling.com http://ancientstones.com http://earthstones.com
From: "Peter Pei" on 3 Apr 2010 11:33
> Sort of. > > Like I said, the folling will work: > > document.getElementById("question").innerHTML; > > While you are using a getElementById, which returns an ID, but adding > .innerHTML will return the class value. > > Try it. > > Cheers, > > tedd No, this will not work, if it appeared working, please re-check your data, and make sure you didn't miss anything... Run the following in any browser, and see whether you get a pop up, then change class= to ID=, and run it again. <body onload='alert(document.getElementById("question").innerHTML)'> <p class="question"> Who is Roger Rabbit? </p> </body> innerHTML works off an object, and it does nothing if youu cannot even locate the object in the first place. -- Using Opera's revolutionary e-mail client: http://www.opera.com/mail/ |