Jump to content

nogray

Members
  • Posts

    930
  • Joined

  • Last visited

Posts posted by nogray

  1. Well, you would need to reset all the class names before you start validating the form, for example add "clear_errors()" in top of the validation to remove all the invalid classes. If you have a URL, I can help looking up the problem.

  2. You posted the part that works, but not the part that reset the class names. It's usually done with an if else statement (not sure what it didnt' work for you), but here is an example

    if (document.registration_form.name.value == "") {
        document.getElementById("name_blank").style.display = "inline";
        valid = false;
        document.registration_form.name.className = "invalid_form";
    }
    else {
        document.getElementById("name_blank").style.display = "none";
        document.registration_form.name.className = "valid";
    }
    

  3. The reason why the author added two images is because the height issue with fluid layout. If you assign a background color to the news and side divs, and the content was too long. The news and side background won't extend down with the content. You can try to remove the background images and assign background colors to the news and side divs, add extra content and resize the window to see the effect.

     

    If you want the same style layout (three color background to extend all the way for the three divs regardless of content and size of window) you would need to use the same images width. You can resize the height to 1px if that will save some kb.

     

    P.S. I never read the book, but got the author intentions from your post and the sample you posted

  4. This could be a security zone conflict in your browser setting. For example, if you have a page on your PC, or a trusted security zone and you click on a link to a third part site or try to open a third party site that is in different security zone (e.g. default zone), IE will open it in a new window.

  5. You can add an onchange event and set the div background color style to that value

     

    e.g.

    <input type="text" onchange="document.getElementById('my_div_id').style.backgroundColor = this.value;" /><div id="my_div_id"> </div>

     

    This code won't validate the user input and an invalid color will cause an error.

  6. Why is this in the middle of the buttons </form>, it looks like your code will not validate and the </form> will add a line break in IE. close the form where it should (not in the middle of the div between the buttons).

  7. Try this,

    <!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>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Snooker Brackets</title>
    <style type="text/css">
    .base {
    background-color: #CF6;
    height: 50px;
    width: 400px;
    }
    .player1 {
    background-color: #000;
    height: 50px;
    width: 400px;
    color: #FFF;
    }
    .player2 {
    background-color: #fff;
    height: 50px;
    width: 400px;
    }
    .player1over {
    background-color: #009;
    height: 50px;
    width: 400px;
    color: #FFF;
    }
    .player2over {
    background-color: #C9C;
    height: 50px;
    width: 400px;
    }
    .class {
    background-color: #C9C;
    height: 50px;
    width: 400px;
    }
    </style>
    <script>
    function change_class(player, cls){
    var my_ids = ['_div2', '_div3', '_div4', '_div5', '_div6'];
    for (var i=0; i<my_ids.length; i++){
    	document.getElementById(player+my_ids[i]).className = cls;
    }
    }
    </script>
    </head>
    <body style="margin: 0pt;">
    <div class="base" id="player1_div1" onmouseover="change_class('player1', 'base player1over');" onmouseout="change_class('player1', 'base player1');">Player 1</div>
    <div class="base" id="player2_div1" onmouseover="change_class('player2', 'base player2over');" onmouseout="change_class('player2', 'base player2');">Player 2</div>
    <div class="base player1" id="player1_div2">Player 1</div>
    <div class="base player2" id="player2_div2">Player 2</div>
    <div class="base player1" id="player1_div3">Player 1</div>
    <div class="base player2" id="player2_div3">Player 2</div>
    <div class="base player1" id="player1_div4">Player 1</div>
    <div class="base player2" id="player2_div4">Player 2</div>
    <div class="base player1" id="player1_div5">Player 1</div>
    <div class="base player2" id="player2_div5">Player 2</div>
    <div class="base player1" id="player1_div6">Player 1</div>
    <div class="base player2" id="player2_div6">Player 2</div>
    </body>
    </html>
    

     

  8. JavaScript strings can't have multible lines and probably your JS code looks something like this

    sometextarea.value = "line 1 bla bla bla
    
    line2 bla bla bla 
    
    line 3 bla bla bla "
    

     

    You can replace the carriage returns with \n and it will show up as carriage returns in the textarea

  9. You need to change your onmouseover and onmouseout events to call the function, e.g.

    onmouseover="change_class('player1', 'player1over');" 
    

    Also you would need to change this line

    var my_ids = ['_div1', '_div2'];
    

     

    to include the other divs (up to 6 from your code).

  10. you can use document.getElementsByTagName('tag name here') to get an array of the elements. e.g.

    HTML
    <ul id="my_list"><li>message 1</li><li>message 2</li></ul>
    
    Script
    var ul = document.getElementById('my_list');
    var li_arr = ul.getElementsByTagName('li');
    
    for (var i=0; i<li_arr.length; i++){
        // do something
    }
    
    

     

    If you are going to remove or add elements from the parent, you would need to use a while loop instead of for loop since the length property will change.

  11. In your case, I'll make a function that will check the value and return the integer or a 0;

     

    e.g.

    function my_parse_int(val){
        val = parseInt(val, 10);
        if (isNaN(val)) return 0;
        return val;
    };
    
    ... change the onchange event to
    onchange="document.getElementById('total').value = (my_parse_int(document.getElementById('f1').value) ....) *1.5;

  12. First you would need to add a unique id to all your div tags (but they should all have a common part to match the player)

    e.g.

    <div class="..." id="player1_div1"></div><div class="..." id="player1_div2"></div>...

    Than, create a javascript function that change the class name for all the ids listed,

    e.g.

    <script>
    function change_class(player, class){
        var my_ids = ['_div1', '_div2'];
        for (var i=0; i<my_ids.length; i++){
            document.getElementById(player+my_ids[i]).className = class;
        }
    }
    </script>
    

    and your onmouseover and onmouse out will call the function with the appropriate variables.

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