SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict
    Join Date
    Mar 2001
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Is there a way to remove text from a field on submit?

    I viewed source and created a form similar to the "Search for..." thingie on top of the sitepoint pages...but when people click the go button, it allows the "Search for..." to remain in the text field...is there a way that I can make the text disappear upon hitting submit...

    To explain better, my form has an optional field, Name...and if they didn't fill it out I want that name to be cleared...instead of sending out all these forms saying Name: "Name"...

    If this can be done within the form html rather than adding a function in the head, that would be the solution I'm searching for...

    Thank you/.

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You shouldn't have any reservations about where the js goes - you're limiting yourself by having any.

    df=document.form.field;df.value=(df.value.match(/^Name.../))?'':df.value;

    Something like that - but maybe more .... efficient?

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  3. #3
    SitePoint Addict
    Join Date
    Mar 2001
    Posts
    249
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply...I know nothing about javascript at all so I didn't really understand what you wrote...

    Also, it's not that I have reservations about where the JS is, but it's within a php app, and the form is all over my pages, but the header code is separate from the form code and different headers are loaded in different places and it will be a pain to get it right because I'd have to change a bunch of templates...

  4. #4
    SitePoint Addict
    Join Date
    May 2000
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have not tested this, but have you tried using the onSubmit event in the form that to reset the form. Not sure if it would take place before the form is sent or after though. Something like this:
    <FORM ..... onSubmit="document.form_name.reset()">


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
  •