• 0

Values in forms


Question

I have a public blog in which visitors can leave comments using a form. However, some visitors leave the name/nick field empty, which ruins my design. I don't wish to force people into entring his or her name, but I don't want it to be left blank either. In other words, I want the name to be filled with for example "Your name" until the visitor clicks the fiels do type down his own name.

Currently I'm using the code below, but for it to take effect one has to click the field one time and the prefilled form kicks into place, which kind of ruins the whole idea... I want it to be there all the time, until the visitor types something else in.

<input type="text" name="author" class="commentformstyle" value="Enter your name" 

onblur="if(this.value.length == 0) this.value='Enterr name';" onclick="if(this.value == 'Enter your name') this.value='';" 

size="42" maxlength="255">

Or is it just me? Please try it out at ottoman.blogg.se

Thanks in advance

Link to comment
https://www.neowin.net/forum/topic/663094-values-in-forms/
Share on other sites

2 answers to this question

Recommended Posts

  • 0
  Borbus said:
Using javascript to validate user input is a very bad idea. Check the length on the server side and replace it with something accordingly. I would have just designed it in such a way that it breaks gracefully when optional user input is not present, though.

Thanks for the reply!

yeah, i've also thought about that and i think i'll go with redesigning the comments section if noone has ha better idea. Using JS is out of the question then as i'd like to learn how to do things the right way from the beginning.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Posts

  • Recent Achievements

    • First Post
      Gladiattore earned a badge
      First Post
    • Reacting Well
      Gladiattore earned a badge
      Reacting Well
    • Week One Done
      NeoWeen earned a badge
      Week One Done
    • One Month Later
      BA the Curmudgeon earned a badge
      One Month Later
    • First Post
      Doreen768 earned a badge
      First Post
  • Popular Contributors

    1. 1
      +primortal
      630
    2. 2
      ATLien_0
      258
    3. 3
      Xenon
      164
    4. 4
      neufuse
      142
    5. 5
      +FloatingFatMan
      108
  • Tell a friend

    Love Neowin? Tell a friend!