+ Reply to Thread
Results 1 to 6 of 6
Like Tree2Likes
  • 1 Post By leafypiggy
  • 1 Post By misson

Thread: onclick text select and also a comment script if possable

  1. #1
    monsterm is offline x10Hosting Member monsterm is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    44

    onclick text select and also a comment script if possable

    i have 2 text fields and when i click on a text it highlights the whole box but the problem is thast it only highlights 1 box instaed of 2 boxes. heres the javascript im using


    HTML Code:
    <html><head><title>(Type a title for your page here)</title>
    
    <script type="text/javascript">
    function select_all()
    {
    var text_val=eval("document.form1.type");
    text_val.focus();
    text_val.select();
    }
    function select_all()
    {
    var text_val=eval("document.form1.type1");
    text_val.focus();
    text_val.select();
    }
    
    </script>
    
    </head>
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    
    <form name=form1 method=post action='' ''>
    <input type="text" name="type" size="70" onClick="select_all();" value="text1">
    <p>
    <input type="text" name="type1" size="70" onClick="select_all();" value="text2">
    </p>
    </form>
    
    </body>
    </html>
    if u wonna try it out the page is http://monstermatt2.pcriot.com/test/

    also

    if anyone has a script that site viewers can comment on the page without being registerd (like on some sites u have to register to make comments) and only

    Name
    email
    your comment


    can u pm me or reply in here thx


    (im making a video page)

  2. #2
    driveflexfuel is offline x10 Sophmore driveflexfuel is an unknown quantity at this point
    Join Date
    Jul 2008
    Posts
    159

    Re: onclick text select and also a comment script if possable

    You can not use two functions with the same name. The code below should work fine for you.

    Code:
    <html><head><title>(Type a title for your page here)</title>
    
    <script type="text/javascript">
    function select_all()
    {
    var text_val=eval("document.form1.type");
    text_val.focus();
    text_val.select();
    }
    function select_all_1()
    {
    var text_val=eval("document.form1.type1");
    text_val.focus();
    text_val.select();
    }
    
    </script>
    
    </head>
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    
    <form name=form1 method=post action='' ''>
    <input type="text" name="type" size="70" onClick="select_all(); select_all_1();" value="text1">
    <p>
    <input type="text" name="type1" size="70" onClick="select_all(); select_all_1();" value="text2">
    </p>
    </form>
    
    </body>
    </html>
    Last edited by driveflexfuel; 07-21-2009 at 10:05 AM.

  3. #3
    leafypiggy's Avatar
    leafypiggy is offline Community Advocate leafypiggy is on a distinguished road
    Join Date
    Aug 2007
    Location
    Massachusetts
    Posts
    2,228

    Re: onclick text select and also a comment script if possable

    Code:
    <script type="text/javascript">
    function select_all()
    {
    var text_val=eval("document.form1.type");
    text_val.focus();
    text_val.select();
    }
    function select_all()
    {
    var text_val=eval("document.form1.type1");
    text_val.focus();
    text_val.select();
    }
    
    </script>
    You declared the function twice. Try this:

    Code:
    <script type="text/javascript">
    function select_all()
    {
    var text_val=eval("document.form1.type");
    text_val.focus();
    text_val.select();
    var text_val1=eval("document.form1.type1");
    text_val1.focus();
    text_val1.select();
    }
    
    
    </script>
    Last edited by leafypiggy; 07-21-2009 at 10:11 AM.
    dinomirt96 likes this.
    Neil Hanlon | x10Hosting Support Representative
    Neil[at]x10hosting.com
    █ I'm always happy to help. Just ask a question in Free Hosting
    Terms of Service IRC

  4. #4
    VPmase's Avatar
    VPmase is offline x10 Elder VPmase is an unknown quantity at this point
    Join Date
    Nov 2007
    Location
    Dixon, IL, USA
    Posts
    914

    Re: onclick text select and also a comment script if possable

    Quote Originally Posted by leafypiggy View Post
    Code:
    <script type="text/javascript">
    function select_all()
    {
    var text_val=eval("document.form1.type");
    text_val.focus();
    text_val.select();
    }
    function select_all()
    {
    var text_val=eval("document.form1.type1");
    text_val.focus();
    text_val.select();
    }
    
    </script>
    You declared the function twice. Try this:

    Code:
    <script type="text/javascript">
    function select_all()
    {
    var text_val=eval("document.form1.type");
    text_val.focus();
    text_val.select();
    var text_val1=eval("document.form1.type1");
    text_val1.focus();
    text_val1.select();
    }
    
    
    </script>
    That script will do the same as having the two functions lol.

    Something like this should work and is efficient:
    Code:
    <html><head><title>(Type a title for your page here)</title>
    
    <script type="text/javascript">
    function selectText(b){
    switch(b){
    case 1:
    var text_val = eval("document.form1.type");
    text_val.focus();
    text_val.select();
    break;
    case 2:
    var text_val=eval("document.form1.type1");
    text_val.focus();
    text_val.select();
    break;
    }
    }
    </script>
    
    </head>
    <body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
    
    <form name="form1" method=post action='' ''>
    <input type="text" name="type" size="70" onClick="selectText(1);" value="text1">
    <p>
    <input type="text" name="type1" size="70" onClick="selectText(2);" value="text2">
    </p>
    </form>
    
    </body>
    </html>
    Last edited by VPmase; 07-21-2009 at 10:39 AM.

  5. #5
    monsterm is offline x10Hosting Member monsterm is an unknown quantity at this point
    Join Date
    Jun 2009
    Posts
    44

    Re: onclick text select and also a comment script if possable

    Quote Originally Posted by driveflexfuel View Post
    You can not use two functions with the same name.
    ahh ok thx

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: onclick text select and also a comment script if possable

    No need for eval or switches or even the call to focus(). Also, the <p> element isn't structural and the <body> attributes are deprecated; you should replace all of them with styling.

    HTML Code:
    <html><head><title>(Type a title for your page here)</title>
    <script type="text/javascript">
    function selectText(node){
        node.select();
    }
    </script>
    <style type="text/css">
    /* replacements for <body> attributes. These values are most likely the same as the
     * browser defaults, so could be dropped entirely with no noticeable effect. 
     */
    body {
      background-color: white;
      color: black;
    }
    a { color: blue; }
    a:visited: {color: purple;}
    a:active: { color: red; }
    
    /* No need for the <p> element that contained text1. Use style instead. */
    form input {
      display: block;
    }
    
    </style>
    </head>
    <body>
    
      <form name="form1" method=post action=''''>
        <input type="text" name="type" size="70" onClick="selectText(this);" value="text1" />
        <input type="text" name="type1" size="70" onClick="selectText(this);" value="text2" />
      </form>
    </body></html>
    karimirt47 likes this.
    Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.
    Misson, not Mission.

+ Reply to Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers