Zaloguj | Zarejestruj | FAQ
Anonymous

Preforming basic maths functions

+ Odpowiedz

Posty: 21 1, 2, 3


Re: Preforming basic maths functions

przez atik » Cz lip 19, 2012 1:12 pm

nicci5 napisał(a):hi

i changed the names in some places as i thought they would have to be called what they ate in the form ie your number 1 field is called TIME on my form , if i change the names on my form to match yours do you think that would work ?

Nicci

Sorry but i think you have missed something. Have you actually noticed in my following post -

Kod: Zaznacz cały
<script type="text/javascript">
   function calculate_result(sum) {
      var n1 = document.getElementById("number1").value;
      var n2 = document.getElementById("number2").value;
      var n3 = document.getElementById("number3").value;
      var n4 = document.getElementById("number4").value;
      var sum = Number(n1) + Number(n2) + Number(n3) + Number(n4);
      b = sum / 10.0;
      document.getElementById("a").value = sum;
      document.getElementById("b").value = 3600/sum;
      document.getElementById("c").value = 2700/sum;
      document.getElementById("d").value = 25200/sum;
   }
</script>

<form>
   1st Number:<input type="text" name="number1" id="number1"/><br/>
   2nd Number:<input type="text" name="number2" id="number2"/><br/>
   3rd Number:<input type="text" name="number3" id="number3"/><br/>
   4th Number:<input type="text" name="number4" id="number4"/><br/>
   <input type="button" value="Calculate" onclick="calculate_result();"/><br/>
   a:<input type="text" name="a" id="a"/><br/>
   b:<input type="text" name="b" id="b"/><br/>
   c:<input type="text" name="c" id="c"/><br/>
   d:<input type="text" name="d" id="d"/>
</form>


I have included both html form part and javascript part here, did you already noticed that? First part is javascript part and 2nd part is html part. This is the complete code. You can surely change it, but you need to make changes in html if you change in javascript or vice-versa. First i would suggest you to copy the full code and paste it in a blank document. Then try it out and see how it works. Later, you can change anything, making sure change in both html & javascript.
Avatar użytkownika

atik

  • Posty: 471
  • Dołączył(a): Pn paź 17, 2011 4:55 pm

Re: Preforming basic maths functions

przez nicci5 » Cz lip 19, 2012 1:17 pm

Thanks sorry to be a pain , i will try this now.

Nicci
Avatar użytkownika

nicci5

  • Posty: 12
  • Dołączył(a): Wt lip 17, 2012 9:51 am

Re: Preforming basic maths functions

przez atik » Cz lip 19, 2012 1:30 pm

nicci5 napisał(a):Thanks sorry to be a pain , i will try this now.

Nicci

No problem at all. Try and let me know if you need any help.
Avatar użytkownika

atik

  • Posty: 471
  • Dołączył(a): Pn paź 17, 2011 4:55 pm

Re: Preforming basic maths functions

przez nicci5 » Cz lip 19, 2012 1:35 pm

hi

have tried again and have copied and pasted onto a blank sheet with just the 4 number boxes and the 4 abcd boxes and it is still coming up with the same error ?
<script type="text/javascript">
function calculate_result(sum) {
var n1 = document.getElementById("number1").value;
var n2 = document.getElementById("number2").value;
var n3 = document.getElementById("number3").value;
var n4 = document.getElementById("number4").value;
var sum = Number(n1) + Number(n2) + Number(n3) + Number(n4);
b = sum / 10.0;
document.getElementById("a").value = sum;
document.getElementById("b").value = 3600/sum;
document.getElementById("c").value = 2700/sum;
document.getElementById("d").value = 25200/sum;
}
</script>

<form>
1st Number:<input type="text" name="number1" id="number1"/><br/>
2nd Number:<input type="text" name="number2" id="number2"/><br/>
3rd Number:<input type="text" name="number3" id="number3"/><br/>
4th Number:<input type="text" name="number4" id="number4"/><br/>
<input type="button" value="Calculate" onclick="calculate_result();"/><br/>
a:<input type="text" name="a" id="a"/><br/>
b:<input type="text" name="b" id="b"/><br/>
c:<input type="text" name="c" id="c"/><br/>
d:<input type="text" name="d" id="d"/>
</form>
Avatar użytkownika

nicci5

  • Posty: 12
  • Dołączył(a): Wt lip 17, 2012 9:51 am

Re: Preforming basic maths functions

przez nicci5 » Cz lip 19, 2012 1:36 pm

nicci5 napisał(a):hi

