Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Moving value from 1 input textbox to another

    <html>
    <head>
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
    <meta http-equiv='Content-Script-Type' content='text/javascript'>
    <script type = 'text/javascript'>
    function unselectall(form)
    {
    var i=0;
    for(i=0;i<=15;i++)
    {
    tdname = 'invbox'+i;
    if (document.getElementById && document.getElementById(tdname).style)
    {
    document.getElementById(tdname).style.borderColor = '#000000';
    form.selected.value = 0;
    }
    else
    {
    i=20;
    }
    }
    }

    function selectthis(form, pos)
    {
    unselectall(form);
    var tdname = 'inventory';
    document.getElementById(tdname).style.borderColor = '#ffff00';
    form.selected.value = form.position1.value;
    }

    </script>

    </head>
    <body>
    <form id='inventorytable' method='post' action='addflowerlight.php'>
    <table id='inventory' border=1>
    <tr>
    <td id = 'invbox1' ><img src = 'images/Lights/6inv.jpg' onclick="selectthis('inventorytable', 1);"><input type = 'text' id = 'position1' value='6'></td></tr></table>
    <input type ='text' id='selected'>
    <input type ='submit' value='Equip Light'>
    </form>
    </body>
    </html>


    What am I doing wrong? The onclick wont trigger.

  • #2
    Regular Coder Krupski's Avatar
    Join Date
    Dec 2010
    Location
    United States of America
    Posts
    505
    Thanks
    39
    Thanked 47 Times in 46 Posts
    Quote Originally Posted by schenn View Post
    What am I doing wrong? The onclick wont trigger.
    Change all your single quotes to double quotes in HTML and use single quotes in Javascript.

    Example:
    Code:
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    <script type = "text/javascript">
    function unselectall(form)
    {
        var i=0;
        for(i=0;i<=15;i++)
        {
            tdname = 'invbox'+i;
            if (document.getElementById && document.getElementById(tdname).style)
            {
                document.getElementById(tdname).style.borderColor = '#000000';
                form.selected.value = 0;
            }
            else
            {
                i=20;
            }
        }
    }
    
    function selectthis(form, pos)
    {
        unselectall(form);
        var tdname = 'inventory';
        document.getElementById(tdname).style.borderColor = '#ffff00';
        form.selected.value = form.position1.value;
    }
    
    </script>
    
    </head>
    
    <body>
    <form id="inventorytable" method="post" action="addflowerlight.php">
        <table id="inventory" border=1>
            <tr>
                <td id ="invbox1" >
                    <img src ="images/Lights/6inv.jpg" onclick="selectthis('inventorytable', 1);">
                    <input type ="text" id ="position1" value="6">
                </td>
            </tr>
        </table>
        <input type ="text" id="selected">
        <input type ="submit" value="Equip Light">
    </form>
    </body>
    </html>
    Last edited by Krupski; 12-26-2010 at 10:43 PM.

  • #3
    New to the CF scene
    Join Date
    Dec 2010
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks!


  •  

    Tags for this 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
    •