Changing fontcolor in formfield

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Joe

    #1

    Changing fontcolor in formfield

    having this script:
    -------------------------------------------------------------------
    <script language="JavaS cript" type="text/javascript">
    <!--
    function isanumber()
    {
    var antal = document.insert .antal.value;
    var isanumber = /^[0-9]+$/;
    if(isanumber.te st(antal))
    {
    ready = true;
    }
    else
    {
    document.forms. insert.antal.fo cus();
    document.forms. insert.antal.va lue = "insert a number";
    ready = false;
    }
    return ready;
    }
    -->
    </script>
    -------------------------------------------------------------------

    I would like to change the fontcolor in the inputfield to red when the
    function returns FALSE.Can this be done, and if, how??

    Joe


  • Janwillem Borleffs

    #2
    Re: Changing fontcolor in formfield


    "Joe" <amplifymysoul@ hotmail.com> schreef in bericht
    news:3f0331bd$0 $76088$edfadb0f @dread11.news.t ele.dk...[color=blue]
    > having this script:
    > -------------------------------------------------------------------
    > <script language="JavaS cript" type="text/javascript">[/color]
    ....[color=blue]
    > </script>
    > -------------------------------------------------------------------
    >
    > I would like to change the fontcolor in the inputfield to red when the
    > function returns FALSE.Can this be done, and if, how??
    >[/color]

    <html>
    <head>
    <title> New Document </title>
    <script type="text/javascript">
    function isanumber() {
    var field = document.insert .antal;
    var antal = field.value;
    var isanumber = /^[0-9]+$/;
    var ready = isanumber.test( antal);

    if (!ready) {
    field.focus();
    field.value = "insert a number";
    field.style.col or = 'red';
    // Optional; Change the font color back to black when new
    // data is entered into the field
    field.onkeypres s = field.onpaste = function () { this.style.colo r =
    'black' }
    }
    return ready;
    }

    </script>
    </head>

    <body>
    <form onsubmit="retur n isanumber()" name=insert>
    <input type=text name=antal><inp ut type=submit>
    </form>
    </body>
    </html>


    JW



    Comment

    • Joe

      #3
      Re: Changing fontcolor in formfield

      Thanx, that really did the trick

      Joe


      "Janwillem Borleffs" <jwb@jwbfoto.de mon.nl> wrote in message
      news:3f034f75$0 $28899$1b62eedf @news.euronet.n l...[color=blue]
      >
      > "Joe" <amplifymysoul@ hotmail.com> schreef in bericht
      > news:3f0331bd$0 $76088$edfadb0f @dread11.news.t ele.dk...[color=green]
      > > having this script:
      > > -------------------------------------------------------------------
      > > <script language="JavaS cript" type="text/javascript">[/color]
      > ...[color=green]
      > > </script>
      > > -------------------------------------------------------------------
      > >
      > > I would like to change the fontcolor in the inputfield to red when the
      > > function returns FALSE.Can this be done, and if, how??
      > >[/color]
      >
      > <html>
      > <head>
      > <title> New Document </title>
      > <script type="text/javascript">
      > function isanumber() {
      > var field = document.insert .antal;
      > var antal = field.value;
      > var isanumber = /^[0-9]+$/;
      > var ready = isanumber.test( antal);
      >
      > if (!ready) {
      > field.focus();
      > field.value = "insert a number";
      > field.style.col or = 'red';
      > // Optional; Change the font color back to black when new
      > // data is entered into the field
      > field.onkeypres s = field.onpaste = function () { this.style.colo r =
      > 'black' }
      > }
      > return ready;
      > }
      >
      > </script>
      > </head>
      >
      > <body>
      > <form onsubmit="retur n isanumber()" name=insert>
      > <input type=text name=antal><inp ut type=submit>
      > </form>
      > </body>
      > </html>
      >
      >
      > JW
      >
      >
      >[/color]


      Comment

      Working...