SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript focus and select

    <head>
    <body>
    <td width="346"><table width="346" border="0" cellpadding="0" cellspacing="0">
    <tr>
    <td width="63" height="5" valign="top" class="myWebEmbedNURLFont">&nbsp;&nbsp;URL</td>
    <td id="urlForm" width="283" align="left" valign="top"><input name="embedCode" type="text" value="testingtestingtestingtestingtestingtestingtestingtestingtestingtestingtestingtesting" class="myWebEmbedNURLInputFont" size="47" onClick="javascript:document.urlForm.embedCode.focus();document.urlForm.embedCode.select();" readonly="true"></td>
    </tr>
    </td>
    </body>


    a very draft code, what i wanna do is when i click on the form, the value will auto be selected. but i cant seem to do so, and i am not very sure of the problem. can someone kindly point out to me? thanks.

  2. #2
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Code JavaScript:
    document.urlForm.embedCode
    is referring to form with name 'urlForm' and to element inside the form with name 'embedCode'. You don't have a form tag with name 'urlForm'. You have a table column td with id='urlForm'. This wont work.

    Wrap form element(s) with form tag:
    Code HTML4Strict:
    <form name='urlForm'>
    <input .....>
    </form>
    Then:
    Code HTML4Strict:
    onClick="javascript:....
    You don't need to use inside onclick 'javascript:' because onclick is already expecting js code.


    Code JavaScript:
    document.urlForm.embedCode.focus();
    You don't need to use this because when you click on text box you just did focus().


    Code JavaScript:
    document.urlForm.embedCode.select();
    When you add form tag this will work.

    So input tag should look like:
    Code HTML4Strict:
    <input name="embedCode" type="text" value="testingtestingtestingtestingtestingtestingtestingtestingtestingtestingt estingtesting" class="myWebEmbedNURLInputFont" size="47" onClick="document.urlForm.embedCode.select();" readonly='true'>

  3. #3
    SitePoint Member
    Join Date
    Mar 2006
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks but can i ask, does select(); only work on form? can it work on Div too?

  4. #4
    SitePoint Enthusiast
    Join Date
    Nov 2006
    Posts
    99
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)


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
  •