Results 1 to 5 of 5

Thread: form feild value's

  1. #1
    Join Date
    Sep 2006
    Location
    Liverpool UK
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default form feild value's

    Evening all.

    Im in the proccess of building a form for a site, and would like to know how to make the initial valus dissapear when a user goes to submit text into each box.

    Ie: the name box has 'name' in it but at the mo i have to delete it before filling in details.

    Many of you may wonder why i'm not using <label for=""> to place outside the text areas, and although I have used these on previous sites im after something different on this one.

    Please advise.

    geoffb

  2. #2
    Join Date
    Oct 2006
    Posts
    75
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    first thing that comes to mind for me is javascript, essentially the same idea as what i have on my site for my buttons:

    in the html define the default value, then use onmouseover to run a javascript that will turn the default value into ""

    i'll get u some code, when i get home, assuming this works lol, just a theory

  3. #3
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by geoffb
    Im in the proccess of building a form for a site, and would like to know how to make the initial valus dissapear when a user goes to submit text into each box.
    One can alter the value of a control when it receives focus, but it's not usually a good idea. Playing with input like that can just confuse the visitor - not everyone may understand why a value just disappeared.

    Many of you may wonder why i'm not using <label for=""> to place outside the text areas, and although I have used these on previous sites im after something different on this one.
    Before you continue, ask yourself: if the value that presumably indicates the purpose of that control is gone, will the visitor still understand, upon reviewing the form, what each of the given responses where meant to represent? If it is not abundantly clear, I would urge you not to pursue this.

    Code:
    function clearDefault(control) {
        if (control.value == control.defaultValue) control.value = '';
    }
    HTML Code:
    <input type="text" value="..." onfocus="clearDefault(this);">
    You may need to be careful here to ensure that the visitor would not want to use the default value as their response.

    Mike
    Last edited by mwinter; 10-19-2006 at 01:43 PM. Reason: Typo in code

  4. #4
    Join Date
    Oct 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I've done it even in a simpler way

    <input value="BLABLABLA" type="text" id="username" onFocus="if (this.value == 'BLABLABLA') this.value = 'whateverer you want here';">

    et voilá....everytime it is with 'default' value it changes to '<whatever_you_want_even_nothing_if_you_want_to>'


    if you need something else.....i think it's a easy turnaround from this point

    /*
    if(if.needed == false)
    remove(if);
    */ (LOOOL)



    BIG UP
    zuguz

  5. #5
    Join Date
    Dec 2004
    Location
    UK
    Posts
    2,358
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by zuguz
    I've done it even in a simpler way
    Not to dash your enthusiasm, but how is what you've posted simpler? It would seem that the OP intends to do this with several controls, which would mean code duplication with your approach. It may also require maintainence: if the default value changes, the event listener will also need to be changed.

    Mike

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •