I need help java isn't adding when its supposed to

This is a discussion on "I need help java isn't adding when its supposed to" within the JavaScript Forum section. This forum, and the thread "I need help java isn't adding when its supposed to are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > JavaScript Forum

Notices


Reply
 
LinkBack Thread Tools
  #1 (permalink)  
Old May 28th, 2007, 23:35
TheSealPortalTeam's Avatar
User of Users

SuperMember
Join Date: May 2007
Location: Buffalo
Posts: 267
Blog Entries: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Cool I need help java isn't adding when its supposed to

Code: Select all
  <script language="JavaScript" type="text/javascript">
    function AddStrength(args)
    {

        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value = value1 +1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -1 ;

    }
    </script>
I use this in aspx (as you can tell) and I'll hit the add button and it'll subtract but it won't add, It'll do 81 instead of 9, 811 instead of 10. HELP

http://thesealportal.no-ip.biz/tsp/p...harCreate.aspx
the url wasn't supposed to have the team part sorry
Last Blog Entry: Frontpages and Gathering Peak Users. (Jun 16th, 2008)

Last edited by TheSealPortalTeam; May 28th, 2007 at 23:38. Reason: fixed uri/url
Reply With Quote

  #2 (permalink)  
Old May 29th, 2007, 01:37
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: I need help java isn't adding when its supposed to

Ok, remenber the following:

1. Java is very different from Javascript.
Java: Programming launguage, needs to be compiled, strict data types.
Javascript: Scriptting language, needs an interpreter (browser), generic data types.

2. You're adding a number and text. Javascript can't perform the mathematical operation on the text so it converts the number to text and creates a new text string. What you need to do is convert the text into a number, like this:
Code: Select all
  <script language="JavaScript" type="text/javascript">
    function AddStrength(args)
    {

        var value1 = 0;
        value1 = new Number(document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value);
        var value2 = 0;
        value2 = new Number(document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value);
        document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value = value1 +1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -1 ;

    }
    </script>
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #3 (permalink)  
Old May 29th, 2007, 10:22
TheSealPortalTeam's Avatar
User of Users

SuperMember
Join Date: May 2007
Location: Buffalo
Posts: 267
Blog Entries: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I need help java isn't adding when its supposed to

thanks, I can also do this
Code: Select all
  <script language="JavaScript" type="text/javascript">
    function AddStrength(args)
    {
        //Specifically add strength while decreasing total points
        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        if (value2 == 0){
        alert("You have maxed out your total points");
        }
        else{
        document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value = value1 -=(-1) ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -=1 ;
        }

    }
    </script>
Last Blog Entry: Frontpages and Gathering Peak Users. (Jun 16th, 2008)
Reply With Quote
  #4 (permalink)  
Old May 29th, 2007, 10:39
spinal007's Avatar
Moderator
Join Date: Mar 2004
Location: Good Ol'London
Age: 22
Posts: 1,612
Blog Entries: 1
Thanks: 0
Thanked 2 Times in 2 Posts
Send a message via ICQ to spinal007 Send a message via MSN to spinal007 Send a message via Yahoo to spinal007 Send a message via Skype™ to spinal007
Re: I need help java isn't adding when its supposed to

I'm not sure that would work, but if you've tested it and it works, then it works!
Last Blog Entry: Random String in Javascript (Apr 21st, 2008)
Reply With Quote
  #5 (permalink)  
Old May 29th, 2007, 21:25
TheSealPortalTeam's Avatar
User of Users

SuperMember
Join Date: May 2007
Location: Buffalo
Posts: 267
Blog Entries: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Re: I need help java isn't adding when its supposed to

