The output of a text field?

Discussion in 'JavaScript' started by Fry_watson, Feb 13, 2007.

  1. #1
    Ive been making a online turn based game in my free time, and i was wondering how to make it show up that ive bought the weapon. after i click submit its suppose to say you have 1 weapons. But its not working and how can i tell it were i want it to display it at.
    heres my code.
    sorry if i explained that bad.


    <html>
    <body background="http://www.script-design.com/img/home0/2.jpg">
    <script type="text/javascript">
    function Buy()
    {
    var name=prompt("weapon?","1")
    if (name!=null && name!="")

    {
    document.write("You have" + name + "Weapons")
    }
    }
    </script>
    <input type="text" name="prompt" value="1">
    <input type="submit" name="prompt" value="Submit">
    </body
    </html>
     
    Fry_watson, Feb 13, 2007 IP
  2. lbalance

    lbalance Peon

    Messages:
    381
    Likes Received:
    18
    Best Answers:
    0
    Trophy Points:
    0
    #2
    you need to add <form> tags and tell it to access that function you made onSubmit
     
    lbalance, Feb 13, 2007 IP
  3. giraph

    giraph Guest

    Messages:
    484
    Likes Received:
    27
    Best Answers:
    0
    Trophy Points:
    0
    #3
    you'll want to use

    <input type="button" onclick="Buy();" />
    Code (markup):
    As far as getting it to show up where you want, I suggest making an empty tag like.

    <span id="myID"></span>[code]
    
    Then instead of document.write use
    
    [code]document.getElementById("myID").innerHTML = "Your text goes here";
    Code (markup):
     
    giraph, Feb 13, 2007 IP