| |
| |
| |
|
Page: 1 2 3 4 5 6 7 8
<bluefoxicy> <div name="changeme">foo</div> <bluefoxicy> and after a user clicks a button, it changes that to <bluefoxicy> <div name="changeme"><p><b>HELLO!</b></p></div> <bluefoxicy> or some such deal. <TheoCode> okie, 1 min <bluefoxicy> sweet. I can call PHP functions on the URI now <TheoCode> I did it using an ID <bluefoxicy> can you show me? <TheoCode> this won't work with a non standard dom <bluefoxicy> so it breaks IE? <TheoCode> http://pastebin.bafserv.com/1658 <TheoCode> it will have problems in netscape 4 and IE 4 <bluefoxicy> but most modern day browsers with JS? <TheoCode> yeah, it would be fine <bluefoxicy> alrighty <bluefoxicy> http://192.168.1.105/bluefox/ajax/add.php?call=add&a=3&b=7.2 The page source for this URI is exactly "10.2", is there a way to read the page source into a java script variable? <TheoCode> I don't know off hand, anyone else out there? <bluefoxicy> google does it using an iframe but I'd prefer a more direct method. <Zyclops> function myobject() { this.public_variable = 'public var'; function private_function() { public_variable = '; }} <Zyclops> public_variable should equal nothing? <Zyclops> or to have access to public_variable does private_funciton actually have to be a priviliged method? <bluefoxicy> <input type="input" name="num_a" value="0" /> <bluefoxicy> a = num_a.value; <bluefoxicy> Error: num_a is not defined <kicken> Just because you name an element doesn't mean it's automatically available by that name. <bluefoxicy> right <bluefoxicy> used getElementById() <bluefoxicy> TheoCode: Your solution spits out visible <p></p> if I write "<p></p>" <bluefoxicy> i.e. it's like <p></p> <kicken> If you set .nodeValue, HTML isn't interpureted <kicken> if you set .innerHTML it is, but even then I think there are a few problems. <Zyclops> In a javascript object how do you define a variable has having global scope to that object so that all the functions in that object can access it <kicken> by making it a property of `this' <kicken> this.whatever = blah; <Zyclops> so in the object i go this.myproperty = blah; <Zyclops> lol <Zyclops> and in the function of the object i can just use myproperty = 'blah2" <Zyclops> and object.myproperty should equal 'blah2' <kicken> No. <Zyclops> ahh ok <kicken> You always have to use `this' <bluefoxicy> what what objects can you .src and .innerHTML on <kicken> It's not optional like in some other languages. <Zyclops> so in the function i should use this.myproperty = 'bla2'; <kicken> bluefoxicy technically, .innerHTML isn't standard, which is why there might be some problems with it. However, for browsers which do support it, you can use it on about any dom element. <bluefoxicy> kicken: I'm trying to download a URI into a variable and act on its contents directly <kicken> .src I dunno if that's standard or not, but it'd be available on those elements which have a src attributes (images, frames, etc) <kicken> bluefoxicy xmlhttprequest. <bluefoxicy> ? <kicken> http://www.aoeex.com/extras/suggest.html <Zyclops> kicken: i can't manipulate the variable in the object from a function in that object, any ideas? <kicken> how are you declaring the function? <Zyclops> i've tried this.show_menu = function(e) { <Zyclops> and just function show_menu(e) <Zyclops> as a nested function in the object <kicken> this.show_menu=function(e){...} is correct. <kicken> or Object.prototype.show_menu=function(e){...} from outside the object. <bluefoxicy> ok <Zyclops> in the object i have a line of code this.TEST_VARIABLE = 'test'; and in the function i have this.TEST_VARIABLE = 'die'; I make sure i call the function, then check the value of instance_of_object.TEST_VARIABLE, and it's still equal to test <kicken> how do you call the function? <Zyclops> event_element.oncontextmenu = this.show_menu(); <Zyclops> show_menu() definitly runs <Zyclops> becuase it displays a menu <Zyclops> and if i alert this.TEST_VARIABLE straight after,it displays 'die' <Zyclops> straight after the ***ignment in the function that is <kicken> put the code in the pastebin, or give me a URL to it. <Zyclops> kicken: http://pastebin.com/397248 <Zyclops> I still don't think i understand js variable scope properly <kicken> You can't really ***ign a member function to be an event handler. <kicken> event_element.oncontextmenu = this.show_menu; That makes show_menu the event handler, but inside show_menu `this' will point to event_element, not your object. <Zyclops> hmmm, is there anyway around that? <bluefoxicy> SWEET! <Zyclops> ahhh that makes sense <bluefoxicy> I now have an add.php file that includes an ajax.php file <bluefoxicy> and an html file with no php in it <kicken> The lazy way around it is to just ***ign a custom property to event_element that references your object <kicken> I tend to call it me. <bluefoxicy> and the html file takes 2 numbers, reads add.php?call=add&a=(a)&b=(b) and adds (a) and (b) <kicken> event_element.me = this; event_element.oncontextmenu = this.show_menu; <Zyclops> lol, thats a really intersting work around <kicken> then inside show_menu, you can use this.me to get to your object. <Zyclops> Thankyou! thats actually a nice solution <kicken> I started on a photo gallery that used xmlhttp to change properties and stuff. It's pretty cool actually. Only works decently in mozilla because of my drag/drop script though. <Zyclops> kicken: do you think if i'd used an event handler script i could have worked around that problem as well? <kicken> What do you mean an event handler script? <Zyclops> kicken: your solution workes perfectly <Zyclops> http://www.twinhelix.com/javascript/addevent/demo/ << like this, my understading is that it handles all events seperatly <kicken> I don't think a script like that would be of a real big help. <Zyclops> ok <kicken> The more proper way to get around the problem would be to use what's known as a closure <kicken> but they can be a bit complicated at times. <kicken> and a bit of a pain sometimes. <Zyclops> i've read about that. It's all working now so thats what counts/ <bluefoxicy> http://i2.photobucket.com/albums/y10/bluefoxicy/test_ajax.png <Zyclops> new_menu_item.onclick = function() { << is there anyway to make the reference a new function every iteration? <Zyclops> because i'm finding that instead of creating an individual function for each menu_item, menu_item.onclcik just references the last function to be ***igned to onclick <khaladan> you could wrap it in another function that returns a function <khaladan> = function() { return function() { ... } } (); <Zyclops> thats a good idea <Zyclops> damn, it breaks a reference to another object then <khaladan> oh? <Zyclops> what i'm doing is creating a number of menu items and adding specific onclick events to them like <Zyclops> new_menu_item.onclick = window[call_js_function](this.me.event_element_data); << is what i tried first <Zyclops> call_js_function is just a string of a function name <Zyclops> event_element_data is some preset data it needs <khaladan> mmmm <Zyclops> so i then change that to .onclick = function() { windows[call_js_function](this.me.event_element_data); } <Zyclops> but then the last menu item onclick function overwrites all the rest <Zyclops> so if i nest it again i lose the reference to this.mne <Zyclops> this.me even <khaladan> right <khaladan> it's because of some lexical scope crap <Zyclops> yep <Zyclops> i don't really understand js scope that clearly even though i spent an hour reading about it <Zyclops> i'm wondering if i should just define a variable outside of the object <Zyclops> and use that, since i only need one for all instances <khaladan> what i think you need to do is this <khaladan> .onclick = function(item) { return function() { windows[call_js_function](item.me.event_element_data); } } (new_menu_item); <Zyclops> new_menu_item.me = this; <Zyclops> new_menu_item.onclick = function(new_menu_item) { return function() { window[call_js_function](new_menu_item.me.event_element_data); }() }; <Zyclops> comes up with new_menu_item.met has no properties <khaladan> well yeah <Zyclops> ahh yep <Zyclops> i see my mistake <khaladan> new_menu_item.onclick = function(SOME_ITEM) { return function() { window[call_js_function](SOME_ITEM.me.event_element_data); } } (new_menu_item); <khaladan> see SOME_ITEM and the last part too <khaladan> you're invoking & p***ing a value to an anonymous function that returns an anonymous function that uses that value <khaladan> this is so a new lexical scope is created each time... <Zyclops> haha, now thats a head twister... i'm trying to make it work atm <khaladan> ok good luck! <Zyclops> now it only will call the very first function from the menu <khaladan> paste the line again :) <paste-it> "Zyclops" at 202.6.138.45 pasted "Looks nicer in here" (4 lines) at http://pastebin.bafserv.com/1660 <khaladan> are the .me's being set right? <Zyclops> new_menu_item.me = this; <Zyclops> and that get's set every iteration <khaladan> hmm :( <Zyclops> but call_js_function is the function name that rotates <Zyclops> call_js_function = menu_items_array[i][1]; << iterates through functions in an array <Zyclops> http://wwww.pastebin.com/397271 << our bit's at line 303 <khaladan> functfunction(data) { return function() { window[call_js_function](data); } } (this.data); <Zyclops> basically it calls a differnet js_function for every button they click, and event_element_data is set everytime they click in a particular area <khaladan> yeah.. <khaladan> wanna try what i just pasted? <Zyclops> yeah def <khaladan> err actually <khaladan> i don't think that will work <khaladan> but i think this might: <khaladan> function(o) { return function() { window[call_js_function](o.data); } } (this);
Return to javascript or Go to some related
logs:
football osdev unixboard metal
|
|