Jump to content

KevinM1

Moderators
  • Posts

    5,222
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by KevinM1

  1. - skip to ~31:48 (yeah, it's a long video). Douglas Crockford is the senior JavaScript Architect at Yahoo! and the guy who wrote the spec for JSON. I'll take him at his word regarding the curly braces.
  2. While digging around, looking for an answer, I found: http://bytes.com/topic/javascript/answers/761827-createelement-appendchild-not-working-ie So, try adding a <tbody> tag.
  3. <html> <!-- the head and all that jazz --> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <input type="submit" name="search1" value="Search Option 1" /> </form> </html> $on = $_POST['search1']; if($on == "on") { include("searchtopic.php"); } else { include("searchnormal.php"); } No JavaScript required.
  4. Well, a quick glance doesn't show anything wrong. However, one of the little JavaScript 'gotchas' is that, unlike other languages, for consistent results, you need to start your opening curly brace on the same line as the name of whatever block of code you write. In other words, the following is good: function myFunction(/* args */) { if(something) { //code } } And this is bad, and can cause odd errors: function myFunction(/* args */) { if(something) { //code } } It has something to do with the way JavaScript executes statements (at least, according to Douglas Crockford). What do you mean by 'doesn't work'? Is the form not displaying? Not behaving properly? I'm also curious - why are you building the entire form dynamically? Surely having raw HTML would be simpler and easier to debug.
  5. For the MySQL database, yes. There are also other built-in functions that do the same thing for other brands of db. Even better, using the MySQLi extension or PDO gives one prepared statements, which automatically escape values.
  6. You're missing a . after $data in your fwrite line.
  7. If that's all you're using Base for, why even bother? Simply create your own __autoload() function to automatically include()/require() the correct class files when needed.
  8. Haha, you're right. I didn't realize that properties could be static. Still learning the ins and outs of the language myself.
  9. Well, IMO, it depends on the operations being done on the data. If you're merely treating the object as a collection of data that can be stored and/or retrieved, you could define it as something like a PHP version of a struct by keeping the data members public. If you're doing anything more advanced/complex, keep the encapsulation in place.
  10. In C#, it looks like it may be overloaded as both a struct and a class. VB makes a distinction between a Date object and instantiating it with the value obtained by DateTime.Now, but C# doesn't. See: http://msdn.microsoft.com/en-us/library/system.datetime.aspx
  11. Actually, DateTime is a struct, not a class. Now is a field of the struct representing the current system time. Also, class properties aren't static. Example: public class Person { private string name; private int age; public Person(string name, int age) { this.name = name; this.age = age; } public string Name { get { return this.name; } set { this.name = value; } } public int Age { get { return this.age; } set { this.age = value; } } } //... Person person = new Person("Bubba", 34); person.Name = "Forrest Gump"; Console.WriteLine("{0}'s age is {1}", person.Name, person.Age);
  12. Actually, now that I'm more awake, you don't need another structure (class or struct) to do what you want. You simply need an event handler. So, this is what I came up with - test.aspx: <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> </head> <body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="DropDownList1" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" AutoPostBack="true" runat="server"> <asp:ListItem>--</asp:ListItem> <asp:ListItem Value="Red">Red</asp:ListItem> <asp:ListItem Value="Yellow">Yellow</asp:ListItem> <asp:ListItem Value="Green">Green</asp:ListItem> <asp:ListItem Value="Blue">Blue</asp:ListItem> </asp:DropDownList> <br /><br /> <asp:Label ID="Label1" runat="server"></asp:Label> </div> </form> </body> </html> That should be pretty straight forward. Setting DropDownList1's AutoPostBack to true is essential in getting this to work. test.aspx.cs: using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; public partial class _Default : System.Web.UI.Page { public void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { switch(DropDownList1.SelectedValue) { case "Red": Label1.Text = "Rusty"; break; case "Yellow": Label1.Text = "Sunny"; break; case "Green": Label1.Text = "Grassy"; break; case "Blue": Label1.Text = "Icy"; break; default: Label1.Text = "Bubba"; break; } } protected void Page_Load(object sender, EventArgs e){ } } Again, pretty straight forward. Just to recap what's going on: DropDownList1 has an event that fires whenever you change its selection - OnSelectedIndexChanged. In order to do something with the event, you need to tie it to an event handler function. In this case, the event handler is called DropDownList1_SelectedIndexChanged. The event handler obtains the value of the list's current selected index, and fills Label1 with the correct text. AutoPostBack is needed because there's no submit button to send the info to the server so the function can fire. AutoPostBack allows the info to be submitted whenever the list's index changes. If you don't like the fact that a page refresh is necessary for it to work, you could always do it in straight JavaScript. Since you're not accessing any data that lies on the server (database, XML files, etc), there's no real reason to use .NET for something like this. Unless, of course, this is for educational purposes.
  13. Ah! VB! Run!! First, be sure to put runat=server in your select server control. Otherwise, your script won't be able to get a hold of the value. I think you're on the right track. I'm not too familiar with using inline coding - I prefer to use a pure code-behind file - but I don't see why the basics of what you're trying to do won't work. You should clean up your class a bit, though. Despite its small size, it could be better. I'd do either (using C#): public class PetName { private string firstName; public PetName(string name) { this.firstName = name; } public string FirstName { get { return this.name; } set { this.name = value; } } } To treat it like a full-fledged class, or: public struct PetName { public string FirstName; } To treat it as plain old data. Also, to do what you want to do, you'd most likely need to tie it into the select's onchange event. Do you merely need to store the value of the name, or do you need to display it, too?
  14. KevinM1

    Page Layout

    Why are you: 1. Trying to use parts of the background image as hyperlinks? 2. Not slicing your large image if, indeed, it has the buttons/links you want to use? 3. Not using CSS to help with the layout in general? It sounds like this is your first attempt at transferring a layout to an actual web page, so I'll give you more of a hint than I normally would. Layouts developed in an image editing program, like Photoshop, need to be sliced into logical parts. You can't transfer the image wholesale, set it as the background of the page, then put links over it (well, technically you can, but it's definitely not the way to go). So, you need to cut up your layout, but how do you know where and what to cut? It depends on the layout itself and how it would fit into HTML. As you make your layout, you should think about its structure, and how that would translate into code. Also, it's not a good idea to use a table for layout. Tables are easy to understand, but using them quickly becomes nightmarish. Using divs with CSS positioning and styling is the preferred way to do it. Tables are a sign of amateurish design. This link should explain what I mean in detail: http://net.tutsplus.com/site-builds/from-psd-to-html-building-a-set-of-website-designs-step-by-step/
  15. It's a scope problem. You perform all that math, but don't actually return $total. You need to do: function add_it_all_up(/* argument list */) { //math here return $total; } Then, in the main code, assign that to another variable: $final_price = add_it_all_up(/* argument list */); Just putting 'return;' doesn't do anything. It merely exits the function. To return a value from the function, you need to explicitly return it in the function itself (return $total;) and, in the code that actually invokes the function, assign it to a variable for future use ($final_price = ...).
  16. What on earth does that mean? There's allot of great software written in Python. Not picking up the sarcasm if it's intended. But for example: http://www.hotscripts.com/ 18,201 PHP scripts vs. 141 Python scripts
  17. Can you show us your classes?
  18. In terms of the basics, just stick with the obvious. Encapsulation (visibility keywords (private, protected, public), determining which parts of the object should be publicly available to the rest of the system), inheritance, composition, inheritance vs. composition, and polymorphism. The kinds of things that make up the first few chapters of any OOP book. If possible, it may be in your best interest to give examples to your students in both Java and PHP. That would help illustrate that OOP concepts are applicable in a variety of different environments and languages. If you're having issues with PHP's OOP stuff, you should check out Matt Zandstra's book PHP 5: Objects, Patterns, and Practice. It's essentially a blend of J2EE Enterprise Patterns and the Gang of Four's Design Patterns..., but with examples written entirely in PHP. I doubt there's a better PHP-centric OOP book available.
  19. What do you know of OOP currently? And, how basic is this course going to be? Your initial post doesn't inspire confidence, and it's hard to point you in the right direction without knowing both your skill level and what the course is specifically geared towards.
  20. What I'd really like to see would be consistency between function names. A quick look at the function reference shows that a lot are multiple words jammed together without any separator, and all in lower case. Examples: datetime() htmlentities() htmlspecialchars() isset() phpinfo() A whole bunch of string manipulation functions... The majority, however, use an underscore to separate words: array_diff() in_array() is_int() mysql_real_escape_string() Trivial? Probably, but it's frustrating having to keep track of little language idiosyncrasies like this. A consistent naming scheme - which must be enforced by libraries/plugins/modules/whatever - is all I'm asking for.
  21. But, can it play Crysis?
  22. I would pay money for this. Seriously.
  23. The PHP check will be invoked anyway.... What does your HTML for the form look like?
  24. I don't know if you were talking to me or the OP, kickstart, but missing quotes was the cause of my error. So, code that works as the OP intended: <html> <head> <title>Blah</title> <style> div { border: 1px solid black; } </style> </head> <body> <div id="myDiv"></div> <div id="idRgt"></div> <button id="addDiv">Click to add new div</button> <input type="hidden" id="numDivs" value="0" /> </body> <script type="text/javascript"> var oButton = document.getElementById('addDiv'); var numDivs = document.getElementById('numDivs').value; oButton.onclick = addElement; function addElement(){ var mainDiv = document.getElementById('myDiv'); var newDiv = document.createElement('div'); var newDivId = 'my' + numDivs; var writeDiv = document.getElementById('idRgt'); writeDiv.innerHTML = "newDivId: " + newDivId + "<br/>"; newDiv.setAttribute('id', newDivId); newDiv.innerHTML = "Element Number: " + numDivs + "has been added! <button onclick='removeElement(\"" + newDivId + "\");'>Remove div: " + newDivId + "</button>"; mainDiv.appendChild(newDiv); ++numDivs; } function removeElement(divId){ var mainDiv = document.getElementById('myDiv'); var divRem = document.getElementById(divId); if (divRem){ mainDiv.removeChild(divRem); --numDivs; } } </script> </html>
  25. I've been trying to make a test script to show the OP how to do it, but I've run into a snag myself. I'm getting an odd scope error when trying to pass the id of one of the dynamically created divs to the removeElement() function. My test code is below: <html> <head> <title>Blah</title> <style> div { border: 1px solid black; } </style> </head> <body> <div id="myDiv"></div> <div id="idRgt"></div> <button id="addDiv">Click to add new div</button> <input type="hidden" id="numDivs" value="0" /> </body> <script type="text/javascript"> var oButton = document.getElementById('addDiv'); var numDivs = document.getElementById('numDivs').value; oButton.onclick = addElement; function addElement(){ var mainDiv = document.getElementById('myDiv'); var newDiv = document.createElement('div'); var newDivId = 'my' + numDivs; var writeDiv = document.getElementById('idRgt'); writeDiv.innerHTML = "newDivId: " + newDivId + "<br/>"; newDiv.setAttribute('id', newDivId); newDiv.innerHTML = "Element Number: " + numDivs + "has been added! <button onclick='removeElement(" + newDivId + ");'>Remove div: " + newDivId + "</button>"; mainDiv.appendChild(newDiv); ++numDivs; } function removeElement(divId){ alert(divId); var mainDiv = document.getElementById('myDiv'); var divRem = document.getElementById(divId); if (divRem){ mainDiv.removeChild(divRem); --numDivs; } } </script> </html> The error is: I can't see where the error is actually happening, however...I'm normally very careful with how I obtain my element references. Also, the actual div id isn't being passed into removeElement(). It's being created properly in addElement(), but the alert tells me that divId is actually the div itself ([Object HTMLDivElement]), rather than its id. Very odd. I think another pair of eyes are necessary, as I can't see the problem from where I sit.
×
×
  • 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.