« first day (362 days earlier)      last day (4597 days later) » 

1:46 AM
1
Q: Code for the Eratosthenes’ Sieve in JavaScript

RafaelI'm a beginner in Javascript. I found this method kinda tough to get for a beginner like me. But i tried to do my best, and here's what i came up with. Is this a good code regarding performance ? Is there anything wrong with it ? var notPrime = [] ; var prime = [] ; var n = prompt("Enter n: ")...

 
1:58 AM
Dennis MacAlistair Ritchie, creator of "The C Programming Language" and co-creator of UNIX, R.I.P.
 
zirak can u help me with this?
http://stackoverflow.com/questions/7748625/jquery-colorbox-and-js-email-validation-integration
 
3:07 AM
anybody online
 
 
2 hours later…
5:02 AM
Can anybody look at this code, I cant get an onclick swtich alert to work
It keeps telling me "Uncaught TypeError: object is not a function"
 
morning guys, gals and other things
 
mornin
 
morning
 
5:20 AM
@howdy the javascript is run in the onload event, which is its own scope, so your promo function won't be visible to the onclick handler
you're also calling document.alert... which doesn't exist, it's window.alert
 
yeah i found that out by experimenting with window vs document
im kind of confused how the onclick is being run on load?
 
look in the sidebar, under 'choose framework'
it's set to call all your javascript in the onload event
which basically means it's put inside a function, and things are contained inside that function unless you explicitly make them global
you can either change your function line to window.promo = function(){ or change that drop down
 
:S idk jiddle too well. How do I get it off the onload?
if I put this into an actual webpage, what am i doing wrong to keep this from working properly?
 
you also don't need to include html and body tags in the html window
nothing
 
what?
 
5:25 AM
if you put it in an actual webpage without the onload handler it would work unless the rest of the page is crazy
 
:/ it doesnt work when i put it in an actual webpage it gives me an "Uncaught TypeError: object is not a function" on the image tag
 
then something else on the page is messing it up
if i change the dropdown from onload to head, and fix the document.alert then it works fine
 
ohhhh ok I think I understand whats going on then :S
I have an variable named promo thats declaring an array() object, guess I cant name the function the same thing
 
unless they're scoped differently
the way you're doing this is wrong btw
you should never have onclick attributes in your html
 
the way im doing what?
 
5:31 AM
give the element an ID and add the handler in js
 
right 90% of the time I'd go with that, but this is for a class, we haven't hit that chapter in the book yet
that's literally not until chapter 11 in this book and were on 7
:/
 
v.v
I don't like classes that teach you the wrong way first and then fix it later
it's not hard to do it the right way from the start
 
thought I could just use DOM and get image subzero and add the handler that way
though* yeah, it's an online class and it's not that great
 
@david it's not just "not hard"...imo learning the right way is easier than unlearning the wrong way. especially when they don't tell you right off that "there's a much better way to do this; we're just being lazy right now" :P
 
yeah
good old javascript
it's bed time
 
6:17 AM
anyone with idea on how to grab JSON from AJAX file upload with jQuery form plugin?
 
please any body tell me how can i get the value N from this ajax response {"status":"N"}
 
JSON.parse(response).status?
 
yaa thanks :)
 
@aL3xa did you set the dataType to 'JSON' in the options ?
 
hi, i am wondering if anyone could have a look at stackoverflow.com/questions/7737820/… I cant seem to get the plugin I need to work I am also using another plugin to allow sorting of the tables and pagents
 
6:33 AM
yes, but since AJAX uploads are meant to work by targeting response in hidden iframe, I have to wrap the result in `<textarea>` tag O_o
strage... will see how does that work...
@Oddant how do you manage AJAX uploads?
 
0
Q: Js - making sense of timing & conflicting properties

Salman KhanAll, Am using jquery to animate a sliding effect on the li elements. While I have managed to create the sliding effect, it is not being animated correctly. Issue: I think the issue is to with the jquery animation timing, which conflicts with the rest of the code immediately below the jquery ani...

 
@aL3xa well i was using jQuery form plugin too when I tried to upload files in an ajax solution, it worked file, didn't try to get a json object back, just a text/plain and displayed it in a span element
 
@Oddant can you please provide some sample code?
 
0
Q: Js - making sense of timing & conflicting properties

Salman KhanAll, Am using jquery to animate a sliding effect on the li elements. While I have managed to create the sliding effect, it is not being animated correctly. Issue: I think the issue is to with the jquery animation timing, which conflicts with the rest of the code immediately below the jquery ani...

 
$('input[type=submit]', '#myForm').submit(function(e){

  // here goes data formatting (e.g. make sure the email field is correct using RE)

  $(this).ajaxSubmit({
    success : function(data){
      alert(data);
    }
  });

  e.preventDefault();
});
@aL3xa was it helpful ?
 
