Jump to content

Hadien

Members
  • Posts

    247
  • Joined

  • Last visited

Everything posted by Hadien

  1. javascript: <script type="text/javascript"> window.scrollBy(1500,1500);</script> place that inside the <head> tag, preferbly right after the link to your stylesheet with the window's dimensions. If I'm right you want that to run immediately before the page even fully loads so you don't want it in an onload event.
  2. If you mean you still need the session variables in the same request, then add it right after you done messing with it "in that request". session_write_close doesn't delete the session or it's contents, it tells PHP that the page that accessed it is "done playing with it" so that other pages can use it. PHP only allows one page to work on specific session data at a time and locks other pages out of it (forcing them to wait in a sort of queue), at least it should. what you're getting is possibly a deadlock situation were changes in one page request is affecting some other, different page request before both requests even finish. $(function(){}) runs the function immediately. People write it inside "$()" so that the function will run only once (never more) and doesn't pollute the global space. Use "$(document).ready(function(){})" for code that you want to run as soon as the DOM is ready. Also, in php I used to accumulate HTML code into Heredoc syntax or something similar and then echo the result at the end, just so the server can process everything (or at least the essential things) before even sending anything to the browser. Since then I moved to MVC Frameworks like Zend where I didn't need to worry about such things.
  3. isn't all javascript basically a (oversimplified) flow chart of this? ​ Start Yes | -------------------------| | | | |<--------------------<------------ _______|_______ | | | | / _______v_________ ____v______ | | / Was the No | You are likely | / Has any | | Developer /------>| confused | / event ____________| | No Console open? / |_________________| triggered? / No | _____________/ | ___________/ ___|____ ^ | | / | | | ______________ / Did an __|__ | Yes | | | / uncaught Yes | | v ------>| Run Handler |---> error get /-------->| Die | End |______________| thrown? / |_____| ________/
  4. By default in jQuery, they force the "this" reference to refer to the element that triggered the event handler so inside the event handler just use "$(this)" to grab the button that was clicked $("input['type=submit']").click(function(){ $(this).prop('disabled', true) .val("wait");});
  5. I remember, quite vaguely, what you wanted to do with this, very vaguely... Not sure exactly what you've intended to have done but I've written up my own version. In any case like before, I think you're trying to over complicate things with an excessive amount of redundant inputs. http://jsfiddle.net/7NNvX/ take a look at my attempt at your problem, I removed a lot of redundant code and moved away from the confusing table setup you had. Again its a little difficult to solve your problem, however, as I'm unsure exactly what you want.
  6. when the length is zero, the while loop never runs in the first place but when $I is actually less than the length of SelField the while loop runs (which is why its not breaking when the length is 0). the reason why SelField.remove($I) is breaking (and is VERY likely throwing an error, check the console) is because $I is an invalid parameter. remove() expects an actual element that SelField contains, in this case an option or optgroup element, and $I is NOT an element but a simple number. also I'm sure remove() is not the function you want. remove() will destroy the option, making it no longer exist and you unable to reselect or view it. You'll want to change SelField.selectedIndex, as that is what's used to point to a specific option. one more thing, while $I is actually a valid identifier, you should avoid writing it as such. At 1st, I thought you were writing PHP. And don't forget to include a var keyword. it'd be bad if you somehow had some other $I in some outer scope now or in the future and this small loop messed it all up. the var keyword will imply that this $I is unique only to this scope and does not affect any other $I that is possibly written in an encompassing scope.
  7. it looks like you're putting the entire document ready inside the mysql_fetch_array loop so every time its iterating over a country, its writing an extra document ready handler and writing a completely new var cities which is overwriting the previous (which is why you're only getting the last one). you could change the while loop to... $cities = "";$data = mysql_query("SELECT country FROM countries");while($info = mysql_fetch_row($data)){ $cities .= $info[0].',';}?>$(document).ready(function(){ var cities = <?=$cities;?>.split(',');...continued code... This should solve your problem where only the last country is appearing. Theres likely a better way to transfer arrays from php to javascript however...
  8. you can use CSS to set #img_src13{display:none;} to hide the img tag, then switch the onclick handler to the document.ready handler so that the canvas loads automatically when the page's DOM is "ready".
  9. Hadien

    video length

    back in my editing days using Xvid compression with 640x480 resolution, I would average about 20 mb a minute, more if I really worried about visual quality. nowadays video compression has improved a step or two, yet the average resolution has increased as well, I would probably guess 30-40 mb a minute at current standards, yet I wouldn't know for sure since I haven't produced a video in a long while.
  10. Use javascript closures. when you want to use a variable from one scope in another closures are pretty much the only way (there are other ways but they get messy, ugly, and are usually bad practice) function addToList(newID, oldID){ var newer = document.getElementById(newID); var older = document.getElementById(oldID); newer.innerHTML = older.innerHTML; newer.classname = "newclass" newer.onclick = function(){ removeFromList(newID); }}function removeFromList(newID){ alert(newID);} you define a wrapper function "inside" the same scope that newID is defined. Since this function can see all the variables in the addToList, it will know about the "newID" even inside the wrapper. Javascript closures aren't about wrapper functions, but its why wrapper functions like this work.
  11. also note that, unless the function "view_lead_save_field" actually returns a function, that edit button won't do anything when you click it. I assume you'll want it written like this: edit_btn.onclick= function(){ view_lead_save_field(json_param); }; so that it'll run "view_lead_save_field" itself whenever you click the edit button, and not whatever "view_lead_save_field" returns every time you click the edit button. this will also allow the scope (so that it knows what "json_param" is every time you click) to be properly preserved.
  12. to find the key that is pressed use something like this: var key = event.key || event.keyCode || event.which;alert(key); event.key seems to be the upcoming standard way of getting the key, but hasn't been implemented as of yet. keyCode and which are the current recommendations of grabbing the character, yet they are slated to be depreciated and won't be recommended soon. the code I show here "should" give you the right property regardless of version or platform.
  13. using javascript to change the selectedIndex of select element does not cause it to fire the onchange event. you need to manually change the color. <body> <form> <input type="reset" class="resetButton" /> <select id="colors"> <option value="white"></option> <option value="red">AB</option> <option value="blue">BC</option> <option value="green">CD</option> <option value="orange">DE</option> </select> </form> <script> $('document').ready(function(){ $("#colors").change(function(){ $(this).css({"background-color":$(this).val()}); }); $('.resetButton').click(function(){ $("#colors").val("white").change(); }); }); </script></body>here I wrote it sticking closer to jquery own functions
  14. jQuery would simply apply the html to all of them. $() almost always returns a collection object even if there was only one element found. and most query functions would apply their effects to all elements in that collection. but you are right, he is overwriting the previous options and the last option would only appear. you can try this $(document).ready(function(){ var timeslots=["08:00","08:30","09:00","09:30","10:00"]; var drop = $(".drop"); for (var i=0; i<timeslots.length; i++) { drop.append( $("<option>").val(timeslots[i]) .text(timeslots[i]) ); } });
  15. Hadien

    Forum Issues?

    Hooray! site seems to be functioning! (that or I'm looking at a cached CSS, which if so i'm not messing with)
  16. There is basically 2 types of elements in HTML. block elements and flow elements. block elements can have pre-defined dimensions and will fully occupy a single row. Flow elements can have font sizes, alignment and other properties specific to text, plus multiple flow elements can exist on a single row. Block elements can contain block and/or flow elements, but flow elements can only contain other flow elements. the <p> tag is the rare exception where as a block element, it can only contain flow elements, and the <br> tag is a block element. You could manually write in a <br> in a <p> tag, but it wouldn't be valid html. so if you press enter, you should leave one paragraph tag and start a new one. If you would press enter again a br tag should automatically be added in-between the two p tags (if memory serves...)
  17. I am sorry, but I couldn't understand what you were trying to say in that post. Perhaps if you wrote in steps with simple sentences what you do to the program then what you expect the program to do like i describe below. 1). User: Select MAIN-GROUP and COUNTRY radio buttons. Program: Display select boxes for MAIN-GROUP and COUNTRY. 2). User: Select option in COUNTRY select menu. Program: Update COUNTRY select menu to the selected option. 3). User: Select STATE radio buton. Program: Hide COUNTRY select menu. Prevent user the ability to reselect the COUNTRY menu Display select menu for STATE.
  18. you misspelled 'createLink'. you also need to make sure designMode is turned on. and while its on, events won't work in the current document, so you'll have to resort to using iframes. Or turn designMode on (inside the event call) to make the change and then turn it back off afterwards.
  19. When you're calling view(), it creates a setInterval that calls itself 1.2 seconds later. then at that time the 1st setInterval would call view again and a NEW setInterval on the view method would be called. at 2.4 seconds view runs twice and creates 2 more setIntervals. at 12 seconds theres over 1,000 setIntervals registered and view is running 1,024 times in that 1.2 second window. if another 12 seconds goes by it would have to run view() more than a million times…..in a second... which if it falls behind stacks up really quickly. You need to be EXTRA careful when you're having setTimeout and setInterval recursively call the function they are in. Honestly though, that applies to recursive functions in general. remove setInterval from the view function and just put it directly in the onclick.
  20. Hadien

    if(!var_name)

    whats happening is that the if() syntax is casting timer_is_on from a number to a boolean. any number other than 0 is considered true. the "!" is a not operator so when javascript sees "if(!timer_is_on)", its roughly translating to "if timer_is_on is NOT 0, then do this stuff" its important that the function made that check so that it didn't make multiple setTimeout function calls. if it did then the id of the previous setTimeout would be lost, overwritten with the new setTimeout function. If that happened then there would be no way to use clearTimeout on the first setTimeout. actually…. after calling stopCount, one of the setTimeouts would clear and then you would be able to stop the 2nd timeout after its made a count, however, that wouldn't be desired functionality and would be confusing.
  21. 1).Not sure if that's just the forum minifying the url, but its not valid on my end. Make sure its loading correctly on your end. 2).Sorry that should have been "toggleClass()" not "toggle()". 3). The ">" is basically a "direct descendant" selector. for example "body>p" would affect the <p> tag in: <body> <p></p></body> because the p tag is a direct descendant of the body, it is the body's child. however this <p> tag: <body> <div> <p></p> </div></body> is not affected as its not the DIRECT descendant of the body, but more of a grandchild. and that is the biggest, and well only, difference between the two selectors ".hidden>p" and ".hidden p". 4). If you want for them to begin hidden then have the divs start with the class="hidden" and change the button text to show <div class="hidden"> <p></p> <button class="collapsible">show</button></div>
  22. here is my complete file. I've made very minor changes since my last post, but nothing too major: <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>slot machine</title> <style type="text/css"> .slot{ display:inline-block; position: relative; height: 200px; width: 200px; overflow:hidden; } .slot>div{ position: absolute; height: 150px; width: 200px; } .red{background-color:red;} .green{background-color:green;} .blue{background-color:blue;} </style> </head> <body> <div id="slotMachine" style="clear:both;"></div> <button onclick="sl.roll()">spin</button> <script type="text/javascript">function slot(element,symbols){ if(!(this instanceof slot)) return new slot(element,symbols); //variables you see with a "_" prefix are intended to be used // internally. you could use them publicly but you shouldn't // need to... this.slot = element; this._intervalID = null; this._rollspeed = 75; this._rollDuration = 50;//20 frames/second; this.rolling = false; this.current = null; this.slot.innerHTML = ""; //populate the slot for(var sym = symbols.slice();sym.length>0;){ this.slot.appendChild(document.createElement("div")); this.slot.lastElementChild.className = sym.splice(Math.round(Math.random()*(sym.length-1)),1) } this._slotHeight = parseInt(getComputedStyle(this.slot) .getPropertyValue("height")); this._symbolHeight = parseInt(getComputedStyle(this.slot.firstElementChild) .getPropertyValue("height")); this._origin = Math.floor((this._slotHeight-this._symbolHeight)/2); //the origin is where the "current" element will start and stop at, // this is so the slots will properly line up in the end for(var i = this.slot.firstElementChild; i!=null; i = i.nextElementSibling){ i.style.top =(i.previousElementSibling == null) ? this._origin - this._symbolHeight+"px" :parseInt(i.previousElementSibling.style.top) + this._symbolHeight + "px"; if(i.style.top ==this._origin) this.current = i; }};slot.prototype.roll = function roll(){ clearInterval(this._intervalID) this._intervalID = null; var rollControl = function(self){ for(var iter = self.slot.firstElementChild; iter!=null; iter = iter.nextElementSibling){ iter.style.top = (parseInt(iter.style.top) + self._rollspeed + self._symbolHeight) %(self.slot.children.length*self._symbolHeight) - self._symbolHeight + "px"; } }; this._intervalID = setInterval(rollControl,this._rollDuration,this); this.rolling = true; }slot.prototype.stop= function stop(callback){ //if the slot isn't rolling do nothing. if(!this.rolling) return; var currentSpeed = this._rollspeed; var finalSpeed = false; var slowroll = function slowroll(self){ if(!self.rolling){ clearInterval(self._intervalID); self._intervalID = null; return callback(); } for(var iter = self.slot.firstElementChild; iter!=null; iter = iter.nextElementSibling){ var pos = parseInt(iter.style.top) finalSpeed |= currentSpeed<=10 && pos>self._origin-self._symbolHeight/5 && pos<self._origin; iter.style.top = (pos + currentSpeed +self._symbolHeight) %(self.slot.children.length*self._symbolHeight) - self._symbolHeight + "px"; self.rolling &= parseInt(iter.style.top) != self._origin || !finalSpeed; if(!self.rolling &&parseInt(iter.style.top) == self._origin){ self.current = iter; } } //the current speed will slow down, on each pass, to 5. // when a symbol nears the origin on the final pass, it will // decellerate faster down to a speed of 1. currentSpeed = finalSpeed ?Math.max(1,Math.floor(currentSpeed*.5)) :Math.max(4,Math.floor(self._symbolHeight/25), Math.floor(currentSpeed*.95)); } //change the linear rolling animation to a roll that slows to a stop. var changeroll = function changeroll(self){ clearInterval(self._intervalID); self._intervalID = setInterval(slowroll,self._rollDuration,self) } // add a short random delay between .75 and 1.25 seconds on when // the slowdown should begin setTimeout(changeroll,Math.floor(Math.random()*500)+750,this); }function slotMachine(element, slotscount, symbols){ if(!(this instanceof slotMachine)) return new slotMachine(element,slotscount,symbols); //default number of slots to 3 this.machine = element; slotscount = parseInt(slotscount) || 3; this.slots = []; this._intervalID = null; this.machine.innerHTML = ""; for(var i = 0;i<slotscount;i++){ var s = document.createElement("div"); s.className = "slot"; this.machine.appendChild(s); this.slots[i] =slot(s,symbols); } } slotMachine.prototype.matches = function matches(){ if(this.slots.length<1) return false; var check = this.slots[0].current.className var match = function match(e,i,a){ var pass = e.current.className == check; e.current=null; return pass; } //does the current symbol in each slot match? if(this.slots.every(match)){ alert("match!"); } } slotMachine.prototype.roll = function roll(){ clearTimeout(this._intervalID) this._intervalID = null; for(var i=0;i<this.slots.length;i++){ this.slots[i].roll(); } this._intervalID = setTimeout(this.stop,1000+Math.floor(Math.random()*500),this) } slotMachine.prototype.stop = function stop(self){ self = (this instanceof slotMachine) ?this :self; clearTimeout(self._intervalID) self._intervalID = null; var index = 0; var dominoStop = function dominoStop(){ if(index==self.slots.length) return self.matches(); self.slots[index++].stop(dominoStop) } self.slots[index++].stop(dominoStop); }var sl = new slotMachine(document.getElementById("slotMachine"),3,["red","red","green","blue","blue","blue"]); </script> </body></html>
  23. <noscript> is considered "depreciated" in XHTML's eyes, however "XHTML 1.0 Transitional" will allow depreciated elements. That's why it still works. aside from supporting more elements,transitional is still like strict XHTML, in that it still requires that you follow all the clean coding practices (properly nested tags, all lowercase, etc.)
  24. looking at your fiddle there are a couple things that can be cleared up. JSfiddle doesn't make this initally apparent but when you select "onLoad" from that dropdown on the left side it wraps all that code you wrote in that javascript block into a single function and sets it to window.onload. you then wrote a '<body onload="setBookmark()">' tag in the html... which 1). you didn't need to do as JSfiddle automatically puts in a body tag, and 2). Likely overwrote everything you had in that javascript block (because you chose the onLoad setting). Choosing "no wrap - in <head>" or "no wrap - in <body>" is more straightforward to understand as then it'll directly insert the code you wrote in its own <script> tag in either the head or body. further more, I went in to clean up the code you got in your jsfiddle.net/5fQsn/8/ and fixed to the desired functionality; well, I rewrote all your code. The anchor tags where unnecessary, I moved all the inline css into the external sheet, and overhauled your javascript. Personally, if its possible, I like to only call the "document.getElementById" and simliar functions the least amount of times (perferbly only once). if an element won't deleted and is likely to be called upon multiple times, then theres use in remember that element instead of always trying to refind it again. Also I like to make sure that the code I write has the smallest impact in global space.If you've ever looked at the window object, you'd see there is tons of variables available in global space. and the more variables there are in a scope, the more likely that some variables might get overwritten unintentionally. For example if you have a "var i;" thats being used by one piece of code, then later come in and write some other piece of code for something totally different and use var i again you might break both code sections. plus anyone else coming in (or even yourself after not looking at the code for a long time) might see that variable and would have absolutely no idea whats it for. so what I do is create an object (in this example "bookmarks") and everything that has to do with it will be a property of that object. so when you see code like bookmarks.reset(), right-off-the-bat you know that reset function is for resetting bookmarks and not something else like form.reset(). and the global space doesn't see 20 some odd variables, just "bookmarks" which leads to a far less chance of accidental variable name collision.
  25. hiding a selection doesn't make it forget what option you've selected for that select tag. style.display only affects the visual presentation of the object. your browser will still remember what you chose even if you hide it like that. I rewrote your code in this fiddle with a little cleaner html and javascript
×
×
  • Create New...