50 users online (0 members and 50 guests)  


  Results 1 to 11 of 11

Related

  1. Replies: 15
  2. onclick help    Forum: Javascript Forum
    Replies: 3
  3. onClick on php?    Forum: PHP Forum
    Replies: 1
  1. #1
    arose's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    4

    Autoselect predefined input-value onClick.

    Hello @ all,

    the following problem has not let me sleep for quite some time now.

    Using a form with input fields (text) and a predefined value is no problem.

    <input value="Bob" name="example"></input>

    What I want to do is, later when I click into the input field, where the string Bob ist aready written, I would like this text-string to be selected. This way it can be overwritten instantly.

    At the moment I still have to press backspace and delete it manually. Another possiblity would be that the contents "Bob" is deleted automatically onClick.

    One way or the other - I would like to make filling out the form faster and more user friendly.

    Your help is greatly appreciated.

  2. #2
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    Hi there ,

    would this work okay -

    Code:
    <input value="Bob" name="example" onfocus="if (this.value=='Bob') this.value='';" />
    I tested it, should work. You can, of course, amend it all to suit.
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  3. #3
    arose's Avatar
    New User

    Status
    Offline
    Join Date
    Aug 2003
    Posts
    4
    WOW! Works like a charm - and neater than my select and overwrite-thingy

    Thank you very much!

  4. #4
    QuietDean's Avatar
    Administrator

    Status
    Offline
    Join Date
    Oct 2000
    Location
    Bournemouth, UK
    Posts
    2,662
    no problem
    If one of our members helps you, please click the icon to add to their reputation!
    No support via email or private message - use the forums!
    Before you ask, have you Searched?

  5. #5
    MediaMisfit's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Posts
    1

    Re: Autoselect predefined input-value onClick.

    Great solution. That's exactly what I was looking for also!


  6. #6
    DeusEx's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2008
    Posts
    3

    Re: Autoselect predefined input-value onClick.

    Hi there,

    I'm using SMF forum, and I'm trying to input this code id my source, but I'm keep getting this error

    Code:
    Template Parse Error!
    There was a problem loading the /Themes/VersatilityDark/index.template.php template or language file. Please check the syntax and try again - remember, single quotes (') often have to be escaped with a slash (\). To see more specific error information from PHP, try accessing the file directly.
    
    You may want to try to refresh this page or use the default theme.
    syntax error, unexpected T_STRING, expecting ',' or ';'
    Also, I've tried

    Code:
    <input value="Bob" name="example" onfocus="if (this.value=="Bob") this.value="";"/>
    without any ' ' , just " " , but always error

    Regards

  7. #7
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: Autoselect predefined input-value onClick.

    I don't know what is causing the original error, but the changes you mentioned will only cause more errors. Put the single quotes back.

  8. #8
    DeusEx's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2008
    Posts
    3

    Re: Autoselect predefined input-value onClick.

    Erm, my bad.

    I meant with double quotes there's no error, but wont work, and with single quotes there's error

    Sorry

  9. #9
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: Autoselect predefined input-value onClick.

    Could you show me the line before and the line after?

  10. #10
    DeusEx's Avatar
    New User

    Status
    Offline
    Join Date
    Oct 2008
    Posts
    3

    Re: Autoselect predefined input-value onClick.

    I've solved it with

    Code:
    <input value="Bob" name="example" onfocus="if (this.value== \'Bob\') this.value=\'\';" />
    Thanks for help anyway

  11. #11
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: Autoselect predefined input-value onClick.

    No problem. Glad you were able to get it working.