SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: javascript form

  1. #1
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript form

    i got this form but when i load the page the cursor insnt inside the form box ready to type how can i do that this is my code:

    <SCRIPT language="JavaScript1.2">
    function submitform()
    {
    if(document.myform.onsubmit())
    {
    document.myform.submit();
    }
    }
    </SCRIPT>
    Animated Chatrooms - www.121chatrooms.net

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2006
    Posts
    184
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe you're looking for the focus() method. document.myform.elementName.focus();

  3. #3
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    where would that code go
    Animated Chatrooms - www.121chatrooms.net

  4. #4
    SitePoint Guru
    Join Date
    Sep 2007
    Posts
    971
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is my code

    Code:
    <body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">
    <form name="myform" action="sendmessage.php">
    Message: <input type='text' name='message'>
    <A href="javascript: submitform()"
    ><img src="images/send.gif" width="33" height="19" border="0"
    ></A>
    </form>
    <SCRIPT language="JavaScript1.2">
    function dofo() {
    document.message.focus();
    }
    function submitform()
    {
     if(document.myform.onsubmit())
     {
     document.myform.submit();
     }
    }
    </SCRIPT>
    <body onLoad=dofo()>
    Animated Chatrooms - www.121chatrooms.net

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    Reference the message element from the form one instead.

    Code Javascript:
    document.myform.message.focus();

    The more modern way is to use an id attribute on the input element

    Code HTML4Strict:
    <input type="text" name="message" id="message">

    then use document.getElementById

    Code Javascript:
    document.getElementById('message').focus();
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript


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
  •