Jump to content

jeffman

Members
  • Posts

    7,761
  • Joined

  • Last visited

Posts posted by jeffman

  1. Oops. Just noticed something. This might be new since I last put JS in a link. The whole window.open command ended up in my address bar. The content of my original window was obliterated and replaced with the return value of window.open. Changing the code to this fixed that: 'javascript:var x=window.open( etc. . . . But the best solution is probably not to use an <a> element at all. Use a <p> or a <span> and add an onclick handler.

  2. For city and address, there may be nothing you can do. Even in one country, there are many different ways to write an address. Your best bet is to make sure there is no HTML in the text, no javascript, and if you are saving this in a database, always prevent SQL injection. You can Google that.

  3. localStorage.myKey is just normal object syntax for JavaScript. It was the standard before we had methods like setItem and setAttribute. In Firefox, at least, it also works if you write localStorage['myKey'], whch is also normal object/array syntax. ("myDiary_" + TodaysDate) should work. To see if there is already data there, try something like this:

    var data = localStorage.getItem("myDiary_" + TodaysDate);

    If that key hasn't been defined, the getItem method should return "undefined" (Firefox does this) or something else that evaluates to false. It should not throw an error.

  4. New php with oops concepts available in the market and which is a little bit tough in programming for website.
    For what it's worth, creating your own objects in PHP is fairly simple and not required. It's not like some languages where every line of code must be embedded in an object. As to PHP's library objects, I find them conveniently organized and usually well explained. If an object has multiple levels of inheritance, you may have to look at several pages of the manual to find all the information you need.
  5. If it helps, both of these create the same result

    localStorage.setItem('myKey', 'myData');localStorage.myKey = 'myData';

    In each case, you can think of "myKey" as the key that points to the string "myData." I'm not sure what you mean by "a multi-part KEY." That's what I thought I was showing you when I mentioned JSON, but perhaps it's not.

  6. I don't know why you are interested in files. As far as I know, the W3C doesn't have a specification for implementing localStorage. Every browser will do it differently, and a single browser might do it differently on different platforms. Expecting certain filenames to be created seems like a waste of time. Maybe you should explain your goals more clearly. It's possible that what you want cannot really be done, or can be done using other tools, but I am not certain.

  7. This interested me so I played around. Local storage will only accept a string as data. So you need to be able to create a string of key-val pairs that you can parse. JSON is the perfect solution. Here's some code that shows a basic implementation.

    <!DOCTYPE html><html>    <head>        <meta http-equiv="content-type" content="text/html;charset=UTF-8">        <title></title>        <script type="text/javascript">            function init () {                document.getElementById("button1").onclick = function () {                    var obj = new Object;                    obj.key = "val";                    localStorage.test = JSON.stringify(obj);                }                document.getElementById("button2").onclick = function () {                    var newObj = JSON.parse(localStorage.test);                    alert(newObj.key);                }            }            window.onload = init;        </script>    </head>    <body>        <div>            <input type="button" value="Set" id="button1">            <input type="button" value="Alert" id="button2">        </div>    </body></html>

  8. What you really want is for the document to have an element, like a div or something, and update its innerHTML property every time the loop iterates. The div should have an id so you can get a reference to it using document.getElementById().

  9. In strongly typed languages, you declare variables at the top of functions so that the compiler can allocate memory. PHP is weakly typed and allocates memory dynamically, so this type of declaration is not required. As others have pointed out, there may be practical reasons for naming/defining a variable before it is used, but this is not the same as a requirement.

  10. Well, I can. I sort of hate to, but I tested this and it "works." I suggest doing a View Source before and after you click the text to execute the function.

    <!DOCTYPE html><html>    <head>        <script type="text/javascript">            function writeMe() {                var s = "<pre>hi";                s += "\n";                s += "John";                s += "\t\t";                s += "Smith </pre>";                document.write (s);                document.close();            }        </script>    </head>    <body>        <p onclick="writeMe()">Click me</p>    </body></html>

×
×
  • Create New...