SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    onChange says function not defined in external js file

    I have the following code as js for <a href="http://www.oxbowcreations.com/wedding/personalize.php">this</a> site.

    Code:
    // JavaScript Document
    
    function setQty(id)
    {
    	window.$qty = document.getElementById(id).value;
    	alert('The qty is' . window.$qty);
    }
    
    function setResp(id)
    {
    	window.$response = document.getElementById(id).value;
    }
    
    function calculateCost(qty, response)
    {
    	window.$price = 0;
    	
    	if(response = 1)
    	{
    		window.$price = qty(2.25) + qty(.75);
    	}
    	else
    	{
    		window.$price = qty(2.25);
    	}
    }
    
    function qtyDisc(qty)
    {
    	if(qty > 100 && qty < 200)
    	{
    		window.$price -= qty(.25);
    	}
    	else if(qty >= 200 && qty < 500)
    	{
    		window.$price -= qty(.50);
    	}
    }
    
    function changePrice()
    {
    	document.getElementByID("price").value = "$" . window.$price.toFixed(2);
    }
    function updatePrice(window.$qty, window.$response)
    {
    	calculateCost(qty, response);
    	qtyDisc(qty);
    	changePrice();
    }
    I have no clue what the problem is.

    As you can tell I am just a beginner but any help would be appreciated.

    Thanks in advance!

  2. #2
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,800
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    in changePrice getElementByID should have a lowercase d on the end.

    document.getElementByID() isn't defined anywhere but document.getElementById() is.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  3. #3
    SitePoint Member
    Join Date
    Oct 2009
    Posts
    19
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, sorry it took so long to respond.

    Wonderful how one little thing like that makes nothing work.


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
  •