Jump to content

Webworldx

Members
  • Posts

    347
  • Joined

  • Last visited

Everything posted by Webworldx

  1. Just give the table you want to show/hide an id, then use:document.getElementById('my_table').style.display="inline";or .. ="none";in a function to hide it again.
  2. Webworldx

    string search

    <script type="text/javascript">var what_im_searching_for = "w3schools";var my_search = new RegExp( what_im_searching_for , "i");var str="Visit W3Schools!"document.write(str.search( my_search ))</script>
  3. Hi there,Think about the way it compiles the code if you wrote it in a single line:if(something){ do_something() } if(something){ do_something() }var x var y var x--------------notice in the first one, you can add the semicolons if you really wanted to, but it makes no difference - it sees the if statement, reads between the parenthesis then moves to the next if statement. With the second line, you need the semicolons to distinguish that you're creating a variable x, then moving to the next statement and declaring the variable y .. and so on.It's not exactly bad to add the semicolons, but they're not a necessity, so why bother? :)Hope that helps
  4. Err..quite simply, if you return false in the error, it'll go on and treat it like an error and show you the browser's error exception box too after yours.
  5. Not really, since the code has has in his external file starts writing to the document immediately, but I see what you're saying vchris. Ideally, your external file should be full of functions that you can reference later in your code.
  6. Remove the <script..... and </script> lines from the external file
  7. What type of "software" is this? I'm guessing it's more than just a small piece of javascript...?
  8. <script type='text/javascript'>function pick_random_cell(rand, txt){ if(iTD[rand].innerHTML != ""){ pick_random_cell( Math.floor(Math.random() * 16) , txt ); } else { iTD[rand].innerHTML = (txt + 1); iTD[rand].style.fontWeight = "bold"; }}function populate_table(){ for(i=0;i<16;i++){ pick_random_cell( Math.floor(Math.random() * 16), i ); }}</script><table id='myTable' border='1' cellspacing='0' cellpadding='5'> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr> <tr><td></td><td></td><td></td><td></td></tr></table><script type='text/javascript'>var iTD = document.getElementById('myTable').getElementsByTagName('TD');populate_table();</script> How's that?
  9. getElementsByClassName is overkill imo, and encourages bad programming techniques.
  10. It just says "navigate up from the current node to the target node, stop when you're there and return the target node".
  11. aspnetguy, yeah, I know what you mean - but I have faith that IE8 will support the ECMAv4 revisions by the end of next year, it'd be silly not to really, especially with the current JS1 bugs and need for updates.Have you tried watch()? It's not great, and obviously you could just build an unwatch() over it, but combined with the others, it's another layer the person needs to get past before modifying your 'constant'.
  12. Constants are coming in JS2 aspnetguy
  13. It's a bit abstract, but say you were at the foot of the tree in a span tag inside a table, and you wanted to color the whole row (TR) that the span was in, then you could use ascendDom( mySpan, 'TR' ) to get there. It's a bit-script really.
  14. Webworldx

    JavaScript

    add "return false;" into your check and it won't carry out the click. Ideally you want to be checking the null value server side too though.
  15. Well you choose a target node, and it goes up the DOM tree until it finds it, or it gets to the top level (html).
  16. Webworldx

    Pls help me

    Yes, just simply create an array in the array: var x = [];x[0] = [ 0 , 1 , 2 ]x[1] = [ 1 , 2 , 3 ]x.......
  17. Well, just if you don't send a tag that can have a value attribute like er.. <input id="fridge" value="" /><b id="fridge2"></b><script type='text/javascript'>alert( document.getElementById('fridge').value == null );alert( document.getElementById('fridge2').value == null );</script> Input does have a value attribute by default (whether you include it in your tag or not), so it'll come up "false", but B doesn't by default, so it'll come up true in the second message box.It's a useful error catcher in case you send the wrong object into your function
  18. I meant half screen width, sorry - was typing fast half avail width, half popup window
  19. Hi there,If you've ever played with VB, you'd have come across this, but think of it as.. function the_name ( arg1, arg2, an_object ){ with(an_object){ style.color="#FF0000"; innerHTML = "Something"; style.fontWeight="bold";}} The with just saves you writing an_object multiple times, so the code could be expanded to: function the_name ( arg1, arg2, an_object ){ an_object.style.color="#FF0000"; an_object.innerHTML = "Something"; an_object.style.fontWeight="bold";} In the case of the example, say you had<input id="my_field" value="Some Value">you could do: <script type='text/javascript'>//Get the selected input tag and put it in a variable as an objectvar myField = document.getElementById('my_field');validate_required( myField , "Error with field" );</script> And it would perform checks on the object's value, see if it was null or blank, and show the "Error with field" alert if so.
  20. document.write("<a href='" + urlsarray[x] + "'>" + urlsarray[x] + "</a><br />");
  21. Dead horizontal is screen.width minus half the size of your popup window. (or availWidth if you want to be picky)
  22. Webworldx

    RegExp

    Just personal preference for me.
  23. http://alexking.org/blog/2003/06/02/insert...ing-javascript/
×
×
  • Create New...