6:46 AM
@Oddant hm... so if you omit dataType, it will return just plain text right?
*, right?
 
yes
as far as I know
 
hm... lemme see
yeah, it defaults to null
 
ok
 
@Oddant , why would you want to add submit event on the all the submit buttons
 
why not ?
 
6:48 AM
`jConfirm('Continue?', 'Current Maximum Instances', function (ans) {
if (!ans)
return;
else
response = remoteCall(getUrl+'regist/registration.php', str);
}); `
this function is not working
 
@aL3xa Did you look at this one plugin ? valums.com/ajax-upload
 
@Oddant yeah, I even asked the author to release it under MIT license =)
 
@tereško what is your point ?
 
but I didn't use it, since I found it too cumbersome =/
it does everything automatically =/
which I don't like
 
@aL3xa you can only use it as the widget form and strip all the unnecessary code
 
6:52 AM
anybody?
 
I think
@aL3xa ok
 
@Oddant , instead of $('input[type=submit]', '#myForm') you should just have $('#myForm')
 
@Oddant dunno, I'm not into messing with it right now
but anyway, thanx a lot for suggestion and sample code =)
 
Any body here can help me with Json parsing using Jquery
 
6:53 AM
4
Q: How to parse json response and add functions like error,complete to it using JQuery?

Sahil GroverI am working on making a mini app using Json parsing . Output I am getting by hitting url http://localhost:3000/cities.json is as below [ { "id": 1, "name": "Bangalore" }, { "id": 2, "name": "Chandigarh" }, { "id": 3, "name": "Chennai" }, { ...

 
@aL3xa anytime you need help :)
 
why using jquery? JSON.parse(jsonText) will give you an object...one that you don't need jquery to work with
 
@Oddant hahah... I was banging my head, and now I see that I have malformed JSON =) ahahah
 
@tereško yes sounds more logical
 
then ?
 
6:54 AM
@cHao bingo
 
@aL3xa uff !
 
=)
 
I don't like when this happen
..
alright I need to go, see you later
 
@aL3Xa and @chao check my full question
i have tried every way given there
 
@SahilGrover , its long , and it contains invalid json-like data as example
 
6:56 AM
@Oddant blimey, the JSON is valid O_O
now, I hate when this happens! =)
those Alice in Wonderland moments... =)
 
then what is the is valid syntax plz
 
@SahilGrover , that link was for you
there is a big "validate" button
 
@SahilGrover sorry, when I said that JSON is valid, I thought about JSON in my code =/
dunno about yours, however... =/
 
@teresko that says even this code is not valid $.getJSON("localhost:3000/cities.json?&callback=?",
function(data){
alert("hi");
});
 
@SahilGrover Huh?
is that suppose to be vaild JSON ?
 
7:04 AM
he seems extremely confused
 
what u say about this @omeidherat
$(function(){
$.getJSON("http://localhost:3000/cities.json?&callback=?",
function(data){
$.each(data,
function(){
alert("hi");
});
});
})
 
validate the content of http://localhost:3000/cities.json?&callback=?
 
That is JavaScript, not JavaScript Object Notation.
@SahilGrover Yeah what @tereško said
 
and for debugging, please use console.log() or console.dir()
 
