Jump to content

Hadien

Members
  • Posts

    247
  • Joined

  • Last visited

Everything posted by Hadien

  1. first off: out_edit_item_pic1.innerHTML = code working; doesn't work because "code working" wasn't in quotes so it not seen as a string. As for. out_edit_item_pic1.innerHTML = '<img src="../images/items/'.theitemid.'/pic1.jpg" width="200px" border="0" />'; you're using php's string concatenation in javascript. use a '+' not '.'. also try to define a height
  2. I don't know regex sub patterns too well so I'm not sure if this will give you exactly what you've wanted. it should count the 1st 292 words and store them in $words[0], while the rest of the text will be stored in $words[1] (if the text has more than 292 words, otherwise the whole text will be in $words[0]). $wordcount = preg_match_all('/((?:s*w){292})(.*)/g',$rows['decision']),$words);if($wordcount !== false){ $section = $words[0]; if($wordcount >292){ $section .= " read more..."; }}else{ //error happened in pattern matching}
  3. you're close... when you've created inner, it is an empty array, a length of 0. if you try to add elements via inner[j] = j. you'll most likey add the element, but the Array instance won't properly update itself to reflect it (length likely won't increase, and its possible iterator functions in Array will likely not work). I haven't checked exactly what happens if you do this, but i'm certain it'll give you behavior you don't want, and likely cause array-out-of-bounds errors down the line. you had the right idea about pushing into events. also reinitialize inner inside the outer for loop, or all 8 elements in events will refer to the exact same inner array, which would have 16 elements (if using push). var events = [];var output = "events[inner[]]:";for (var i=0 ; i<8 ; i++){ var inner = [];// instantiate inside outer loop for (var j=0 ; j<2 ; j++){ inner.push(j); //or inner[j] = j; } events.push(inner); output+="nt["+i+"]: [["+inner.join("], [")+"]]";}console.log(output);/*prints the following:events[inner[]]: [0]: [[0], [1]] [1]: [[0], [1]] [2]: [[0], [1]] [3]: [[0], [1]] [4]: [[0], [1]] [5]: [[0], [1]] [6]: [[0], [1]] [7]: [[0], [1]]*/ the reason my 2nd example,"another way" works is because i first gave events array a preset size of 2 elements (each element initialize to undefined). so events[0] and events[1] are still inbounds of what the Array constructor already allocated for events. EDIT: bah, I've mixed up languages, inner[j]=j; is valid and safe code. but you do need to reinitialize inner inside the outer loop to get what you want
  4. works fine for me, and all i had to do was add some <html> tags.
  5. if its not directly obvious, whats happening is that all those separate icons are actually clumped together in just one image, and its using css to only show a small part of the entire image, like so: when you would hover over the link (via a:hover) the css would change to the position to look at to give the new icon look. having all the icons all collected into one image saves a lot of overhead, since the browser only needs to download just one image, and not like 70. also, the hover states will come pre-loaded too. if each state was in it's own image, the browser won't request for a state's image until its actually needed, which seems like an optimization, but can cause little interactive quirks from time to time. for example, depending on how you've set up the css, when you hover over a link the background may not appear to change for a second or so. or even worse you might see a broken image for moment which can defeat the immersion.
  6. I haven't used PHP in like a couple years either, but actually you should almost never need to use echo; only time I would use echo is if I'm accumulating all text to go on the page into a single variable so that i can continually mess with the data before actually sending any HTML headers. I can also run $Tidy->clean($html) before actually sending anything. most other times i would use a shorthand echo like <span> Welcome, <?= $username;?></span> but I don't count that as a true echo. jimfrog, the php code is valid, but you're echoing inside js code so the browser thinks its javascript code and not plaintext/html. it sees this: <script> function doOnLoad(){ document.write('hi'); john } doOnLoad(); </script> it thinks you're referring to a variable 'john', but not doing anything with it. and it sees the variable as undefined (its still valid code, so no error). the code in post 21 works because the jQuery that written there is written INSIDE the php curly brackets. if the isset($_SESSION[]) is false, php will skip all that jQuery code and jump to the closing curly bracket after in PHP, then continue on as usual. and as such the jQuery code wouldn't be added to the page.
  7. creating multidimensional arrays is simple, especially with the shorthand syntax: var events = [];events.push(['ddddddd','eeeeeee']);events.push(['fffffff','ggggggg']);//another wayvar events = new Array(2);events[0] = [].push('ddddddd','eeeeeee');events[1] = [].push('fffffff','ggggggg');//or just do thisvar events = [ ['ddddddd', 'eeeeeee'], ['fffffff', 'ggggggg'] ]; push is an instance method, not a constructor method if you run "Array.push()" its not going to understand what you're talking about. but "(new Array).push()" makes sense to it since you first created an empty array instance and then started to push it. Everything defined in an Array's prototype is an instance method/property which instances will have access to, but the constructor doesn't and vice versa (at least not directly).
  8. Did you remember to start the session? http://www.w3schools.com/php/php_sessions.asp without explicitly calling session_start(), php may attempt to auto-start a session, but may pass in the wrong session ID/Name (shouldn't happen but you never know). you could also experience a session deadlock if a certain user might access the more than once per request (once in a main page and maybe another in an iframe, or if a user has two pages open and one page is loading very slowly). php only allows one page to play with a Session variables at a time. once a page is done changing the session, run session_write_close(); which will allow other pages access to the session even if the original page using it is still loading.
  9. have php add it in conditionally <script> function doOnLoad(){ doThis(); doThat();<?php if(isset($_SESSION['formverified']){ unset($_SESSION['formverified']); ?> //this section of code will be added ONLY if the php finds that SESSION variable $('#confirm') .reveal({//the modal fires here animation:'fade', animationspeed:600, closeonbackroundclick:true }); <?php } ?> maybeDoThisToo(); } </script> in your "form_validation.php" (or whatever you've called it) you'll set the $_SESSION variable before calling header() to redirect to the actual page. when profile.php first sees it, it'll see that theres a session variable 'formverified' and then just add some javascript to the page along with the rest of your javascript. it'll then delete the session variable so if the user refreshes, profile.php will run the check again but won't see any SESSION variable and thus skip adding in that code. javascript doesn't have to mess with any cookies, in fact it's totally unaware that it's being messed with
  10. It seems that when you try to move the popup again that we forgot to consider where the popup is currently at (its starting left and top). The first time you move the popup theres no apparent problem since the popup's left and top values are initially set (rather assumed) to 0. So to fix this, the mousedown fuction also needs to consider the current top and left attributes before dragging. function mousedown(e){ e.stopPropagation(); var d = document.getElementById('dvpopupctl').style; dragflag.move = true; dragflag.offsetX = e.clientX-(" "+d.left).replace(/D/gi,""); dragflag.offsetY = e.clientY-(" "+d.top).replace(/D/gi,"");} since top and left will be a string with numbers and "px" appended to it after the first time through, we need to perform a regular expression that will remove any and all non-number characters. The '" "+' is to ensure that if d.left or d.top are not strings going into the function, that they are transformed into strings before running the string function replace and thus not causing an error. give that a try and see how it works for you
  11. I couldn't find anything wrong with any image in a table per se. but I did see a rather odd graphical glitch in div#footer in Opera. for some reason the background color and image would also render 1 pixel outside the border area (increase the border to something like 5px and change the background-color for body to black to make it more noticeable). changing various styles for the div and the table wouldn't seem to fix it. except for adding a border-radius on #footer with just a single pixel would correct it. pretty odd, and not sure if thats what s/he was talking about.
  12. the "id" which you've passed is just a string. its not a DOM element object and as such, it doesn't have the properties selectedIndex or options. You can also change the onclick event to onclick="SetTF(this)" as another option. Since the element you want to work on is the very same element thats calling the event, you can use "this". The 1st alert won't show what you've expected but the rest of the function should work flawlessly. If you're using a diagnostic, start playing with the console object for debugging. console.dir(id) should let you see everything that the variable id had in it. it would've quickly helped you find out that id was just a string.
  13. first off, I should say that you shouldn't use tables to design a page layout. Tables are meant for tabular data, not this, which is one of the reasons this is giving you such a hard time. now to answer your questions. 1. Its messy (since you can't use fluid sizes), but you can make the content row scroll on your screen. <div class="container"> <div class="scroller"> <table class="page"> ... </table> </div></div> div.container { position:relative; padding-top: /*amount of vertical pixels head and navigation take up*/; padding-bottom: /*amount of vertical pixels footer takes up*/;}div.scroller{ overflow: hidden; height: 100%;}tr.head, tr.navigation, tr.footer{ position: absolute;}tr.head{top:0px;}tr.navigation{top:/*amount of vertical pixels head takes up*/}tr.footer(bottom:0px;} you'll need to figure out the pixel values for the commented sections in the CSS. This should work for you but do know that its very inflexible, the nature of using tables for layouts. It will break if someone tries to use accessibility functions like ctrl+ to zoom in or other similar operations. 2. technically, barring extra contraints, almost any element in html can be made scrollable. usually, however only elements that naturally have display:block become scrollable. 3. its possible, though it'll require a lot of work. I would start off with a pre tag, and overlay that with an invisible textarea tag (position: absolute; opacity:0;). Add a onkeyup event listener to the textarea to have it string.escape(this is important!) it's value, then perform string.replace() to wrap reserved words in span tags with appropriate classes, and then pass that string to the pre tag's innerHTML. it should be stressed when you create an online editor (well... when you use any textfield) that you escape the string, not only in javascript but at least in php, if php or your database were to process it. if someone were to type in "</textarea><script>...",they could immediately start messing with webpage itself (XSS javascript isn't immediately dangerous to your website, but its nonetheless unwanted and is usually the herald of worse things to come). Its not funny the first time when you come across the username: 'jeff";DROP ALL TABLES;' (of course another good measure is to prevent the majority of database privileges from the users)
  14. Php is the one doing the verification and the redirect, so have php conditionally (by looking at a variable in the POST request) and directly add some extra javascript which will command it to create the modal onload.
  15. //shuffles the array recursivelyfunction shuffleArray_r(list){ //recursive breaker if (list.length == 0) return list; //copy to new array so that the original list isn't affected list = [].concat(list); var newlist = list.splice(Math.floor(Math.random()*(list.length)),1); return newlist.concat(shuffleArray_r(list));}var myoldlist = [1,2,3,4,5];var mynewlist = shuffleArray_r(myoldlist);
  16. Hadien

    W3Schools.com

    with ECMAScript 5th edition, thats not fully true anymore. what about "hasOwnProperty","defineProperties", "create", etc.?
  17. Hadien

    Object.name?

    Getting the name of the Object's type is trivial. Getting a variable's identifier is a nightmare even more so inside closures. You can't reliably find the variable identifier (objects don't naturally store them) because you could have 0, 1, or even 1,000 variables referencing the same object. it would be both difficult (sometimes impossible) and unnecessary for an object to figure out which variable(s) is currently referencing it. Primitives however only have one reference variable (but since they are primitives they don't actually store any metadata about themselves just the data), if you make another variable point to a primitive, the data is copied to a new address, it doesn't reference to the exact same primitive, unlike how its done with the more advanced data structures. if you want to find the name of an Object, refer to it's constructor.name //for functions/classes/constructorsalert("Array's name is: "+Array.name);//says "Array's name is: Array"//for instancesvar arr = []alert("arr name is: "+arr.constructor.name);//says "arr name is: Array" A function's name can't be overloaded or overwritten, its a read-only attribute. anonymous functions will have an empty string and you can't change it to something meaningful after it's defined. something I didn't particularly like when I was trying to write dynamic constructors. but understandably it prevents a lot of unstable code if inexperienced programmers (or hackers) could change it on the fly. if you want the actual identifier, then use objects and key-value pairs, thats really the only way. Ingolme's post is essentially this case but on the global scale, but won't work for varibles defined in different scopes (inside functions) and closures EDIT: if you want an extremely bad way in reliably finding the variable identifier you can write a function that throws an error, catches it and use a regex on it's stack trace to find the 3rd line in the stack, loads up the file as a nonJS/html file and reads that line and parses out everything on that line except arguments in the function and returns an array of strings listing the identifiers that were passed in. then just call that function in any situation when you need to know the actual identifiers that were passed in... of course, I'm merely spouting crazy talk.
  18. only 2 foreseeable reasons why that could happen, the event object wasn't passed into the function via 'e', or you're using IE 8 or below. when an event is triggered there are 3 directly available local variables (maybe more in other browsers and frameworks): arguments - the common arguments variable that every function has access to. event - this has the event object you want to use, which has the stopPropagation and the client/page coordinates. this - refers to the dom element that is currently firing the event reading the html you posted at the top, you should be passing in the 'event' variable directly into your event handlers. add a console.dir(e) inside your functions to see if they are really getting the event object (then look in the browser's debugger to see the console). as for IE8 and below, you can degrade gracefully by checking if the event has the function, then run it. and just unconditionally return false (which should also stop propagation, but will also prevent default actions too) if(e.stopPropagation) e.stopPropagation()//add middle code here//after everything else is donereturn false;
  19. var dragflag = { move:false, offsetX:0, offsetY:0}function mousedown(e){ e.stopPropagation(); dragflag.move = true; dragflag.offsetX = e.clientX; dragflag.offsetY = e.clientY;}function mousemove(e){ e.stopPropagation(); if(!dragflag.move) return true; var d = document.getElementById('dvpopupctl').style; d.left = e.pageX-dragflag.offsetX +"px"; d.top = e.pageY-dragflag.offsetY +"px";}function mouseup(e){ e.stopPropagation(); dragflag.move = false; dragflag.offsetX = 0; dragflag.offsetY = 0;} added an offset so that when you begin to drag the div it won't snap it's top-left corner to the cursor
  20. if you're still using this inside the hover event you don't even have to access the id (even though having 2 different elements use the same id is bad enough and that's the main reason it's not working), you're pretty much breaking the wheel so that you can reinvent it $("a div").hover( function(){ $("pre.green",this).show(); }, function(){ $("pre.green",this).hide(); }); in this example i'm using the $(selector,context) format and "this" is referring to the element that is firing the hover event. so it will only look for the pre tags inside that hovered div which have the green class. you might need to use stopPropagation(so that it won't bubble up and out to snag other pre.green tags ), but i can't recall for hover.
  21. //parses "42 2013" to find 42nd week in the year 2013,// then sees if that week is the last week in the monthfunction isLastWeekInMonth($string){ list($week,$year)=split(" ",$string); $start = "January 1st, $year"; $now = "$start +$week weeks"; $next = "$start +".($week+1)." weeks"; return Date('n',strtotime($now)) != Date('n',strtotime($next)); }function isLastWeekInQuarter($string){ list($week,$year)=split(" ",$string); $start = "January 1st, $year"; $now = "$start +$week weeks"; $next = "$start +".($week+1)." weeks"; return (Date('n',strtotime($now)) != Date('n',strtotime($next) && intval(Date('n',strtotime($next)))%3==1) } I don't have access to a php server atm so i can't even try to test this. not sure how strtotime would handle a combination of date and relative formats so I'm not sure it would work.
  22. $isLastWeekInMonth = (date("m") != date("m",strtotime('+1 week')));
  23. Hadien

    Center page

    then you want to separate the page into 2 divs. the 1st div will have the nav and will have, say width:25%, height:100%, and position:fixed, the 2nd div will have all the rest of the stuff on the page and will have width: 75%, position:relative, and left:25%. then you can use margins and stuff inside that div to center and align content for the right section of the page.
  24. you can use the html5 audio tag, it allows looping <audio controls loop autoplay> <source src="assets/audio/music.mp3" type="audio/mpeg">Your browser does not support the audio element.</audio> do you need xml?
  25. the columns in the tbody don't match the columns in thead because you gave them display:block. While doing so allows you to scroll, the tbody's connection with thead has been severed and as a result the entire width of the body was set to the width of the 1st column on thead. another option is to restore thead and tbody's display to default and instead use position:relative+absolute. Simply using relative+absolute on the table+thead/tbody will work at first,but since you can't control the height of tbody this way (the css will more or less be ignored) it won't scroll as you please. so instead of setting relative+absolute on the table itself, use 2 wrapping divs. <div class="scrollableTable"> <div class="scrollableArea"> <table> <thead></thead> <tbody></tbody> </table> </div></div>.scrollbleTable{position:relativepadding-top:6.5em;/*static height for thead*/ }.scrollableTable .scrollableArea{overflow:autoheight: 400px; /*how much scrollable height you want tbody to show*//*you might want to add a width slightly wider than tbody, scrollbars will offset the columns otherwise*/}.scrollableTable thead{position':absolute;top:0} thead should still be connected to tbody so column widths shouldn't get demolished. and thead will fill up the top padding of .scrollableTable. tbody, and the rest of the table will inherit scrollableArea so that it remains scrollable, yet you can also set the height of the veiwable scroll area by changing scrollableArea's height. see if that works for you.
×
×
  • Create New...