Jump to content

Webworldx

Members
  • Posts

    347
  • Joined

  • Last visited

Posts posted by Webworldx

  1. <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>

    :)

  2. 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

  3. 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.

  4. <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?

  5. 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'.

  6. 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 :)

  7. 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.

×
×
  • Create New...