Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Can't Call Function in Javascript *EDIT* I fixed it
New Posts  All Forums:Forum Nav:

Can't Call Function in Javascript *EDIT* I fixed it

post #1 of 15
Thread Starter 
Ok so I am starting a custom computer company and i am trying to make a custom configurator so you can pick your parts and all that good stuff. DiGiCiDaL has already gotten me well on my way, but I am having trouble causing the systemTotal() function to update, here is the code I have so far.
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<script type='text/javascript'>
function updateRamSelection(price,imageid,imgurl) { 
   document.getElementById(imageid).src = imgurl;
   var ramItem = price;
   systemTotal();
}
</script>

<script type='text/javascript'>
function updateCPUSelection(price,imageid,imgurl) { 
   document.getElementById(imageid).src = imgurl;
   var cpuItem = price;
  systemTotal();
}
</script>

<script type='text/javascript'>
function systemTotal() {
        var ram = document.getElementById(ramItem).value;
        var cpu = document.getElementById(cpuItem).value;
        var total = parseInt(ram, 10) + parseInt(cpu, 10);
        document.getElementById('cart_Total').value = total;
}
</script>



<body>

<form name="sysbuild" id="sysbuild" action="actionpage.html" method="post">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td colspan="2" align="center"><strong>SYSTEM CPU SELECTION</strong></td>
  </tr>
  <tr>
    <td align="center" width="120"><img name="cpupic" id="cpupic" src="images/customconfig/cpu/i3-3225.jpg" width="100" height="100" alt="Processor Image" border="0" /></td>
    <td align="left">
        <input type="radio" name="Part_CPU" value="CPU_NO_Xi3T3225"  onclick="updateCPUSelection('130','cpupic','images/customconfig/cpu/i3-3225.jpg')" onmouseover="systemTotal()" checked /> Intel Core i3-3225 Dual Core Processor (Included)<br/>
        <input type="radio" name="Part_CPU" value="CPU_NO_Xi5T3350P"  onclick="updateCPUSelection('540','cpupic','images/customconfig/cpu/i5-3350p.jpg'); systemTotal();" /> Intel Core i5-3350P Quad Core Processor (+$30)<br/>
        <input type="radio" name="Part_CPU" value="CPU_NO_Xi5T3570K" /> Intel Core i5-3570K Quad Core Processor (+$70)<br/>
        <input type="radio" name="Part_CPU" value="CPU_NO_Xi7T3770" /> Intel Core i7-3770 Quad Core Processor (+$140)<br/>
        <input type="radio" name="Part_CPU" value="CPU_NO_Xi7T3370K" /> Intel Core i7-3770K Quad Core Processor (+$180)<br/>
    </td>
  </tr>
  <tr>
    <td colspan="2" align="center"><strong>SYSTEM MEMORY SELECTION</strong></td>
  </tr>
  <tr>
    <td align="center" width="120"><img name="rampic" id="rampic" src="images/customconfig/ram/4gb16002x2.jpg" width="100" height="100" alt="Memory Image" border="0" /></td>
    <td align="left">
    <input type="radio" name="Part_RAM" value="RAM_NO_R4GB1600_2X2" onclick="updateRamSelection('130','rampic','images/customconfig/ram/4gb16002x2.jpg'); systemTotal();"  checked /> 4GB DDR3 1600MHz Memory - 2X2GB (Included)<br/>
        <input type="radio" name="Part_RAM" value="RAM_NO_R8GB1600_4X2" onclick="updateRamSelection('500','rampic','images/customconfig/ram/8gb16004x2.jpg'); systemTotal();"  /> 8GB DDR3 1600MHz Memory - 4X2GB (+$50)<br/>
        <input type="radio" name="Part_RAM" value="RAM_NO_R16GB1600_4X4" /> 16GB DDR3 1866MHz Memory - 4X4GB (+$100)<br/>
        <input type="radio" name="Part_RAM" value="RAM_NO_R32GB2133_4X8" /> 32GB DDR3 2133MHz Memory - 4X8GB (+$250)<br/>
      </td>
  </tr>
