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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Mar 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Working With Input boxes

    I am working a program for my personal website. This is a link to show how the program works: http://jsfiddle.net/VrMXE/1/
    Can someone help me modify it so that the text will appear in 3 input boxes instead of one. I want to click the text, it appears in Box 1, click again, Box 2 and then Box 3 (not at the same time).

    Code:
    var hasbeenset = false;
    function setInput(id){
        if(hasbeenset){
            document.getElementById("myinput").value+=", " + id;
        }
        else{
            hasbeenset = true;
            document.getElementById("myinput").value=id;
        }
    }
    function showtext(id){
    document.getElementById(id + "text").innerHTML=id;
    }
    
    <img width="50px" height="50px" src="https://pcbx.us/zachrip/yxo.jpeg" id="orange" onclick="showtext(this.id)"/>
    <p onclick="setInput(this.id)" id="orangetext"></p>
    <img width="50px" height="50px" src="https://pcbx.us/zachrip/yxp.jpeg" id="apple" onclick="showtext(this.id)"/>
    <p onclick="setInput(this.id)" id="appletext"></p>
    <img width="50px" height="50px" src="https://pcbx.us/zachrip/yxq.jpeg" id="banana" onclick="showtext(this.id)"/>
    <p onclick="setInput(this.id)" id="bananatext"></p>
    <input id="myinput" type="text" value="not set yet!"/>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,633
    Thanks
    0
    Thanked 649 Times in 639 Posts
    if (hasbeenset=true)

    This statement does two things. First it sets hasbeen set to true

    hasbeenset=true

    Then it tests if hasbeenset is true

    if (hasbeenset)
    Last edited by Basscyst; 03-07-2013 at 05:34 PM.
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.


  •  

    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
    •