1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

How to type in a Form Field without clicking it - i.e like Google/Yahoo?

Discussion in 'JavaScript' started by misohoni, Jun 13, 2005.

  1. #1
    This may be an easy one and I used to be able to do this in old versions of DW, but how to make a field open (i.e. you can type in it straight away) without clicking on it first.

    Examples - the search boxes in Yahoo/Google...you don't need to click on them before you type your search.

    Thanks
     
    misohoni, Jun 13, 2005 IP
  2. tresman

    tresman Well-Known Member

    Messages:
    235
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    138
    #2
    It's javascript, did you looked at google code?

    you can do that:

    <body onload="myfunction()">
    Code (markup):
    now, betweeen the <head> and the </head> you have to add:

    <script type="text/javascript">
    <!--
    function myfunction() {
    this.focus()
    };
    // -->
    </script>
    Code (markup):
    This should work, but if not you reply here or do some test. I am not a javascript guru (I'm reallyyyyy far waya from) but this is basically the idea.
     
    tresman, Jun 13, 2005 IP
  3. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #3
    Ah I thought it was something I needed to add in the <input form part> thanks, I'll test it
     
    misohoni, Jun 13, 2005 IP
  4. cagintranet

    cagintranet Well-Known Member

    Messages:
    328
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    128
    #4
    Heres what i use:
    add this onload statement to your <body> tag.
    <body OnLoad="document.requestform.aname.focus();">
    PHP:
    syntax is document.[formname].[fieldname that needs the focus].focus()


    below is the input field that will be recieving the focus... see how the name of it is "aname" - same as in the onload statement?
    <input type="text" name="aname" value="">
    PHP:
    hope this helps
     
    cagintranet, Jun 22, 2005 IP
  5. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #5
    thanks but didn't work for me.
     
    misohoni, Jun 22, 2005 IP
  6. tresman

    tresman Well-Known Member

    Messages:
    235
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    138
    #6
    Well Mishoni,

    I thought you had already solved this problem. But look like not.

    I think it didn't work cause you haven't read carefully what he said.

    Please note this

    And note now the [formname].

    Give your form a name and it will work.

    But if you do not want to think, find te code below

    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
      <head>
        <title>
        </title>
      </head>
      <body onload="document.myform.myinput.focus()">
      
      <form name="myform">
      <input name="myinput" type="text" />
      <input type="button" value="GO!" />
      </form>
      
      </body>
      
    </html>
    
    
    Code (markup):
    Is that easy. Look at "myfrom" and look at "myinput". Look too at the onload statement. It's that easy man.

    cagintranet in fact solved your problem already.
     
    tresman, Jun 22, 2005 IP
  7. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #7
    Err thanks for the beginneers run thru, your rcode didn't work for me though - I've got multi-layered dynamic tabs on my site same as Google/Yahoo and it doesn't pick it up. Here's the code I've been messing with but I don't think there's a solution. No Cagintranet's code gives JS errors...

    <script>
    <!--
    function selector(){document.schina.q.focus();}
    d=document;
    // -->
    </script>
    </head>
    <body onLoad=selector()>
     
    misohoni, Jun 22, 2005 IP
  8. tresman

    tresman Well-Known Member

    Messages:
    235
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    138
    #8
    can you please post the site so I can have look. Or pls pm.
     
    tresman, Jun 22, 2005 IP
  9. misohoni

    misohoni Notable Member

    Messages:
    1,717
    Likes Received:
    32
    Best Answers:
    0
    Trophy Points:
    200
    #9
    Thanks for the offer, I've spent a couple of hours on it and realised it's not worth it at this moment...is ok thanks for the help though.
     
    misohoni, Jun 23, 2005 IP
  10. webnp05

    webnp05 Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    document.form.fieldname.focus() does not seem to work on Safari when i test it. Is anyone else having this trouble? Anyone can provide a solution please?
     
    webnp05, Jul 14, 2005 IP
  11. J.D.

    J.D. Peon

    Messages:
    1,198
    Likes Received:
    65
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Try this:

    <body onload="document.forms.n1.n3.focus()">
    <form name="n1">
    <input name="n2"><input name="n3">
    </form>
    </body>

    or this:

    <body onload="document.getElemenetById("id3").focus()">
    <form>
    <input name="n2"><input name="n3" id="id3">
    </form>
    </body>

    J.D.
     
    J.D., Jul 15, 2005 IP