Jump to content

denno020

Members
  • Content count

    755
  • Joined

  • Last visited

  • Days Won

    2

denno020 last won the day on February 8 2014

denno020 had the most liked content!

Community Reputation

21 Good

About denno020

  • Rank
    Prolific Member
  • Birthday 02/22/1987

Profile Information

  • Gender
    Male
  • Location
    Australia

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

  1. First, to make your code easier to read, I suggest you write it like this: <script type="application/javascript"> (function($) { $(document).ready(function() { $(" .et_bloom_submit_subscription").click(function() { var $subscibeButton = $(this); // same as $('.et_bloom_submit_subscription') var $form = $subscibeButton.closest('.et_bloom_form_container'); var $firstName = $form.find('.et_bloom_subscribe_name input'); if ($firstName.attr('value') == '') { $firstName.addClass('et_bloom_warn_field'); return false; } else { $firstName.removeClass('et_bloom_warn_field'); } }); }); })(jQuery) </script> It caches jQuery objects so that you're not having to constantly parse the DOM, which will give a slight performance boost, but it will also make it much more obvious as to where the last name check should go <script type="application/javascript"> (function($) { $(document).ready(function() { $(" .et_bloom_submit_subscription").click(function() { var $subscibeButton = $(this); // same as $('.et_bloom_submit_subscription') var $form = $subscibeButton.closest('.et_bloom_form_container'); var $firstName = $form.find('.et_bloom_subscribe_name input'); var $lastName = $form.find('.et_bloom_subscribe_last input'); if ($firstName.attr('value') == '' || $lastName.attr('value') == '') { // Use .toggleClass so the second parameter will add/remove the warning class if only one of the fields is empty $firstName.toggleClass('et_bloom_warn_field', $firstName.attr('value') == ''); $lastName.toggleClass('et_bloom_warn_field', $lastName.attr('value') == ''); return false; } else { $firstName.removeClass('et_bloom_warn_field'); $lastName.removeClass('et_bloom_warn_field'); } }); }); })(jQuery) </script> There are a few other optimizations/updates that I would make to this code, if it were mine, but for the sake of simply answering the question, I won't change too much :). Hope that helps! Denno
  2. A quick and slightly dirty way you could achieve this is by wrapping your checkbox groups in a single element (div for example) and wrapping your tables in a single element also (but not the same one). So it would be something like this: <div class="checkbox-groups"> <!-- All of your checkbox groups --> </div> <div class="tables"> <!-- All of your tables --> </div> Then, you can use jQuery's index() function to get the index of the group that contains the checkbox that is activated, and then find the corresponding nth-child() in your tables div. Something like the following pseudo code $('input[type="checkbox"]').on('click', function(e) { var $checkbox = $(e.target); var index = $checkbox.index(); // Find corresponding <table> in the .tables element var $table = $('.tables').find('table:nth-child('+index+')'); // Loop through table cells to determine which should be highlighted }) I have written that using ES5, as your Fiddle is also written using ES5, but it could be cleaned up a but with arrow functions and template literals from ES6, should you happen to have access to a build tool or don't care about support for IE. If you can have a crack at implementing something like that, and post back with results, I'll be happy to help further with your solution
  3. The only way to get a value from JS to your PHP is to send a request from the JS to your server. This could either be through a form submission or an AJAX request PHP is run on the server, whereas JS is run on the client, essentially 2 completely different places that each have no idea about the other.
  4. denno020

    expected expression, got '.'

    There are issues with your code, no doubt, but what our friend above didn't mention is the reason you're getting the error is because you've got a semi colon at the end of line 8, even though you then try and concatenate another function call. Remove that semi colon and your code shouldn't complain. Whether it works as you expect it to is what you'll need to test next Denno
  5. denno020

    Image Slider

    Hi Stephie22, A Google for "Javascript carousel" turned up this, which looks quite nice: http://kenwheeler.github.io/slick/ Otherwise just run the same search and see what you can come up with, there will be a tonne of existing plugins/libraries etc
  6. Update: I have got back in touch with the hosting provider and am speaking to a different person now, and they're telling me that imagewebp isn't enabled and that I can't get it enabled because it's not supported on shared hosting. So seems there is nothing I can do about it. Thanks anyway
  7. Thanks for the response. How would I check the version of GD that is installed? I did suspect this could be the problem, but I didn't realise they were installed separately, so I (apparently wrongly) assumed that it was inside PHP itself. Also, as I mentioned, when running phpinfo() on the production server, it lists webp in the following two sections: HTTP_ACCEPT text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 $_SERVER['HTTP_ACCEPT'] text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8 Is this not related to GD?
  8. I'm having a weird issue with the aforementioned function inside my site. Here is an excerpt of code: if ($extension == 'jpg' || $extension == 'jpeg') { $isSaved = imagejpeg($image, $filename, $imageQuality); } elseif ($extension == 'gif') { $isSaved = imagegif($image, $filename); } elseif ($extension == 'png') { if ($imageQuality >= 100) { $imageQuality = 0; } elseif ($imageQuality <= 0) { $imageQuality = 10; } else { $imageQuality = round((100 - $imageQuality) / 10); } $isSaved = imagepng($image, $filename, intval($imageQuality)); } elseif ($extension == 'webp') { $isSaved = imagewebp($image, $filename, $imageQuality); } else { throw new Exception(sprintf('Image format "%s" not supported.', $extension), self::ERROR_NOT_SUPPORTED_FORMAT); } The issue is with the webp section, when this code runs (having passed a webp image to it), I get this exception Fatal error: Call to undefined function Image\Core\imagewebp() in ...... To me it looks like PHP isn't picking up the function as a native PHP function. I am able to use this code perfectly fine on my development machine (windows machine using WAMP with PHP7), but the issue seems to arise when this code is run on my production server. I have been in touch with my hosting provider just now, and they weren't able to enlighten me at all, actually telling me that I need to check the scripts or with a developer that can fix it. The production server is also running PHP7, and webp appears to be enabled (checked using phpinfo()) Does anyone know how I could continue to debug this issue? Thanks Denno
  9. denno020

    js/json issue....

    In the interest of completeness, something I didn't add to the jsFiddle is to break the loop(s) once you've found the data you want. Don't need to waste time looping through the rest of the data if you already have your translation value
  10. denno020

    js/json issue....

    You were on the right path with your for loop.. You just needed to go another level deeper.. I've had to make a few assumptions on what data you know (i.e. what you can test using if conditions), so the code in the attached jsFiddle may be a little off, but it should serve as a decent starting point. Check out what I've written here: var json = { "lang": [{ "code": 1000, "day": "Sunny", "night": "Clear", "icon": 113, "languages": [ { "lang_name": "Chinese Simplified", "lang_iso": "zh", "day_text": "晴天", "night_text": "晴朗" }, { "lang_name": "Finnish", "lang_iso": "fi", "day_text": "Aurinkoinen", "night_text": "Pilvetön" }, { "lang_name": "French", "lang_iso": "fr", "day_text": "Ensoleillé", "night_text": "Clair" }, { "lang_name": "German", "lang_iso": "de", "day_text": "Sonnig", "night_text": "Klar" },{ "lang_name": "Spanish", "lang_iso": "es", "day_text": "Soleado", "night_text": "Despejado" }, { "lang_name": "Swedish", "lang_iso": "sv", "day_text": "Soligt", "night_text": "Klart" }] }, { "code": 1003, "day": "Partly Cloudy", "night": "Partly Cloudy", "icon": 116, "languages": [{ "lang_name": "Chinese Simplified", "lang_iso": "zh", "day_text": "局部多云", "night_text": "局部多云" },{ "lang_name": "Finnish", "lang_iso": "fi", "day_text": "Puolipilvinen", "night_text": "Puolipilvinen" }, { "lang_name": "French", "lang_iso": "fr", "day_text": "Partiellement nuageux", "night_text": "Partiellement nuageux" }, { "lang_name": "German", "lang_iso": "de", "day_text": "leicht bewölkt", "night_text": "leicht bewölkt" }, { "lang_name": "Spanish", "lang_iso": "es", "day_text": "Parcialmente nublado", "night_text": "Parcialmente nublado" }, { "lang_name": "Swedish", "lang_iso": "sv", "day_text": "Växlande molnighet", "night_text": "Växlande molnighet" }] } ]} // Example, get the Spanish translation for Partly Cloudy for (var i = 0 ; i < json.lang.length ; i++) { // Loop the weather types // First iteration will give you 'Sunny' // Second iteration will give you 'Partly Cloudy' // etc var langFile = json.lang[i]; if (langFile.code !== 1003) { // Matching on the code for 'Partly Cloudy' continue; // Continue the loop if the code doesn't match } // Getting here means we know that the variable lang contains the language translations for 'Partly Cloudy' for (var j = 0 ; j < langFile.languages.length ; j++) { // Loop through translations to find Spanish var language = langFile.languages[j]; if (language.lang_iso === 'es') { alert(language.day_text); // Success! This is where you will update your applications text. (You won't use alert) } } } Any questions, let us know . Hope that helps, Denno
  11. denno020

    js/json issue....

    Yep this should be pretty easy.. Have you come close to any working code? I wouldn't mind seeing what you've got, and then I can try to show you where you're going wrong and how to change it. Might be better than me just giving you the answer I think Denno
  12. denno020

    Ajax on safari

    Can you try replacing window.location.href with just location.href and see if that works Denno
  13. denno020

    More Random Count

    I'm struggling to figure out which numbers you want to be random.. But, for random numbers you can just use the Math object, and the random() function. That will return a decimal between 0 and 1, so you'll need to do some further work to get a whole number that is between some lower and upper limits. For setting those limits, the Mozilla Developer Network page for the Math.random() function has some great examples Denno
  14. denno020

    Event binding with dynamic ID's

    What exactly isn't working? is the modal not being populated with the right data? That is because when you call $('.alert-modal').html(data), the data variable likely has a value of undefined If you can let me know exactly what isn't working, I can help you work through that. Ignore that I wrote the ID section of my code, that just seems to be confusing you
  15. denno020

    Event binding with dynamic ID's

    You should be able to attach the listener to `#svrAlertsUS`, because the element itself isn't being replace, only it's contents, so the JS event binding won't be lost. But to answer your question, yes that event binding you've written will work. The suggestion I gave in regard to getting the ID will read whatever the ID is, regardless of how it came to be assigned to the returned data. I wasn't sure if you'd need it, I added it just in case. Looking at your original code again, the function executed when a link is clicked is going to need some more work. You'll likely want to read the content of the `#svrAlertsUS`, and then inject that into the modal, rather than relying on `data` still having the correct data that you want Denno
×

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.