-
Posts
5,717 -
Joined
-
Last visited
-
Days Won
6
Everything posted by Adam
-
Hmm.. Is there a reason you're writing all of the pop-up's contents using JS? Why not place it all in an HTML file you specify in open(), and then just use JS to add in the extra bits of data you need? Or perhaps even easier, pass the data in as parameters and build the HTML using PHP?
-
Including the () after the function means that you're invoking it immediately, and then passing into the setTimeout function anything it may return. Just drop those and you will be passing the function itself: setTimeout(myWindow.setFocus, 2000);
-
You could just define it before the script is included? <script type="text/javascript"> var someVar = '<?php echo htmlspecialchars($someVar) ?>'; </script> <script type="text/javascript" src="js.js"></script>
-
My attempt at explaining the JS issue to someone: http://forums.phpfreaks.com/index.php?topic=361547.0
-
You need to use: myWindow.document.write( "<" + "/script>" ); There's actually a recent thread about this in the misc board as well. Because JS is wrapped in HTML tags, the browser first looks for the opening and closing script tags, then the JS engine parses what's in the middle. So the browser finds the closing script tag, even though it's within a string, and passes the JS engine a broken script.
-
You can just echo the PHP variable into a JS variable declaration: var someVar = '<?php echo htmlspecialchars($someVar) ?>'; Added the escaping to ensure no characters within the string would break the JS syntax.
-
I disagree, I'm with Kevin on this one. From my experience the people doing the hiring are a little more down to Earth these days, and appreciate that a degree is not required to be good at the job. It's probably a regional thing though..
-
JavaScript form textbox value detection not working correctly.
Adam replied to Jacbey's topic in Javascript Help
Fixed jQuery version: // Create an array of elements var elements = $('#forename, #surname, #sex, #country'); // Bind the focus/blur events elements.focus(function() { // We always want the dim effect hidden when focusing on an element toggleDim(false); }).blur(function() { var showDim = true; // Loop through the elements until we find one with a value elements.each(function() { if ($(this).val() !== '') { showDim = false; return false; } }); toggleDim(showDim); }); -
JavaScript form textbox value detection not working correctly.
Adam replied to Jacbey's topic in Javascript Help
Just realised there's a bug in the code. The jQuery each should use the alternative syntax and access the value with the Val() method. I'm on the train at the moment but will update the code when I'm home. -
JavaScript form textbox value detection not working correctly.
Adam replied to Jacbey's topic in Javascript Help
Yeah that makes a lot more sense, cheers. Rather than adding a bunch of "onblur" and "onfocus" attributes within the HTML, we can pull out the logic and handle the binds separately. That way we can also avoid a lot of repetition by actually scripting it: // Create an array of elements var elements = [ document.getElementById('forename'), document.getElementById('surname'), document.getElementById('sex'), document.getElementById('country') ]; // Loop through each element for (i=0, l=elements.length; i<l; i++) { // Bind the focus event elements[i].onfocus = function() { // We always want the dim effect hidden when focusing on an element toggleDim(false); }; // Bind the blur event elements[i].onblur = function() { var showDim = true; // Loop through the elements until we find one with a value for (x=0; x<l; x++) { if (elements[i].value !== '') { showDim = false; break; } } toggleDim(showDim); }; } function toggleDim(show) { // I'll leave this to you } That probably looks more complicated than it is. All it does it create an array of elements, loops through them and binds the focus and blur events to each element separately. Within the focus event we simply just hide the dim effect, within the blur event we loop through the elements again and check if any have a value. When an input is encountered that does have a value we just update the flag and break out of the loop. At the end we then just update the dim. I left the toggleDim() function for you to complete because that's pretty straight-forward. I'm not sure how you've got your scripts set-up, but you'll need to put that at the end of the <body> or within the window's load/ready event handler. --------------- Also I'm not sure if you've used jQuery before, but this is the kind of thing it excels at. Here's the equivalent: // Create an array of elements var elements = $('#forename, #surname, #sex, #country'); // Bind the focus/blur events elements.focus(function() { // We always want the dim effect hidden when focusing on an element toggleDim(false); }).blur(function() { var showDim = true; // Loop through the elements until we find one with a value $.each(elements, function(key, val) { if (val !== '') { showDim = false; return false; } }); toggleDim(showDim); }); None of this has been tested by the way. -
JavaScript form textbox value detection not working correctly.
Adam replied to Jacbey's topic in Javascript Help
So it's clear, on what events on what inputs do you want the dim effect to be removed? -
Running a query for each row of a result set is bad practise and really inefficient, never mind running a subsequent query for each row from each of those queries as well. In your case let's say the user belongs to 10 groups. So 10 rows are returned in the top-level query, which means the second-level query is ran 10 times. Let's then say that each group has on average 5 ballots available, which means the third-level query is ran around 5 times for every group. That means, if my math is right, you're running about 78 queries in total! Instead, as mentioned, you could use a join that will do everything in a single query: $sql = " SELECT b.* FROM group_membership gm JOIN group_ballots gb ON (gm.group_id = gb.group_id) JOIN ballots b on (gb.ballot_id = b.id) WHERE gm.user_id = '{$user}' "; I used b.* because I don't know the names of the columns, but I would add them manually instead of using *.
-
They're different for me? How much time did you give in between adding the dynamic titles and checking the feedback? It's possible Google just hasn't re-indexed the pages yet.
-
I don't get why apps on a music player is a negative? I have my phone, why do I need another identical device, except that it just lacks phone capability? It's daft. I love music and I would much rather invest in a music player that spends 100% of their time improving that experience, rather than having Facebook and other pointless app/games available on it. I have a phone for that. I've never used Zune but after the comments that it's "all about music", I'm intrigued to look into it. Edit: I didn't mean the other negative points ZulfadlyAshBurn raised weren't valid by the way, just not those about apps.
-
Oh sorry I follow you now, I thought you meant the value that's split was from a drop-down. Glad it's working though.
-
I don't understand? How can you split 1, 2, 3, etc. ?
-
Personally I think "always" using back-ticks is a little overkill. If you know that there are reserved words and are vaguely aware of the ones which may conflict with common names for columns, I don't see the need. Just my opinion of course, but I find them awkward to read.
-
To ensure everyone's on the same page here, what's your definition of a model?
-
You can use split(): var parts = someval.split('-'); // parts[0] now contains "12" // parts[1] now contains "99" Not quite. You want to select a sub-string of someval; currently you're trying to select it from the input's DOM object. With the parts array though you don't need to use substring: document.formName.inputName1.value = parts[0]; document.formName.inputName2.value = parts[1];
-
Yeah I see what you mean. I'll experiment with a subtle outer/inner shadow, to try and blend them in better. Thanks! Here's the original by the way (mind your eyes): http://goo.gl/9j0Cb I don't have a huge amount of content to work with, but he has now sent me a nice amount of high-res images at least.
-
Hi guys, Started work over the weekend on a new spare-time freelance job for a friend's Dad. It involves a lot of design and I tend to struggle on that front, but quite pleased with progress so far. Still in the design stages so I haven't chopped it up yet, but prepared a preview for the guy and would also welcome some early feedback while it's up. http://goo.gl/tXeJf Cheers
-
If you're more familiar with PHP, here's the equivalent that might explain it better: $options = new stdClass; $options->$theSide = 400; $foo->animate($options, 400);
-
In JS you can't have "variable variables" like in PHP, because there's no way of determining what's meant to be a variable and what's meant to be the actual name of the variable/property. However, JS does provide an alternative way of accessing object properties, which is the array-like syntax (I stress like, because they're not actually arrays.) Given we reference the name of the property as a string, it means we can manipulate it and pass a variable instead. So in the code, we first define options as an empty object: var options = {}; Then using the array-like syntax, we set the "marginLeft" property of the object: options[theSide] = 400; So at this point, options is equal to: {marginLeft: 400} We can then pass that variable into the animate() method as an argument: $('#animDiv').animate(options, 400); Which is exactly the same as: $('#animDiv').animate({marginLeft: 400}, 400); The only difference is we've stored the object within a variable.
-
It most certainly can be done. Just add an extra statement to the function: function transferField(someval){ document.formName.inputName1.value = someval; document.formName.inputName2.value = someval; }
-
Yeah I think that's a pretty good idea. I bet people have some right handy tools they never think to mention..