KevinM1
Moderators-
Posts
5,222 -
Joined
-
Last visited
-
Days Won
26
Everything posted by KevinM1
-
[SOLVED] Is it possible for 1 form to have 2 actions?
KevinM1 replied to kringshot's topic in PHP Coding Help
Not without using JavaScript. Thankfully, what you want to do is rather simple to execute using sessions. Google 'PHP sessions' to get started. -
First, instead of polluting the board with multiple threads, you should consolidate your questions in as few posts as possible, preferably only one. It's bad etiquette to hog the forum. Second, if you actually bothered to read the forum rules (there's a handy link to them in my signature below), you'd know that asking homework questions without attempting to answer them yourself is prohibited. So...what answer would you choose, and why?
-
OK, I have no sites using php4 anyway, but what was the reason to use =& anyways? I saw the docs on "return by reference", but I don't understand. Normal assignment is often achieved with 'return by value.' This means that a copy of the value is returned and stored in the variable being assigned to. 'Return by reference' actually stores a reference to that particular value/object/whatever. So, instead of having a copy, you're essentially dealing with the real thing. More info: http://www.adp-gmbh.ch/php/pass_by_reference.html , http://us2.php.net/references
-
Are you familiar with CSS at all? Ken's solution relies on CSS to function. His code, broken down: var selected_image = null; Initially set the selected image to null, as nothing's been selected yet. var imgs = document.getElementsByTagName("img"); Obtain all of the images (<img ... />) on the page. for (var e = imgs.length; --e > -1; ) { Loop through them all (a clearer way of writing this would be: for(var i = 0, var imgCount = imgs.length; i < imgCount; i++){ ) Then... if (imgs[e].className === "img_unselected") { If the image we're currently at is supposed to be part of this functionality imgs[e].onclick = function () { Add a function to its onclick event. That function does the following: if (selected_image !== null) selected_image.className = "img_unselected"; If there's another image that's been selected already, set it back to normal. Then... this.className = "img_selected"; selected_image = this; }; } } Tell the current image to set its border, and store a reference to it so we know which image to 'turn off' if another is clicked. Ken's solution also has the benefit of not needing the onclick event to be written directly in the image's HTML. But, like I first said, Ken's solution requires knowledge of CSS to work. Let us know if you need a crash course on it.
-
You should show us all code from where $query is defined/assigned to the line where the error is being reported.
-
You're right about number 1. Had a brain fart, there. Number 2 is easily remedied by setting the variable to '"Kevin"'
-
Why couldn't you dynamically hide/show pre-existing elements instead? I'm not a fan of injecting a lot of HTML into an existing document, especially if it's somewhat complex, like in this instance where you're trying to tie dynamically written buttons to other functions. It makes things hard to debug and modify.
-
In my test code, I did: <html> <head> <title>Blah</title> <script type="text/javascript"> window.onload = function() { var myName = "Kevin"; var htmlToInject = "<button type='button' onclick='insert(" + myName + ")>Clicky</button>" var buttonDiv = document.getElementById('buttonDiv'); buttonDiv.innerHTML += htmlToInject; function insert(someName) { var myDiv = document.getElementById('myDiv'); myDiv.innerHTML += someName; } } </script> </head> <body> <div id="buttonDiv"></div> <div id="myDiv"></div> </body> </html> Firebug tells me that 'insert(Kevin)' is not defined. If you want to debug it for me, be my guest. To the OP, I think you're getting the same kind of error that I am. I'm curious, though - why are you trying to inject buttons into the HTML to begin with? It seems like an odd design choice on the surface.
-
I'm unable to loop the same variable instance twice
KevinM1 replied to scrubbicus's topic in PHP Coding Help
Show code. -
Not if 'name' was assigned to earlier, which I assume it was. Well there's that and then there's also the case when the function is executed upon onClick. The problem there isn't the variable being passed in, but rather the event handler. I made a test script to double-check this kind of code injection. The variable I passed into the inline event handler worked fine - it just couldn't find the event handler function itself. Firebug said that the function and not the variable was not defined. But, that's not what the OP asked for ;-P
-
Not if 'name' was assigned to earlier, which I assume it was.
-
If I'm reading you right, you have a variable named 'name' and you want to inject it into the string. If that's the case, double quoted strings in JavaScript don't work the same way as they do in PHP. If you want to inject a variable into a string, you'll need to manually concatenate it: var newHTML2 = "' /> <small>(<a href='#'>Save</a>) (a href='#' onclick='editNameC(" + name + ")'>Cancel</a>)</small></span>";
-
You can't use getElementById() in this case because an id is a unique identifier. So, JavaScript expects that you're referencing only one element when you use an id. You'll need to grab a hold of the radio buttons by name. It's not too hard to do: var radioArray = new Array(); var inputs = document.getElementsByTagName('input'); var chartOutput = ''; for(var i = 0; i < inputs.length; i++) { if(inputs[i].name == 'chart') { radioArray.push(inputs[i]); } } /* now you can check to see which button has been pressed */ for(var j = 0; j < radioArray.length; j++) { if(radioArray[j].checked) { chartOutput += " " + radioArray[j].value; } } alert("Chart -" + chartOutput); So, you'll need to run through all of the inputs on the page and store those that represent the radio buttons. Then, you'll need to go through that grouping and obtain the value of the checked button.
-
Use: switch($rand) { /* the rest of your code */ }
-
To get you started, you should look at how other sites are designed. Look for common elements like header images, navigation menus, content columns, and other things of that nature. Observe how they add a sense of structure to the page - by using headings, or borders to separate sections, etc. The positioning of elements is key. IMO, the first step should be to build the general layout. Fiddle around with the raw HTML (or, even better, use a graphics editor) to see where elements should go. Once you're happy with that, then you can go on to colors and font. With your site, in particular, I'm not a fan of the blue and green combo. It puts a bit of strain on my eyes. A simpler color combination with more contrast may work better. In fact, I think a three or four color design would work best. Black and white for the text, so it's easy to read (see: CNN, Amazon, ESPN, IGN, etc), and the other, more exciting colors to give your site personality and visible 'oomph'. Hope this helps a bit.
-
Oh geez...I didn't even see the second while-loop. D'oh!
-
If that's the version you're currently using, mind copying the exact error message you're getting?
-
No music for me. Too distracting.
-
A few things: First, HTML attribute values should be placed in quotes. Right now, none are. Second, it doesn't look like you're actually grabbing a hold of that select input. I'm not familiar with the Prototype framework, but using regular vanilla JavaScript, I'd try something like (ignoring your PHP in the example): <script type="text/javascript"> window.onload = function() { var items = document.forms["form1"].elements["lifedropdown"]; items.onchange = function() //could also use onclick { var itemID = this[this.selectedIndex].value; alert(itemID); } /* the rest of your script */ } </script> <!-- your form --> Life: <form id="form1" name="form1" method="post" action="pod.php"> <select id="lifedropdown" name="lifedropdown"> <!-- your options --> </select> </form> Note that I removed the function call from the select's code. That's just my coding style. I like keeping my script out of my markup. In any event, something along those lines should work.
-
I'm not sure how helpful this will be, but here's another way of looking at it. Both abstract classes and interfaces help create and enforce type. They each do it in different ways. Like Daniel said, abstract classes are incomplete. Their most common use is to be an uninstantiated base class that other classes derive from. Here's a canned example: abstract class Animal { public function makeSound(); public function walk() { echo "I moved 3 feet"; } } class Cat extends Animal { public function makeSound() { echo "Meow"; } } class Dog extends Animal { public function makeSound() { echo "Woof"; } } As you can see, abstract classes can have a mix of methods that are declared, but not defined (makeSound()) and fully defined methods (walk()). The important thing to remember is that abstract classes can't be instantiated (that is, you can't create an object of that class), so they are used as base/parent classes. Interfaces, again like Ken and Daniel said, enforce their own interfaces (sounds dumb, but bear with me). The methods in an interface are never defined - instead, any class that implements that interface must provide definitions for each interface method. So, what does this have to do with type? Look at the following example: abstract class Collection { protected $items; protected function push($item); protected function pop(); } interface IEnumerable { public function count(); public function next(); public function previous(); } class Stack extends Collection implements IEnumerable { } class Queue extends Collection implements IEnumerable { } Both Stack and Queue can be considered to be an object of three distinct types: Their own type (Stack or Queue) Collection IEnumerable Daniel's example took advantage of this fact as he checked whether or not his objects were XMLable. With OOP, as you get more familiar with it, you'll see that two of the more important considerations are an object's type and an object's interface. The two often go hand-in-hand. Look at the example with the animal-themed classes again. Cat and Dog aren't entirely the same. But, since they share the same base class, and their public interfaces are the same, they can be used interchangeably in certain instances: class Zoo { private $animals; public function addAnimal(Animal $animal) { $this->animals[] = $animal; } public function makeSound() { foreach($this->animals as $animal) { $animal->makeSound(); } } } That Zoo could contain nothing but Dogs, nothing but Cats, or a mix of each. But, it doesn't matter what is actually contained in the Zoo, as we can treat everything uniformly. Hopefully this helps a bit.
-
Are you still getting an SQL error?
-
Absolute value is simply the value of a number. Whether it's positive or negative doesn't matter - the value of the number is the same in either case. That's what the abs() function returns. More info on absolute values: http://en.wikipedia.org/wiki/Absolute_value
-
Hmm... Well, the toggle event is essentially a specialized click event (http://docs.jquery.com/Events/toggle#fnfn2fn3.2Cfn4.2C...). So, why not remove the outer-most click event? $(document).ready(function() { $("cdinfo").hide(); $('#cdcase').toggle( function() { $('#cdinfo').animate({width: "250"}, 1500); }, function() { $('#cdinfo').animate({width: "0"}, 1500); }); });
-
Looks like you're calling preg_match wrong, as the second argument is supposed to be the string you're checking. So, try: if(preg_match('/[^w-]', $str)) { echo "Error"; }
-
It'd be easier to just use the absolute value: $tmp = $submitted - $database; //store the difference in a temporary variable $result = abs($tmp); //find the absolute value of the difference and store the result echo "$result"; From what I can tell by reading the manual, the abs() function can't calculate the absolute value of a mathematical expression; it can only find the value of individual numbers. That's why you should first store the difference in a temporary variable.