okay now java is just not working by putting a value deep into the hidden feilds (hid***)
Code: Select all
  <script language="JavaScript" type="text/javascript">
    //Strength
    function AddStrength(args)
    {
        //Specifically add strength while decreasing total points
        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        if (value2 == 0){
        alert("You have maxed out your total points");
        }
        else{
        document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value = value1 -=(-1) ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -=1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_hidTotalPoints").value = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value
        document.getElementById("ctl00_ContentPlaceHolder1_hidStr").value = document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value 
        }

    }
        function SubbStrength(args)
    {
        //Specifically subtract strength while increasing total points
        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        if (value1 == 8){
        alert("You CAN NOT lower a skill past 8");
        }
        else{
        document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value = value1 -=1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -=(-1) ;
        document.getElementById("ctl00_ContentPlaceHolder1_hidTotalPoints").value = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value
        document.getElementById("ctl00_ContentPlaceHolder1_hidStr").value = document.getElementById("ctl00_ContentPlaceHolder1_txtStrength").value 
        }

    }
        //Wisdom
    function AddWisdom(args)
    {
        //Specifically add wisdom while decreasing total points
        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtWisdom").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        if (value2 == 0){
        alert("You have maxed out your total points");
        }
        else{
        document.getElementById("ctl00_ContentPlaceHolder1_txtWisdom").value = value1 -=(-1) ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -=1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_hidTotalPoints").value = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value
        document.getElementById("ctl00_ContentPlaceHolder1_hidWis").value = document.getElementById("ctl00_ContentPlaceHolder1_txtWisdom").value 
        }

    }
        function SubbWisdom(args)
    {
        //Specifically subtract wisodm while increasing total points
        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtWisdom").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        if (value1 == 8){
        alert("You CAN NOT lower a skill past 8");
        }
        else{
        document.getElementById("ctl00_ContentPlaceHolder1_txtWisdom").value = value1 -=1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -=(-1) ;
        document.getElementById("ctl00_ContentPlaceHolder1_hidTotalPoints").value = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value
        document.getElementById("ctl00_ContentPlaceHolder1_hidWis").value = document.getElementById("ctl00_ContentPlaceHolder1_txtWisdom").value 
        }

    }
    //Wisdom
    function AddDefence(args)
    {
        //Specifically add wisdom while decreasing total points
        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtDefence").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        if (value2 == 0){
        alert("You have maxed out your total points");
        }
        else{
        document.getElementById("ctl00_ContentPlaceHolder1_txtDefence").value = value1 -=(-1) ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -=1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_hidTotalPoints").value = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value
        document.getElementById("ctl00_ContentPlaceHolder1_hidDef").value = document.getElementById("ctl00_ContentPlaceHolder1_txtDefence").value 

        }

    }
        function SubbDefence(args)
    {
        //Specifically subtract wisodm while increasing total points
        var value1 = 0;
        value1 = document.getElementById("ctl00_ContentPlaceHolder1_txtDefence").value;
        var value2 = 0;
        value2 = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value;
        if (value1 == 8){
        alert("You CAN NOT lower a skill past 8");
        }
        else{
        document.getElementById("ctl00_ContentPlaceHolder1_txtDefence").value = value1 -=1 ;
        document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value = value2 -=(-1) ;
        document.getElementById("ctl00_ContentPlaceHolder1_hidTotalPoints").value = document.getElementById("ctl00_ContentPlaceHolder1_txtTotalPoints").value
        document.getElementById("ctl00_ContentPlaceHolder1_hidDef").value = document.getElementById("ctl00_ContentPlaceHolder1_txtDefence").value 
       
        }

    }
    </script>
I just want it to copy the value it makes into both the text boxes (txt***) and the hidden fields(hid***)
Last Blog Entry: Frontpages and Gathering Peak Users. (Jun 16th, 2008)
Reply With Quote
Reply

Tags
subtract skill, skill point creater, javascript, help, character creater, adding skill, thesealportalteam

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding 1 to Column Value Jack Franklin PHP Forum 4 Feb 3rd, 2008 10:19
Adding More Images crackafaza PHP Forum 0 Jan 3rd, 2008 13:18
Adding quizzes hawashp Web Page Design 12 Oct 5th, 2007 12:04
Java/GUI/Server Developer (Java, EJB/Hibernate, SWING) - Berkshire Web JobBot Job Opportunities 0 Jan 16th, 2007 09:30
adding to database benbacardi Classic ASP 17 Aug 18th, 2004 12:28


All times are GMT. The time now is 10:21.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43