</table>
<input type="text" name="cart_Total" id="cart_Total" readonly="readonly">
</form>



</body>
</html>

Ok so the systemTotal() function refuses to update, even though I have it being called to update in three different ways. In the CPU section I have it as an onmouseover] sensor. in the RAM selection page, I have it in the onClick sensor along with the updateRamSelection which by the way, works flawlessly, same as the updateCPUSelection function.
The reason I know this is because this outputs whatever cart_Total is. This works in the updateCPU and RAM Selection functions when I tell it to equal the price. BUT even when I set the document.getElementById('cart_Total').value = total; line to equal a static number, it outputs nothing when in the systemTotal() function. Why is this?

So to recap, the updateRamSelection and updateCPUSelection functions work flawlessly, they update every click and if I tell the cart_Total to equal the price value in either of these functions, it works. But the systemTotal function never runs, even when I say in the body to run that function on page load.
Edited by ADHDadditiv - 5/20/13 at 1:49pm
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
post #2 of 15
FYI, Java and JavaScript are completely unrelated.
post #3 of 15
Thread Starter 
Quote:
Originally Posted by stupid View Post

FYI, Java and JavaScript are completely unrelated.
That actually helps me more then you think, lol I can now successfully google search this.
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
post #4 of 15
how can you be sure it's never being called?

Maybe there is an error in there

try the following:
Code:
<script type='text/javascript'>
function systemTotal() {
       alert("function systemTotal called");
        var ram = document.getElementById(ramItem).value;
        var cpu = document.getElementById(cpuItem).value;
        ram = parseInt(ram, 10) ;
        cpu = parseInt(cpu, 10);
        var total =cpu+ram;
        document.getElementById("cart_Total").value = total;
}
</script>
post #5 of 15
Thread Starter 
Quote:
Originally Posted by EduFurtado View Post

how can you be sure it's never being called?

Maybe there is an error in there

try the following:
Code:
<script type='text/javascript'>
function systemTotal() {
       alert("function systemTotal called");
        var ram = document.getElementById(ramItem).value;
        var cpu = document.getElementById(cpuItem).value;
        ram = parseInt(ram, 10) ;
        cpu = parseInt(cpu, 10);
        var total =cpu+ram;
        document.getElementById("cart_Total").value = total;
}
</script>
Thank you, I figured out that it was calling the function all along, its just that every single operator was apparently wrong...
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
post #6 of 15
AD, are you adding all the inventory by hand one by one in html?
post #7 of 15
Thread Starter 
Quote:
Originally Posted by MakubeX View Post

AD, are you adding all the inventory by hand one by one in html?
Yes good sir I am, and let me tell you I am going to hate my life!
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
post #8 of 15
Quote:
Originally Posted by ADHDadditiv View Post

Yes good sir I am, and let me tell you I am going to hate my life!
Oh boy, I HIGHLY recommend you setup a database, enter the data there and then use server side scripting to pull the items from the database.

It'll be hell to maintain the way you're doing it.
post #9 of 15
Thread Starter 
Quote:
Originally Posted by MakubeX View Post

Oh boy, I HIGHLY recommend you setup a database, enter the data there and then use server side scripting to pull the items from the database.

It'll be hell to maintain the way you're doing it.
I am currently not skilled enough to do this unfortunately. Otherwise I would, trust me. wink.gif
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
Black Jarvis V1.9
(21 items)
 
Mazdaspeed6
(18 items)
 
 
  hide details  
Reply
post #10 of 15
Quote:
Originally Posted by ADHDadditiv View Post

I am currently not skilled enough to do this unfortunately. Otherwise I would, trust me. wink.gif
Are you actually trying to start a company or is this just for practice?
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Can't Call Function in Javascript *EDIT* I fixed it