SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    js wont show result of calculation

    Hello everyone.
    Quick newbie question, i'm sure it is simple to you, but i cant get my head around to figure out why my code wont work. Checked online, seems that i'm doing everything fine, but still wont work... All i'm trying to do, is to make simple calc and display that in diff field.
    Here's my code:

    Code:
    <script type="text/javascript">
    		function calculate(){
    		var a = document.calculate.first.value;
    		var b = document.calculate.second.value;
    		var c = parseInt(a) + parseInt(b);
    		document.calculate.result.value = c;
    		}
    	</script>
    </head>
    
    <body>
    	<form name="calculate">
    		<input type="text" name="first" size="5">
    		<input type="text" name="second" size="5">
    		<input type="button" onclick="calculate()">
    		<input type="text" name="result" id="result" size="5">
    	</form>
    </body>
    by the way i'm using IE10, if that makes any difference.

  2. #2
    Community Advisor bronze trophy
    fretburner's Avatar
    Join Date
    Apr 2013
    Location
    Brazil
    Posts
    1,386
    Mentioned
    45 Post(s)
    Tagged
    12 Thread(s)
    I think it's a naming conflict - try changing your code so that the name of your form and the name of your function are different.

  3. #3
    SitePoint Member
    Join Date
    Feb 2013
    Posts
    21
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you fretburner ... i've spent so much time on this problem, and the solution was so simple ... hrrr...


Tags for this Thread

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
  •