have tried again and have copied and pasted onto a blank sheet with just the 4 number boxes and the 4 abcd boxes and it is still coming up with the same error ?
<script type="text/javascript">
function calculate_result(sum) {
var n1 = document.getElementById("number1").value;
var n2 = document.getElementById("number2").value;
var n3 = document.getElementById("number3").value;
var n4 = document.getElementById("number4").value;
var sum = Number(n1) + Number(n2) + Number(n3) + Number(n4);
b = sum / 10.0;
document.getElementById("a").value = sum;
document.getElementById("b").value = 3600/sum;
document.getElementById("c").value = 2700/sum;
document.getElementById("d").value = 25200/sum;
}
</script>

<form>
1st Number:<input type="text" name="number1" id="number1"/><br/>
2nd Number:<input type="text" name="number2" id="number2"/><br/>
3rd Number:<input type="text" name="number3" id="number3"/><br/>
4th Number:<input type="text" name="number4" id="number4"/><br/>
<input type="button" value="Calculate" onclick="calculate_result();"/><br/>
a:<input type="text" name="a" id="a"/><br/>
b:<input type="text" name="b" id="b"/><br/>
c:<input type="text" name="c" id="c"/><br/>
d:<input type="text" name="d" id="d"/>
</form>



sorry this line is highlighted still
var n2 = document.getElementById("number2").value;
Avatar użytkownika

nicci5

  • Posty: 12
  • Dołączył(a): Wt lip 17, 2012 9:51 am

Re: Preforming basic maths functions

przez atik » Cz lip 19, 2012 1:52 pm

Not sure whats going wrong, because i am still running the same code. You have mentioned about error, but i am not sure you already know that javascript errors are only shown in console. Are you getting error in console? Can you give some more information about how you are trying to run, which browser and where error is shown?
Avatar użytkownika

atik

  • Posty: 471
  • Dołączył(a): Pn paź 17, 2011 4:55 pm

Re: Preforming basic maths functions

przez nicci5 » Cz lip 19, 2012 2:22 pm

when i attempt to paste into properties/calculate /custom calculation script it highlighs the line with var2 which is line 4 on the script . then when i try to click on ok to close the box there is a message that come us at the bottom of the page Javascript debugger saying
SyntaxError: syntax error
3: at line 4


Browser is internet explorer and i am using adobe acrobat 9 pro .

thanks hope this is helpful information
Avatar użytkownika

nicci5

  • Posty: 12
  • Dołączył(a): Wt lip 17, 2012 9:51 am

Re: Preforming basic maths functions

przez atik » Cz lip 19, 2012 2:37 pm

nicci5 napisał(a):when i attempt to paste into properties/calculate /custom calculation script it highlighs the line with var2 which is line 4 on the script . then when i try to click on ok to close the box there is a message that come us at the bottom of the page Javascript debugger saying
SyntaxError: syntax error
3: at line 4


Browser is internet explorer and i am using adobe acrobat 9 pro .

thanks hope this is helpful information

Ok, simply follow the steps , first create a blank html file using any simple text editor like notepad++ (if you can't use that, use simply notepad), paste the full code, save the file (make sure you save with .html extension, not .txt extension). Now open the html file with browser, better chrome or firefox, if none of them available, use internet explorer. When you open with browser, you will see few boxes in 2 sections (4 fields in each section). Fill up first 4 and hit "Calculate" button, you will see result in other 4 boxes. Don't use anyother tool, just try to follow these simple steps.
Avatar użytkownika

atik

  • Posty: 471
  • Dołączył(a): Pn paź 17, 2011 4:55 pm

Re: Preforming basic maths functions

przez nicci5 » Cz lip 19, 2012 3:15 pm

wow that works thanks so much , one last question how do i get it to work on my form ? do i need to start again ? i
Avatar użytkownika

nicci5

  • Posty: 12
  • Dołączył(a): Wt lip 17, 2012 9:51 am

Re: Preforming basic maths functions

przez atik » Cz lip 19, 2012 3:29 pm

nicci5 napisał(a):wow that works thanks so much , one last question how do i get it to work on my form ? do i need to start again ? i

Good to know it worked finally. You can do modifications to html & javascript, but you need to know a little bit of html & javascript basics. I guess you are not familiar with the basics of javascript, and you use rich editors like dreamweaver. Thats not how should you do the stuff, you should first learn basics before trying out those editors. Why not start learning basics? Its not hard at all. This forum has tutorial of both html & javascript. There are many other resources also available for free. The time you are spending trying figuring out simple tasks like the previous one are very basic & you can see you are spending hours. Instead if you had basic, it would take hardly 10 - 15 mins. Once you have the basics, you can do editing the code as you wish without any trouble.
Avatar użytkownika

atik

  • Posty: 471
  • Dołączył(a): Pn paź 17, 2011 4:55 pm


+ Odpowiedz

1, 2, 3