Jump to content

jesh

Members
  • Posts

    2,293
  • Joined

  • Last visited

Everything posted by jesh

  1. jesh

    forum

    You may be able to use javascript for various parts of the forum, but chances are that you'll need some type of server-side technology for this: PHP, ASP.NET, CF, etc. You might also look into using a prebuilt forum that you can simply plug into your site. I'm sure others here have some good suggestions for those.
  2. I think you have some strange (non-printable) characters in there that the browser is having a hard time dealing with. For example, when I try to view your page's source in Firefox, select all, copy, and then paste it into a notepad document, it stops after the first color attribute (in the #content declaration).Also, I get these errors in the javascript console:Error: Expected end of value for property but found ''. Error in parsing value for property 'color'. Declaration dropped.Source File: http://appledore.jacinthe-pirate.com/Line: 16Did you, by chance, copy the color codes from some image editing program and then paste them into your source? In any case, try deleting the color codes and type in the code manually to overwrite the strange (invisible) characters.
  3. But you do if you don't know the filename that you want until runtime. Normally you'd use server-side code to do this:<script type="text/javascript" src="<%=ScriptFileName%>"></script> But if you aren't using server-side technologies, you have to rely on javascript. J Winey, I'm pretty sure it works, but, like you, I haven't tested it extensively.
  4. Are you talking about Stored Procedures? http://dev.mysql.com/doc/refman/5.0/en/sto...procedures.html
  5. I don't personally know of any existing code that you can use (I'm sure it's out there, I just don't know where), but this may help get you started:<html><head><script>function moveRight(){ var leftSelect = document.getElementById("leftSelect"); var rightSelect = document.getElementById("rightSelect"); var leftOptions = leftSelect.options; var count = leftOptions.length; var option; for(var i = count-1; i >= 0; i--) { option = leftOptions[i]; if(option.selected) { leftSelect.remove(i); rightSelect.add(option, null); } }}</script><style>select { height: 100px; }</style></head><body><select id="leftSelect" multiple="multiple"><option value="1">1</option><option value="2">2</option><option value="3">3</option><option value="4">4</option><option value="5">5</option></select><select id="rightSelect" multiple="multiple"></select><button onclick="moveRight();">moveRight</button></body></html> Basically, you'll loop through all the options (backwards) in one of the selects and check to see if the option was selected. If so, add it to the other select and remove it from this one. The function above could probably be generalized so that you could use the same function for moving options in either direction, but I'll leave that up to you.I hope this helps.
  6. jesh

    id tag

    It wouldn't work because, in the HTML DOM, the input element doesn't have a document element. There are (at least) three ways to accomplish what you are trying: // Option 1var a = document.getElementById("tfield");document.write(a.value);// Option 2var a = document.getElementById("tfield").value;document.write(a);// Option 3document.write(document.getElementById("tfield").value); Check out the HTML DOM tutorial: http://www.w3schools.com/htmldom/default.asp
  7. Hmm, rather than: if(name == null) You might try if(!name) This code works as you describe: var name = prompt("What is your name?");while(!name || name.toLowerCase() != "megan"){ name = prompt("Come on, say 'Megan'.");}alert("Hello, " + name); The !name is sort of like an "is set" test. If a variable is set, it will return true. If it is not set, it will return false. So ! (which is the "not" operator) in front of the variable name will be true if it is not set and false if it is.
  8. Other than your VBScript/ActiveX stuff there, the only way to browse the local file system is to use the input type="file". There may be, however, a way to hide the text box and just have a button. This article may help:http://www.quirksmode.org/dom/inputfile.html
  9. You could always do something like this: <a href="mypage.html?myvariable=myvalue">Click Me</a>
  10. jesh

    Boxing elements?

    There are no gaps between the h1 and h4 elements when you do it like this (i.e. the borders touch): <html><head><style type="text/css">h1, h4 { border: 1px solid red; margin: 0px; }</style></head><body><h1>TEST</h1><h4>test</h4></body></html> There is, however, some padding around each element that you may be able to adjust using padding or line-height.
  11. Also, with an IDE (e.g. VisualStudio), I can type Re<TAB>.Red<TAB>("http://www.mysite.com"); rather than Response.Redirect("http://www.mysite.com"); because the IDE lists a dropdown menu of possible classes, members, etc. that match what I am typing. You can't get that with a plain text-editor.
  12. jesh

    30 day timeout

    Ah, but to get the value from the database, you'll need server-side technologies - even using AJAX.
  13. Actually, thanks to this post (http://w3schools.invisionzone.com/index.php?showtopic=9628) I now understand one reason you'd want to use a for-in loop. It comes in handy if you need to build a clone method for an object. You can iterate through all the members in the object without having to know what those members are. With the typical for loop, you'd have to know what members an object had before you could iterate through them.
  14. 1: As an exercise, I once made a function which would display the date (and any other message I wanted) using an LCD image that I created. It used a single image that had all of the characters in a single row in a very specific order. I then would parse the string, one character at a time, to decide what the unicode value was for that character and then use that data to determine the exact location of the letter in my image so that I could use it as the background image for a span element. For example, if each letter in my image was 16 pixels wide, and the ascii code was 97 ("a"), I would then know that I needed to display the image that began at 16 * (97 - 32) pixels from the left. (I started with the space character " ").2: I don't think those are part of any W3C standard. I would avoid those methods. Use the HTML DOM instead.3: Check out the "typeof" function.4: There are a couple problems there. First, you have a semi-colon after the closing curly brace in the do-while loop. It should be: do{}while(test) Also, you declare the str variable inside the do-while loop. Once that loop ends, that variable ceases to exist so your else if (str == null) fails.5: Same problem as above. You have semi-colons after your closing curly braces: if (conf == true){ document.location.href=" http://www.google.com/"};
  15. 1: Hmm. I don't know why that function returns anything, let along returning true. I know with other event handlers, if you return false then the action ceases for that element. For example: <script type="text/javascript">function handleSubmit() // a.k.a. validate form{ return false;}</script><form id="myForm" action="GET" onsubmit="return handleSubmit();"></form> If the handleSubmit function returns true, then the submit action takes place and the form is submitted. If, on the other hand, it returns false, the form never submits. Perhaps returning true in an error handler allows other error handlers - if they are defined - to also handle the error.Maybe someone else can answer this one.2: Well, if you had some type global error handler in your application, then you could throw an exception when something happens to an object (e.g. a method is called before a certain property is assigned?) and then the global error handler could see what the message was and decide which action to take. I tend to do object-specific error handling within the object itself. At times, when I use throw to throw an exception, it's mainly for debugging, but I seem to remember other times when it came in handy.3: That I don't know. I tend to only use the javascript alerts for debugging. If I want a more substantial alert to be made to the client, I'll either send the user to an error page, or use something like the ThickBox to display the alert.
  16. 2: The only thing I'd add here is that there is no indication to the user that s/he is doing anything wrong and s/he may feel that your code is "broken" because it keeps asking for a name. :)3: No. I believe there was a way to do it in VBScript, but that only works in IE so there's really no point unless you are developing for an IE-only audience. You might look into using something like ThickBox (do a Google search for that) which can emulate modal windows (like javascript confirm). If you used those, you can make the window look like anything you want. :)4: The keywords continue and break are used in loops. There's really no point in using a continue in an if statement unless that if statement is in a loop. It's used to skip the rest of the loop, but to still continue to iterate through the loop. var i, item;var count = myArray.length;for(i = 0; i < count; i++){ item = myArray[i]; if(item == true) { continue; } alert("It's false!"); } 5: For an example, look at the code above. The variable "i" doesn't necessarily need to be declared outside of the for loop, however, because it is, it can then be used after the for loop ends. Imagine if instead of using the continue, we used break. Then, if we check "i" after the loop ends, we can tell which element of the array caused the loop to end. "item" is declared outside of the loop because it is never a good idea to declare variables inside of a loop. If you declare it once outside, then you simple overwrite the values each time through the loop. If you declare it inside the loop, the computer has to set aside memory, use the value, then get rid of the memory, then, next time through the loop it has to set aside memore, use the value, then get rid of the memory. It's more effecient to do it that way. Also, with the count variable there. If we hadn't used count to get the length of the array before iterating through the loop, then each time through the loop we'd have to check the size of the array to see if we need to continue. This isn't much of a big deal in this case, but imagine a page with 100 links and you wanted to iterate through each of them: for(var i = 0; i < document.getElementsByTagName("a").length; i++){} vs. var theAs = document.getElementsByTagName("a");var count = theAs.length;for(var i = 0; i < theAs.length; i++){} In the first example, each time through the loop you'd have to get the document object. Then you'd have to traverse through the document object to get all the a tags. Then you'd have to traverse through that array to get the length of the array. This would all need to be done 101 times. That would be MUCH slower than the second method. 6. I believe that is just a matter of style. The only thing I can add here is that when you use && to check more than one item in an if statement, only the first item needs to be false for the whole thing to be false. For example: var test = false;if(test == true && NonExistentVar == false){}else{ alert("Howdy!");} That snippet won't throw any errors because "NonExistentVar == false" is never evaluated because test == false. So, using && in an if statement can sometimes be more efficient than using multiple if statements.Same thing goes with ||. If the first item is true, the rest of the test doesn't need to happen.
  17. jesh

    questions

    question 1 : I'm not aware of a "close" event in the HTML DOM. Are you thinking about the "unload" event?question 2: Yes, you can use the HTML DOM. Using your form as an example, if you give your text input an id of "bob", you can access its value like this: var bob = document.getElementById("bob").value; question3: To call a function from the body, you could do it like this: <script type="text/javascript">function a(){ a = 0; while(a < 100) { document.write(a++); }}</script></head><body><script type="text/javascript">a();</script> question 4: Skemcin has a window.open function listed here: http://w3schools.invisionzone.com/index.php?showtopic=9500
  18. jesh

    30 day timeout

    I'm guessing you're going to need some server-side code to accomplish this. If the encryption algorithm is done in javascript, anyone with a passing knowledge of javascript will be able to crack it.
  19. Yeah, most of the time when you are using javascript to do various things with a webpage, you are actually using the HTML DOM. I'd guess that about 70% of client-side scripting (if not more) is HTML DOM rather than javascript. Go through the tutorial here: http://www.w3schools.com/htmldom/default.asp
  20. Or, if you don't want to use type="button", you'll have to return false on the onsubmit event so that the form doesn't submit:<input type="submit" name="S1" value="Find distance" onclick="distance(); return false;" /> But I like MrAdam's solution better.
  21. Any chance you can post your solution (or the link to it) in case someone else comes across this post with the same problem in the future?
  22. Try this: http://www.irt.org/script/878.htmThey use the for-in loop to iterate through the properties of the object and copy them into the new object. You don't need to know the propery names in order to do this.
  23. I can't remember. I generally try to prevent ENTER from submitting the form. However, I believe that if you have more than one form element (i.e. a username and password field) then you'll have to use javascript to submit the form on ENTER. If AbstractApproach's method doesn't do it, try something like this:Javascript function CheckForEnter(e){ e = (e) ? e : window.event; var charcode = (e.which) ? e.which : e.keyCode; if (charcode == 13) // 13 is ENTER { // submit the form }} HTML: <input type="text" id="login" value="" /><input type="password" id="password" value="" onkeydown="CheckForEnter(event);" />
  24. I think you put [\code] rather than [/code].The for-in loops appear to iterate through all the elements of an object whereas the typical for loops iterate using in indexer (typically it's called "i") like in Chocolate570's example.In the try-it example (http://www.w3schools.com/js/tryit.asp?filename=tryjs_array_for_in), the x takes on the value of 0 in the first loop, 1 in the second, and 2 in the third as it iterates through the array.However, like ViolaGirl mentioned, if you had this:var xvar mycars = new Array()mycars[0] = "Saab"mycars[2] = "BMW"mycars[1] = "Volvo"for (x in mycars){document.write(mycars[x] + "<br />")} The first time through the loop, x would be 0, the second time it would be 2, and the third time it would be 1.
  25. jesh

    Google Maps Pop-up

    Sometimes, when my browser is around 900px wide or less, rather than appearing next to the W3Schools logo, the banner drops down and covers that menu. I have to keep my browser wider than that to prevent it from happening. And it only happens on certain banners.Maybe you are experiencing the same thing.
×
×
  • Create New...