SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Thread: JS var.

  1. #1
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    JS var.

    how can I make something like:

    ok I have an variable, enemyhp, which is set to 20, how can I make this reduce by 10 with clicking an button?
    and then how to display it immediatly when u press it?


    maybe this code is usefull:

    http://www.xzazx.com/game/pointpool.html

    but then just for the immediate changes with those id's...
    I didn't come out of it after three days of hard trying...

    maybe one of u?
    thx!
    Last edited by XzAzX; Apr 15, 2002 at 10:52.
    _o_ OOP _o_

  2. #2
    ********* obeah makeda's Avatar
    Join Date
    Jun 2001
    Location
    rollin' on dubs
    Posts
    492
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    need more info. i checked out your link and it seems to work. if its not working correctly, please elaborate.

  3. #3
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:

    if(val=='minus_20'){section.innerHTML parseInt(form1.attack_add.value) - 10
    makeda is right it dont make, it seems as if you have it covered?

  4. #4
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by makeda
    need more info. i checked out your link and it seems to work. if its not working correctly, please elaborate.
    yeah this works, but what I wan't doesn't work.
    So I wan't to mske something like, when clicking the button, the hp goes down, ok , works,.
    then when the hp == 0;
    a message is displayed, and u'll be send to another page..
    _o_ OOP _o_

  5. #5
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (form1.points_used.value==0)
    {
        
    alert('i reached 0');
        
    window.location.href="http://www.sitepoint.com";

    simple
    Last edited by Andrew-J2000; Apr 15, 2002 at 21:06.

  6. #6
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'll try thx!
    _o_ OOP _o_

  7. #7
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It should work just make sure it has the same name as your layer etc

  8. #8
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    layers/

    I'm not sure what an layer is?..
    hmmz..
    _o_ OOP _o_

  9. #9
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this is the whole code:

    PHP Code:
    <html>
    <
    head>
        <
    title>Battle Page</title>
        <
    SCRIPT LANGUAGE=javascript>
            <!--
                function 
    hpdown(val)
                {
                    
                        if(
    val=='enemyhp'){ehp.innerHTML parseInt(ehp.innerHTML) - 10;
                        
    form1.attack_add.value parseInt(form1.attack_add.value) - 10}
                        
                }
            
    //-->
            
    </SCRIPT>
            
            
    </script>
            
            
    </head>

    <body>

    <FORM id=form1 name=hp>
    <TABLE   cellpadding=1 cellspacing=0 width=250  bgcolor=Ivory border=1 rules=none>

    <TD>Enemy HP <b>:</b></TD>

    <TD align=center id=ehp>20</TD> 
    </table>
    <br><br>
    <br><br>
    <br><br>
    <br><br>
    <TABLE   cellpadding=1 cellspacing=0 width=250  bgcolor=Ivory border=1 rules=none>



    <TD id=attack_b align=center>
    <img src="sword.gif" width="11" height="11" border="0" border=0 onClick="hpdown('enemyhp');" id=hp name="button2"
    style="cursor:hand">

    <TR></td>


        </table>
        
        
        <INPUT type="hidden" id=attack_add name=attack_add value="0">
        
                
                </FORM>
                
                <script language="Javascript" type="text/javascript">
            <!--
                if (hp.ehp.value==0)
                {
                    alert('i reached dead');
                    window.location.href="http://www.sitepoint.com";
                }
            //-->
                
            

    </body>
    </html> 
    but it still doesn't work,, probably the layers?
    _o_ OOP _o_

  10. #10
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PLEAZe!

    Pleaze help me guyz/
    I need it 4 school, 4 an project!
    _o_ OOP _o_

  11. #11
    Currently Occupied; Till Sunda Andrew-J2000's Avatar
    Join Date
    Aug 2001
    Location
    London
    Posts
    2,475
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    just do a couple things, put all attributes in quotes and dont leave them empty, and write html in lowercase

    PHP Code:

    <html>
    <
    head>
    <
    title>Battle Page</title>

    <
    script language="javascript">
    <!--

        function 
    hpdown(val)
        {
            
    //alert(ehp.innerText)
            
    if (ehp.innerText=="0")
            {
                
    alert('i reached dead');
                
    window.location.href="http://www.sitepoint.com";
                return;
            }

            if(
    val=='enemyhp'){ehp.innerHTML parseInt(ehp.innerHTML) - 10;
            
    form1.attack_add.value parseInt(form1.attack_add.value) - 10}
        }

    //-->
    </script>
    </head>

    <body>

    <form id="form1" name="hp">
      <table cellpadding="1" cellspacing="0" width="250"  bgcolor="ivory" border="1" rules="none">
        <td>Enemy HP <b>:</b></td>
        <td align="center" id="ehp">20</td> 
      </table>
      
      <p>&nbsp;<br>&nbsp;</p>
      
      <table cellpadding="1" cellspacing="0" width="250"  bgcolor="ivory" border="1" rules="none">
        <td id="attack_b" align="center"><img src="sword.gif" width="11" height="11" border="0" border="0" onClick="hpdown('enemyhp');" id="hp" name="button2" style="cursor:hand"></td>
      </table>

      <input type="hidden" id="attack_add" name="attack_add" value="0">
    </form>

    <script language="Javascript" type="text/javascript">
    <!--

        if (hp.ehp.value==0)
        {
            alert('i reached dead');
            window.location.href="http://www.sitepoint.com";
        }
    //-->
    </script>
    </body>
    </html> 
    or when it reaches 0

    PHP Code:

    <html>
    <
    head>
    <
    title>Battle Page</title>

    <
    script language="javascript">
    <!--

        function 
    hpdown(val)
        {
            if(
    val=='enemyhp'){ehp.innerHTML parseInt(ehp.innerHTML) - 10;
            
    form1.attack_add.value parseInt(form1.attack_add.value) - 10}

            
    //alert(ehp.innerText)
            
    if (ehp.innerText=="0")
            {
                
    alert('i reached dead');
                
    window.location.href="http://www.sitepoint.com";
                return;
            }
        }

    //-->
    </script>
    </head>

    <body>

    <form id="form1" name="hp">
      <table cellpadding="1" cellspacing="0" width="250"  bgcolor="ivory" border="1" rules="none">
        <td>Enemy HP <b>:</b></td>
        <td align="center" id="ehp">20</td> 
      </table>
      
      <p>&nbsp;<br>&nbsp;</p>
      
      <table cellpadding="1" cellspacing="0" width="250"  bgcolor="ivory" border="1" rules="none">
        <td id="attack_b" align="center"><img src="sword.gif" width="11" height="11" border="0" border="0" onClick="hpdown('enemyhp');" id="hp" name="button2" style="cursor:hand"></td>
      </table>

      <input type="hidden" id="attack_add" name="attack_add" value="0">
    </form>

    <script language="Javascript" type="text/javascript">
    <!--

        if (hp.ehp.value==0)
        {
            alert('i reached dead');
            window.location.href="http://www.sitepoint.com";
        }
    //-->
    </script>
    </body>
    </html> 
    Last edited by Andrew-J2000; Apr 17, 2002 at 06:58.

  12. #12
    SitePoint Zealot XzAzX's Avatar
    Join Date
    Apr 2002
    Location
    Holland
    Posts
    126
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    YEEHAAW!

    yes IT WORKS!
    thx a lot m8!!!!!
    _o_ OOP _o_


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •