Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5
  1. #1
    Member metromax's Avatar
    Join Date
    Jun 2007
    Posts
    76
    Member #
    15335
    Hi everyone, I'm completely new to javascript and wanted to have links load text into a textbox. Can anyone tell me why the below code isn't working?
    Code:
    <html>
    <head>
    <script language="javascript">
    function loadtext(text)
    {
        codebox.value == text
    }
    </script>
    </head>
    
    <body>
    <input name="codebox" id="codebox" type="text" value="">
    <a onClick="loadtext(hi)">Hello World!</a></body>
    </html>

  2.  

  3. #2
    Senior Member
    Join Date
    Jun 2005
    Location
    Atlanta, GA
    Posts
    4,146
    Member #
    10263
    Liked
    1 times
    You don't want ==, you want = == is the equality operator, = is the assignment operator, which is to say that == checks if the variable on the right is equal to the variable on the left, while = puts the value of the variable on the right into the variable on the left.

  4. #3
    Member metromax's Avatar
    Join Date
    Jun 2007
    Posts
    76
    Member #
    15335
    it's still not working
    Code:
    <html>
    <head>
    <script language="javascript">
    function loadtext(text)
    {
        codebox.value = text
    }
    </script>
    </head>
    
    <body>
    <input name="codebox" id="codebox" type="text" value="">
    <a onClick="loadtext(hi)">Hello World!</a></body>
    </html>

  5. #4
    Senior Member seanmiller's Avatar
    Join Date
    Sep 2003
    Location
    Glastonbury, UK
    Posts
    868
    Member #
    3263
    Liked
    1 times
    You should be using the document.getElementById function... also put quotes around the parameter on the call...

    Code:
    <html>
    <head>
    <script language="javascript">
    function loadtext(text)
    {
        document.getElementById("codebox").value = text;
    }
    </script>
    </head>
    
    <body>
    <input name="codebox" id="codebox" type="text" value="">
    <a onClick="loadtext('hi')">Hello World!</a></body>
    </html>
    Sean

  6. #5
    Member metromax's Avatar
    Join Date
    Jun 2007
    Posts
    76
    Member #
    15335
    That did it, thanks for all your help


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:37 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com