validating the content of localhost:3000/cities.json?&callback=? gives
Parse error on line 1:
?([ { "i
^
Expecting '{', '['
 
7:09 AM
then that is the reason why nothing happend
 
means
 
your data source returns an invalid JSON , which channot be parsed
 
but i have been parsing tht already
 
and if it is invalid why it not works for showing error
:(
 
7:12 AM
@SahilGrover this was not in english
 
my concern is to run code not check english :)
 
how can redirect the page when got response from ajax?
 
whats happening ppl
wordpress developer in the house
 
bah.
 
7:14 AM
me asking solution for this stackoverflow.com/questions/7739111/…
but not yet able to get that :(
 
what do you see in JS console when running that script ?
> my concern is to run code not check english :)
well .. if you did , then people could understand you better
 
oh sorry
@chrome Resource interpreted as Script but transferred with MIME type application/json. @firefox no response
 
can you control what comes out of http://localhost:3000/cities.json?&callback=? link ?
 
hmm
i can
its webrick server running at backend
 
then start by making sure that it returns a correct json file
if you are not sure about whats wrong with with current output , paste it somewhere so that we can see it .. like on pastie.org
 
lines 1 and 93 shouldn't be there , in the second file
 
lemme check
 
anybody?
 
ya i changed it
now it would return same in both cases
i.e without 1 and line 93
 
well , now it should work
try something like :
$.getJSON(
   "http://localhost:3000/cities.json?&callback=?",
   function(data){
      console.dir(data);
   }
);
 
7:34 AM
yep
it returned an array
an array of objects which contain objects 1 to .... , every object has id and name of city
thats total json response
now how to add error function to it @teresko
 
what sort of errors are you trying to catch ?
missing file ? (404)
 
hmm
like if there is no response from server
or server it is taking too long to respond
 
this might help
and it is possible to set a timeout on XHR requests
 
hmmm
that was really great of you @teresko ..... can u put an sample code here
say just for 404 page not found
rest i would do by myself
 
just take the example from the same page .. search for "statusCode"
 
7:49 AM
i would try
 
 
2 hours later…
9:35 AM
After reading "prototypes as classes"
I now seem to be using the phrase "class" wrt javascript to mean prototype.
my old self would have shot me for using the phrase "class"
Is it bad to use the phrase "class" wrt javascript?
 
 
2 hours later…
11:18 AM
guys, Im wondering how to get reference to the external CSS file via js?
googling brought about the following:
var myStyle = document.styleSheets[0].cssRules[0].style;
Im not sure what the '.cssRules[0]' does
any insight please
 
document.styleSheets[0]
Is the first CSS file attached to your document
.cssRules[0] is the first CSS rule declaration inside the stylesheet
.style is the style definition inside the rule
 
thanks Raynos
here is what I have builtup:
var dStylesheet = document.styleSheets[0].style
var pBackgroundColorProperty = dStylesheet.eTabInd.children[iActiveNo].backgroundColor;
but the browser doesn't like it
btw, eTabInd is an <li> element
 
"the browser doesn't like it"
 
[iActiveNo] is the counter; the number currently active
 
Modern browsers and old versions of IE
have different stylesheet apis
 
11:31 AM
FF7
Im trying to get & store the background color property of an element
 
The MDN is the reference written by mozilla
So it should work in firefox ;)
The API is quite large so its not a trivial task to learn
 
so does that mean, I have to go through each browser's doc to figure out how to access the stylesheet
that would be a nightmare
 
No
Because all the browsers implement one document, the W3C
Specifically the StyleSheet Interface
However I personally find the w3c standards documents harder to read then the references on the MDN
 
11:38 AM
yes, I agree, the W3c is the best bedside story book for your evil cousins
Im still not finding any reference with example on how to access the stylesheet on MDN
there is the href tag
 
document.styleSheets is an array of stylesheet objects
 
yes
 
.cssRules gives you a CSSRulesList
 
Im trying to build a path to the backGroundColor
 
Then just manipulate that list
 
11:41 AM
maybe Im not thinking correctly
but should the following code (path) that I built, work?
 
var dStylesheet = document.styleSheets[0].style
var pBackgroundColorProperty = dStylesheet.eTabInd.children[iActiveNo].backgroundColor;
 
There is no elegant way of doing that
a stylesheet is a bag of strings
What is eTabInd ?
Maybe you window.computedStyle(Node)
 
ah, now I am getting it
thanks for the cssText Raynos
thats should give the index which I can feed into the cssRulesList
eTabInd is element id
in this case, its <ul>
 
Well that won't work well
 
11:44 AM
iActiveNo is the <li> child that is currently active (index no) in the counter
yes i think I understand now; i.e. the reason it wont work is because Im feeding the HTML div ref. to the CSS query
so in other words, js is having to find the id in CSS file which it won't find
is that right?
 
var style = window.getComputedStyle(document.getElementByid("eTabInd").childNodes[iActiveNo]);
var backgroundColor = style.getPropertyValue("background-color");
Now childNodes is a pain in the ass
even though it may be the correct <li> number
childNodes also contains textNodes. Specifically textNodes containing the \n character.
so childNodes might be [<li>, whitespace, <li>, whitespace, <li>] or [<li>, <li>, <li>]
you need a better way to get, specifically loop over childNodes and ignore any node with nodeType === 3 (text node)
 
awesome...
one moment
 
At this point I could recommend you use a library like jQuery
which makes it easier
$("eTabInd :nth-child(" + iActiveNo + ")").css("background-color")
 
Raynos, why not use children[] instead of childNode?
yes, I could use a loop to ignore the === 3; only count the === 1s
 
I dont know
 
11:52 AM
thank you for the:
var style = window.getComputedStyle(document.getElementByid("eTabInd").childNodes[iActiveNo]‌​);
thats a gem
I didnt know about 'getComputedStyle'
I'd rather avoid jquery if I can
I guess because of my newbieism, I find the syntax of jquery very odd and confusing
 
because children is not in DOM2
it's in DOM4, let me check DOM3
 
oh right
clarify please; DOM is which version of browsers?
 
Not in DOM3 either
Don't know to be honest
 
thats cool
 
modern browsers will support DOM4
IE8 probably wont
IE9 probably wont either
 
11:55 AM
Ive been using children[] in all my code
 
.children works in firefox
 
NO WAY!
let me check IE9
 
Works in chrome
console.log(document.getElementsByTagName("div")[0].children)
There is no good resource for DOM browser compliance apart from the browser support charts on the MDN
Basically cross browser compliance is a really hard problem
That's why everyone uses libraries.
 
yes, my code is not working in IE9
 
You end up writing code like
 
11:58 AM
by library I suppose you will sing praise for Prototype & Jquery?
actually, I haven't checkedout Prototype
so cannot say anything bad about it :)
Im actually super excited about Coffeescript
once am comfortable with js
 
if (el.children) {
  var children = el.children
} else if (el.childNodes) {
  var children = toArray(el.childNodes).filter(function (el) { return el.nodeType === 1; })
}
No
I sing praise for MyLibrary
 
I did see a reference earlier today or was it yesterday in this chat room
but didnt quite pay attention
 
I would also recommend me a dom-shim but thats not ready
 
dom-shim?
sounds very hippy
 
dom-shim will emulate DOM4 in non-compliant browsers
so you basically write code and it works everywhere
because under the hood there is code like
 
12:03 PM
I.NEED.THIS!
 
Object.defineProperty(Element.prototype, "children", {
  configurable: true,
  get: function _get() {
    var arr = toArray(this.childNodes);
    arr = arr.filter(function (el) {
       return this.nodeType === 1;
    });
    return arr;
  }
});
 
so tonight is my 'go back to loving previously divorced childNodes
 
Now .children will just work
Of course .children is probably 100x slower in non-compliant browsers, but meh
 
wow, I need some time just to figure this code out
 
@SalmanKhan : do you know google map?
 
12:05 PM
yes @Ritesh360
 
Well if you dont understand the prototype then its a bit difficult
 
why?
 
i have one issue
i am loading my points on google map using ajax
 
you are torturing me Raynos
 
var div = document.getElementById("id");
console.log(div.doesnotwork); // undefined
Element.prototype.doesnotwork = true;
console.log(div.doesnotwork);
 
12:06 PM
@Rite
 
That vaguely explains the prototype
 
@Ritesh360, you should be asking Raynos the question, Im a newbie
 
but some time that points will not showing on map
 
So all the above code is doing is adding a property .children to all elements. It's defining a get method for it. This getter will filter childNodes of any non-elements and return it
@Ritesh360 I know nothing of google maps
 
cool
off to a meeting
brb 15min
btw, thanks Raynos for all the help
it is awesome
 
12:14 PM
lml
 
12:40 PM
0
Q: create a HTMLCollection

RaynosI'm trying to shim Element.prototype.children which should return a HTMLCollection There is a window.HTMLCollection However var h = new HTMLCollection(); //TypeErrror: HTMLCollection is not a constructor and var h = Object.create(HTMLCollection.prototype); h[0] = div; h.item(0); // Could n...

 
Hi guy's I dnt have knowledge in html. Can anyone suggest me with the best document from basics to complex for learning JQuery.
 
The jQuery documentation, read it
 
can u pls provide the link for it\
I am zero in html...So I am asking for basic document....not very complex
 
jquery.com ¬_¬
follow the documentation link
 
Okay thanq
 
12:45 PM
Dont start with jQuery
Start with MDN Learn
Start with also learning programming
 
Tell me how to start.Actually I am an iphonic app developer I want to learn JQuery ti make the web based apps.
 
Again MDN Learn
 
Okay I will follow as per ur suggestions.
 
and eloquent javascript, if your a good programmer then get the good parts or read the javascript garden
 
Thanq u very much for ur links.
 
12:48 PM
Depends what your aim is
To learn web development
or to use web development as a means to an end
There is a strict balance between learning what you should know and learning only what you need
I cant give recommendations on the latter
 
I want to develop web based iphone apps
U tought me how to start...N I will learn how to end it.. :)
 
thanks @Raynos, cant wait for it to be fully baked ready for use
 
hey can any1 give me some tips on venturing into asp.net and ajax i know most of jquery and javascript...but nothing with actual ajax ...only the other stuff....dom,ui,chaining all the stuff you can do with an .html and .js stuff(you get the point) any books to recommend -> jquery/jscript (ajax) + asp.net (VB)(unless im missing something in jscript)
 
Shudder
ajax isnt hard
you just make http requests
and asp.net is a beast, avoid it
 
thanks for the clarification on ajax....will look into it....why do you say asp.net is a beast?
 
12:55 PM
because asp.net is a huge framework
and its a bad framework
but if you ask me why I will just rant & rage
Not to mention that vb.net <<< c#.net
 
so what do you recommend as a backend language?
 
wow that looks really familiar to js
 
node is js
 
node is an IO library for js.
 

« first day (362 days earlier)      last day (4597 days later) »