-
Posts
5,717 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Adam
-
You can place random bits of JavaScript like that at the bottom of your document - just before the closing body tag - without the need for an event. As a plus point, the code will be executed before the page has loaded - so the user isn't likely to see the paragraph disappear at all. On-load events, including the custom 'jQuery document ready' event, both execute after the page has finished loading, which sometimes can be noticeable.
-
Learn something new every day
-
That's all your code - not the relevant parts.
-
No, not quite. Your templates files only contain display logic - simple control statements to get the output desired. As ignace was saying, your application code should do all the complex stuff and prepare the data so that you only require simple control statements within the display logic. The code, as I mentioned, was purely just a simple example of how the logic is split. What you're asking is kind of like asking how to work with 'complex PHP' - do you have a more specific question?
-
It would theoretically work, but I'd consider it a very hacky method.
-
Fair enough. How come you're setting the input as an array then, out of curiosity..?
-
Square brackets within an input's name creates an array... are you wanting to validate multiple file inputs here? If so then using an ID is not the way to go, as they should be unique. Also if you set the ID the same for each, only the last element with the ID will be validated.
-
Muddy_Funster, bachx is referring to separating the PHP (AKA "business") logic from the display logic. Obviously you will always need PHP to some degree within the HTML; after-all you have to use PHP to loop through a data set (excluding an XSLT approach). SMARTY templates are simply parsed and then 'compiled' into PHP-based templates. A clean way to achieve this with standard PHP code is to include your template files that rely on a set bit of data.. For example: PHP logic $test_data = array('foo', 'bar'); include 'test_template.php'; PHP template <table> <?php foreach ($test_data as $data) { ?> <tr> <td><?php echo $data; ?></td> </tr> <?php } ?> </table> Obviously this is very simple, but you can see how the PHP logic has been split from the display logic. With a better template structure and more planning, it would work well. In the end though this is all SMARTY templates boil down to, it's just coded through a more elegant (arguable) interface.
-
Is "companykey" the ID of an element within the HTML?
-
If you post the relevant code I'll take a better look, but variable scope is quite an easy concept. var global_var = 'foo'; function myFunction() { var scoped_var = 'bar'; } In the code above you can access global_var from within myFunction() as it was defined globally - i.e. outside of the scope of a function. scoped_var can only be accessed from within myFunction() as that's where it was defined - within the scope of the function. You couldn't access scoped_var from within another function however, as it's not in scope. The same principle applies to functions within functions; the top-level function being a kind of "global" scope, but for only the functions defined within. If you redefine a global var from within the scope of a function, be sure to not add "var" in-front of the assignment, or you will declare a local variable -- the global variable would still exist, but you wouldn't be able to access it as you have a local variable with the same name (well you could access it, if you go through the window object: window.global_var). As I said if you post the relevant code I'll take a better look, or someone else might have time to look through your code in greater detail. It's better to read and understand the problem yourself though, than to rely on someone to give you the answer.
-
Recognizing if a specific select option was chosen?
Adam replied to galvin's topic in Javascript Help
You should move the condition to the function... Your HTML mark-up shouldn't contain JavaScript logic -- it's actually good practise to remove all event bindings from the HTML too, never-mind this. -
JavaScript only allows you to refresh a form in whole, similar to a input type="reset", using the .reset() method on a form object. If you want to reset only portions of the form, you would be better (for a more semantic approach) using <fieldset>s instead of <div>s, and manually looping through all inputs within the <fieldset> and clearing their values. Are you using jQuery at all? jQuery makes this kind of thing a simple one-liner, where-as the pure standard JavaScript approach would be a little more complex.
-
That's because you're assigning an array.
-
Look into a technology called AJAX. Using AJAX you can make a HTTP request to the same domain from within your JavaScript, effectively allowing you to call the PHP once an event is triggered.
-
That's an interested idea monkeytooth. How many rows are we talking spiceweasel? ... What a bizarre sounding sentence.
-
javascript/jquery detect user scroll 200px from bottom of page
Adam replied to shortysbest's topic in Javascript Help
You can use: $(window).unbind('scroll', arguments.callee); -
You can't do it like that, as MySQL will have no way of knowing which have already been used on a previous page... short of storing each used item's identifier within a session and pumping into a WHERE clause within the query anyway -- which is a really bad idea for a number of reasons! You need to have some form of order so that you can tell MySQL where to pick up from in the ordered list on the next request. If the results are based on a search criteria, they should be returned in relevance order. If you want a kind of browse page, then I'd order them by newest first (which means as they're added they would be number #1, and then slowly degrade). If you want more randomness, you could perhaps add several random accommodations on the home page or at the side of the normal listings? Either way though, the kind of ordered yet randomized results you wish aren't possible - or should I say feasible - to the best of my knowledge.
-
It depends on what the text contains- if it's literally text/characters, then use a CLOB - character long object. If it's to store "files", like image data, then you should use a BLOB - binary large object. Both are really fun to work with anyway!
-
checking if string contains upper and lower case characters
Adam replied to Destramic's topic in Javascript Help
When you extend the object you don't pass the string in as a parameter, it's already available as this: String.prototype.string_has_numbers = function() { return this.match(/\d/); } You don't need the 'g' modifier in that expression by the way. I'd consider renaming that method too, to be more in-line with the other String methods, like .indexOf(), .charAt(), etc. -
checking if string contains upper and lower case characters
Adam replied to Destramic's topic in Javascript Help
I'll leave the naming of it to you... function nameHere(str) { return str.match(/[a-z]/) && str.match(/[A-Z]/); } This would be more apropriately added as a method to the String object by the way. That way instead of passing it as a parameter to the stand-alone function, you could simply call it like myString.nameHere() - which would be done with the following code: String.prototype.nameHere = function() { return this.match(/[a-z]/) && this.match(/[A-Z]/); } But which you use it up to you of course. -
javascript/jquery detect user scroll 200px from bottom of page
Adam replied to shortysbest's topic in Javascript Help
Much easier to read indented.. but anyway this is how you'd unbind the event: // bind the scroll event here to the function expression $(window).scroll(function () { // check if we've scrolled to the last 100px if ($(window).height() + $(window).scrollTop() >= $(document).height()-100) { // unbind the scroll event so we don't come here again $(window).unbind('scroll'); -
checking if string contains upper and lower case characters
Adam replied to Destramic's topic in Javascript Help
Do you want it to match for only numbers, upper-case and lower-case letters, or make sure the string contains at least one of each? Or even a string that only consists of numbers, upper-case and lower-case letters, and has to have one of each? -
There's a few ways. If you want strict validation, cast the value as a number by subtracting it by 0 (therefore the numeric value won't have changed) and compare it to its string value. For example with your code: if ((form.elements[i].value - 0) != form.elements[i].value) { // invalid } Might want to store that value in a variable to make it a little more readable.
-
Onblur overriding onclick - can't figure out how to make it work
Adam replied to linus72982's topic in Javascript Help
You're welcome