Jump to content

joe92

Members
  • Posts

    304
  • Joined

  • Last visited

Everything posted by joe92

  1. That's a good point, one that I should have remembered to mention. http://lawrence.ecorp.net/inet/samples/js-getelementsbyclassname.shtml The one in the link above works like a charm. Joe
  2. var a = document.getElementsById('totalpayment'); //it's getElementById, notice the lack of s var b = document.getElementsById('netpay'); This is invalid. You cannot grab multiple elements by ID. What you need to use is getElementsByClassName and attach the relevant class to the elements you wish to check. Hope that helps you, Joe
  3. Ditto. Hopefully JavaScript will do the same in reverse and make a few of its language constructs more like php... Ah, one can dream.
  4. Are you trying to match for the '12 Oz Bottle' and replace the spaces at the same time? If so, this thread that I created a while ago will give you a huge helping hand. If not - and you already have the string, you just need to replace the spaces into underscores - then gizmola already solved that one for you Joe
  5. I know this is solved but I thought I would give my tuppence worth. You could have used \W to match anything that is not a word character. Just remember this, all the shorthand regex tricks you know, \w \d \s etc etc., they all have exact opposites which are there uppercase versions. I.e.: \W = Match any character that is not a word character \D = Match any character that is not a digit \S = Match any character that is not a white space character etc etc. Make those letters lower case and you need only to remove the word not from the definitions to find they work. Furthermore, you also amusingly almost posted a regex which needed extremely little tweaking to have worked. You were just missing the vital ^ character. Placed within a character class it means match anything that is not the following characters. So you're regex, [a-zA-Z0-9], needed only become, [^a-zA-Z0-9], to have worked. Joe
  6. You needn't run two replace commands for what can be done in one. You may have tried including the brackets before but were unaware that they have a special meaning in regular expressions. They represent capturing parenthesis. An extremely useful tool. If you want to match them literally you have to escape them in the pattern with a backslash. Change your replace lines to the following one: tag = tag.replace(/\(\d+\)/g,''); This won't get the 5 in html5 as it is not surrounded by round brackets. Hope that helps you, Joe
  7. Number 1 already happens, but there's no captcha. Saw it once when I was considering reviving an old thread :
  8. Hi there, I am creating a login portal to site B from site A and I am running into a rather unique problem. The portal is made with an iframe to site B with a standard user name and password form within it. I then verify the data being sent from site B (as site A cannot verify it) using ajax and if it all checks out ok then the window is redirected to site B with the user logged in. Problem The problem only happens in Safari, no other browser has the issue. With a completely empty cache of site B the user cannot login properly, instead they are redirected to the homepage of site B. I managed to capture this split second error between response and redirect: Now this is the weird part Safari stops caring about that error after the first login attempt and every subsequent attempt afterwards works perfectly. Just like I want it too. I am really confused as to what is happening here. Has anybody run into this error before? Do you know how to solve it? I have tried replicating the error in every other browser and there are no issues. It is just Safari, I have Safari 5.0.4. Thanks for any help, Joe
  9. The key would have to be pressed within in the element you are attaching the event listener too. If you wish for something to happen when you press a key anywhere on the page, then add the event listener to the entire window. Keeping it as a keypress though, change your h2 tag to this: <h2 id="north" contenteditable="true">NFC North</h2> This will allow you to edit the contents of the h2 tag as if it were an input type. This means that when you focus in the h2 tag and then press a key, the event listener will do what you want it too. Otherwise, change the event listener to onmousedown and witness it happen when you click the tag. Hope this helps you, Joe
  10. Also, created a thread on FileZilla about ghost naming files during upload. Hopefully FileZilla will implement it. It's already got someone agreeing with me http://forum.filezilla-project.org/viewtopic.php?f=1&t=23809
  11. Thanks for finding that. I've altered it slightly to suit my needs, and only redirect if I'm not in a test environment. Thought I'd post it here since it's actually quite handy. It captures the type of error as a number and redirects to an error script sending type in the GET. In the error php that number is then retrieved and placed into a table in the mysql database along with a time stamp. If there's a new one when I log in, then I am notified of it: <?php //Report all errors error_reporting(E_ALL); /** Define the shutdown error handling to redirect a user to a nice page if a fatal error is detected **/ function shutdown() { $sandboxing = false; //check if in test environment if(strstr($_SERVER['HTTP_HOST'],'127.0.0.1')) { $sandboxing = true; } $isError = false; if ($error = error_get_last()) { switch($error['type']) { //http://www.php.net/manual/en/errorfunc.constants.php //parsing errors case E_PARSE: $isError = true; $errNum = 1; break; //fatal errors case E_ERROR: $isError = true; $errNum = 2; break; //core php fatal erros case E_CORE_ERROR: $isError = true; $errNum = 3; break; //compiling errors case E_COMPILE_ERROR: $isError = true; $errNum = 4; break; //a user generated error, when you call trigger_error(); case E_USER_ERROR: $isError = true; $errNum = 5; break; } } //error detected, redirect user to error page, but only on actual site if($isError == true && $sandboxing == false) { header("location:http://www.mysite.com/error.php?$errNum"); exit(); } } //make sure the function is called upon reciept of an error set_error_handler('shutdown'); register_shutdown_function('shutdown'); This means I can define errors anywhere in the script, and be told if and when they happen. I like this feature. Might likely add in further details like location... Cheers, Joe
  12. Hi there, Does anybody know of a way to make php execute a redirect if there was a compiling error? Specifically for the means of redirecting during file uploads. Most likely to a script which would wait 5 seconds with a nice error message and redirect back. I had a look at set_error_handler but it specifically says: So that's a no go it seems. If there is no way to do this with PHP, is there an FTP program that will upload the file you want with a ghost name during transfer, and then rename it and overwrite a conflicting file once the file has been 100% uploaded? That would also get around the problem I think. Thanks for any help, Joe
  13. You can't scribble in the PHP manual with extra drawings or reworded sentences to annotate it to your liking... Get the book I say. Just read it with a pinch of salt, knowing that some stuff will be outdated. I started out with O'reillly's 'Learning PHP, MySQL and JavaScript' book. It is fairly recent in terms of a tutorial book being from 2009 and I would recommend it to any beginner. It goes through the basics of everything you will need to know in order to make a website starting off with PHP, going on to describe and how to use MySQL, then slightly more advanced PHP including functions and classes. Then about two thirds/three quarters of the way through it begins to introduce you to JavaScript and then nearing the end, how to make dynamic pages with AJAX calls. Really useful book, and I find myself referencing it most other days when I forget something or get stuck. If you're like me, then a book is much more preferable to read than a computer screen. Especially since you'll be spending most of your other waking hours sitting in front of a computer screen.
  14. Fixed that for you. P.S. England does indeed produce some very fine ales, and lots of awful ones (these are generally found in the south). Fixed your fix Scotland produce the best whiskies in the world. Hands down. Get me an Old Pulteney with cheese and crackers any day of the week and I'm happy. But I stand proud by Yorkshire for the best beers. Black Sheep Ale is my flavour of the month. Though was speaking to the barman about how long it lasts in the cask, and he says 8 days from opening. So unluckily for you, I'm guessing it doesn't get shipped too far out of Yorkshire Southern England sucks for beer though (of what I've tasted from my few trips down there). They don't even put sparklers on the taps! So even if they produced a good beer, you wouldn't know because all you get is a flat acidic pint.
  15. You haven't had a real beer till you've come to England! Black Sheep, Ilkley Brewery IPA, Leeds Best... To name but a few fantastic, Beers
  16. Heard the rap-rock album "Blakroc" that the Black Keys did with some rappers? I've heard a few songs from it, it falls in the 25% It's not bad in terms of rap, but I wouldn't sit down with an aim to listen to it like I would with other artists/albums.
  17. Offt, this is a hard one. I range from anything from The Black Keys (they do the best music videos!) to Jack Johnson to Trentemoller to Audio Slave. Just so long as it isn't rap. Remember, rap is 75% crap. I tend to go through genre's though, not artists. But that's because I use last.fm for my music and I just crack a genre radio on. Currently, I'm on Electronic, Minimal or Experimental. Completely addicted to this song at the moment.
  18. joe92

    validation help

    AyKay47, neat solution. However, I would like to pick you up on one point that you mentioned: My solution has no backtracking in it... Sorry, what? And again, what? Can you please give a bit more information with your posts. What error's are being returned? Have you checked that you are passing the right information to the function? Which alert is popping up from AyKay's response? Your asking people to blind code a solution to a problem that you can't put into words. It's quite difficult.
  19. joe92

    validation help

    That looks like JavaScript, is it? If it is, try: <script> function searchfieldvalidate(value) { if(value.match(/^[a-z]+\s,\s[a-z]+\s,\s[a-z]+$/i)) //i turns case insensitivity on, allowing upper and lower case values of what ever is inside the match { return 'Valid'; } else{ return 'Invalid'; } } </script> What you had would fail on many places. The first being the multiple use of caret and dollar, which out of a character class, [], mean match at the beginning and end of the string. There can't be three beginnings and ends. Secondly, \W (the opposite of \w) means match any character that isn't a word character, meaning it would allow characters like {'#}@&*() through. The third fail was you use of character classes, [a-z][A-Z]\W\,]+. Note in particular, ]+, at the end. That end close square bracket has no opening counterpart bracket so what are we repeating? The square bracket? I don't even know how that would be interpreted to be honest with you, but I can definitely tell you it's wrong. I could go on but I'd rather suggest you read this: http://www.regular-expressions.info/tutorial.html Start at the introduction and end after free spacing. You will go in a matter of days from a complete novice in regular expressions to someone who can handle himself with them quite confidently. It is a very good tutorial. Hope that helps you, Joe
  20. I've installed Win7 on several boxes and have never had to do that. All I have to do is turn off that immensely annoying UAC. Ditto Turning off UAC only has the advantage of removing those highly annoying popup boxes. It does not give you full administrative access to the computer. Programs like Spybot Seach and Destroy, a malware program I use, needs full administrative access to alter the hosts files where it stores a database of malicious websites. I went a month, with UAC turned off, of having to right click and run as administrator to get the program to run properly. Whereas the admin account automatically runs everything as administrator To get that, you need to unlock the admin account. There are other methods to the one I posted, but this one is the most straightforward, just a line of text into the Command Prompt. Joe
  21. No. Preg_match will always stop after the first successful match. Preg_match_all however, is the one that will match them all.
  22. Alternatively to scootstah... If you are in Windows 7, you will need to unlock the administrator account. Microsoft, ever the most annoying firm ever are assuming that every user of their computers is a retard and doesn't even provide documentation on how to do it (that I could find). However, an even bigger geek than myself found out how to do it: (It says for vista, but it's exactly the same in Win7) http://www.howtogeek.com/howto/windows-vista/enable-the-hidden-administrator-account-on-windows-vista/ If you don't want to follow the link: - Start > Type in 'Command Prompt' > right click on Command Prompt and select 'Run as administrator' - Type in 'net user administrator /active:yes' - Look in the User Accounts in the control panel and their is your admin account - When using the admin account you will never get an annoying popup, bliss You might want to do as I do and remove your other account, rename the admin account to your name and only ever use that account. Whiles simultaneously cursing Microsoft for it's ever continuing dumbing down of the computer world Joe
  23. Ha, never mind. I was going along the right path with eval. I just wasn't doing it properly and the guide for this function anywhere is just abysmal. Anyway, the following eval code works: eval('newElement.style.'+property[j]+' = \''+itsvalue[j]+'\''); It's a shame I have to use eval though. I continuously read that it's an evil function :-\ If anyone knows a way around eval, I'd love to hear it! Thread solved though, Joe
  24. Hi, I am trying to create a function which can dynamically create an element for me. I am having difficulty with dynamically creating the styles though. This is my code so far: <?php //not php, just wanted syntax highlighting /*a function to create an element. Pass 0 for a null parameter. Declarations MUST be passed as an array in the format, array(property1, value1, property2, value2, etc...)*/ function createEl(el, inner, declarations, imageSrc){ /*sort out the optional parameters. El is a non optional string determining the element*/ var inner = inner || 0; var imageSrc = imageSrc || 0; var declarations = declarations || 0; /*create the element based on optional parameters sent through*/ var newElement = document.createElement(el); if(inner != 0) { newElement.innerHTML = inner; } if(imageSrc != 0) { newElement.src = imageSrc; } /*create the styles from the declarations array passed*/ if(declarations != 0) { /*create two new arrays to sort the properties from their values*/ var property = new Array(); var itsvalue = new Array(); var propertyNum = 0; var itsvalueNum = 0; /*split the declarations array into properties and values, place into respective arrays*/ for(var i=0;i<declarations.length;i++) { /*values*/ if(i & 1) { itsvalue[itsvalueNum] = declarations[i]; ++itsvalueNum; } /*properties*/ else{ property[propertyNum] = declarations[i]; ++propertyNum; } } /*now loop through the properties and add them, with their correlating values, to the element*/ var thisProp = ''; for(var j=0;j<property.length;j++) /*this is the part that is not working. The styles do not get added*/ { thisProp = property[j]; /*it didn't like just placing an array position after style.*/ newElement.style.thisProp = itsvalue[j]; } } /*return the created element*/ return newElement; } That code looks more than it is. What I need to know is how can I dynamically apply the styles (for loop right at the bottom of the code block) to this element without running a massive if-else statement? I had a play around with eval but I couldn't get it to work for me. I tried many things, and the following which I thought might have most chance of working: eval(newElement.style.thisProp = 'itsvalue[j]'); And I have tested, it definitely pulls out the property and value fine from the passed array. Just I'm having trouble with applying them. Thank you, Joe
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.