Why does one script cancel the other script?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • BaseballGraphs
    New Member
    • Sep 2010
    • 75

    Why does one script cancel the other script?

    Hello,

    I have two pieces of javascript on my page. One of the javascript codes allows a person to place their cursor in a text field and the default writing in the text field will then disappear. Here is the code for this javascript:
    Code:
    <script>
    
    var active_color = '#000'; // Colour of user provided text
    var inactive_color = '#ccc'; // Colour of default text
    
    $(document).ready(function() {
      $("input.default-value").css("color", inactive_color);
      var default_values = new Array();
      $("input.default-value").focus(function() {
        if (!default_values[this.id]) {
          default_values[this.id] = this.value;
        }
        if (this.value == default_values[this.id]) {
          this.value = '';
          this.style.color = active_color;
        }
        $(this).blur(function() {
          if (this.value == '') {
            this.style.color = inactive_color;
            this.value = default_values[this.id];
          }
        });
      });
    });
    </script>
    The second piece of javascript that I am using on this page allows me to show and hide various information. Here is the script for this portion:
    Code:
    <script>
    function doIt() {
    $("#rankings").show("slow");
    }
    $("#button").click(doIt);
    $("#button").click(function () {
    $("#playerstats").hide(2000);
    });
    
    function doItAgain() {
    $("#playerstats").show("slow");
    }
    $("#button1").click(doItAgain);
    $("#button1").click(function () {
    $("#rankings").hide(2000);
    });
    </script>
    While the show/hide javascript works, the javascript that makes default text in a text field disappear does not work.

    If you have some idea as to why the javascript isn't working please let me know! Thanks.
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    are there any messages in the Error Console?

    Comment

    • JKing
      Recognized Expert Top Contributor
      • Jun 2007
      • 1206

      #3
      Could you post the related html that goes along with these scripts?

      Comment

      Working...