clearing a textbox and filling with a function

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

    #1

    clearing a textbox and filling with a function

    If I fill out the textfields properly with Name, Email etc in a row it
    is fine. But if I fill out, for example, my Name, then tab twice, it
    clears my entered value. How do I stop this?

    All I want the script to do is that when the cell is blank or
    whitespace, put the necessary text in the field, else, continue as
    normal.


    --- HTML Extract
    <td width="74%">
    <input name="name" type="text" class="textbox" id="name"
    onMouseOver="th is.style.backgr oundColor = 'CDEDDD';"
    onMouseOut="thi s.style.backgro undColor = 'E2E2E2';"
    onfocus="this.s tyle.background Color = 'CDEDDD'; this.style.colo r =
    '000000';textua l(name,this.val ue);"
    onblur="this.st yle.backgroundC olor = 'E2E2E2'; this.style.colo r =
    '000000';textua l(name,this.val ue);"
    value="Enter Name" size="30"></td></tr>
    -- END Extract


    function textual(element ,text) {

    var name,company,em ail,worknumber, homenumber,quer y

    // If the Field contains the default text, clear it ready for new text
    if (text=="Enter Name") { document.form1. name.value = "" }
    if (text=="Enter Company Name") { document.form1. company.value = "" }
    if (text=="Enter Email Address") { document.form1. email.value = "" }
    if (text=="Enter Work Number") { document.form1. worknumber.valu e = ""
    }
    if (text=="Enter Home Number") { document.form1. homenumber.valu e = ""
    }
    if (text=="Enter your query here...") { document.form1. query.value =
    "" }

    // If the Field is blank, re-write the contents
    if (text=="") {
    if (element="name" ) { document.form1. name.value = "Enter Name" }
    if (element="compa ny") { document.form1. company.value = "Enter
    Company Name" }
    if (element="email ") { document.form1. email.value = "Enter Email
    Address" }
    if (element="workn umber") { document.form1. worknumber.valu e = "Enter
    Work Number" }
    if (element="homen umber") { document.form1. homenumber.valu e = "Enter
    Home Number" }
    if (element="query ") { document.form1. query.value = "Enter your query
    here..." }
    }

    }
  • Michael Winter

    #2
    Re: clearing a textbox and filling with a function

    On 19 Apr 2004 06:31:26 -0700, RelaxoRy <relaxory@postm aster.co.uk> wrote:
    [color=blue]
    > If I fill out the textfields properly with Name, Email etc in a row it
    > is fine. But if I fill out, for example, my Name, then tab twice, it
    > clears my entered value. How do I stop this?
    >
    > All I want the script to do is that when the cell is blank or
    > whitespace, put the necessary text in the field, else, continue as
    > normal.[/color]

    [snipped code]

    You can modify your code to be considerably smaller:

    function clearInput( control ) {
    if( control.default Value == control.value ) {
    control.value = '';
    }
    }

    function restoreInput( control ) {
    if( '' == control.value ) {
    control.value = control.default Value;
    }
    }

    <input ... onfocus="clearI nput(this)" onblur="restore Input(this)">

    Hope that helps,
    Mike

    --
    Michael Winter
    M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

    Comment

    • relaxory

      #3
      Re: clearing a textbox and filling with a function

      Ahhh of course!
      It worked a treat. Must keep remembering everything is recorded.

      Thanks.

      --
      The way of the goat is many.

      *** Sent via Developersdex http://www.developersdex.com ***
      Don't just participate in USENET...get rewarded for it!

      Comment

      Working...