1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

New twist on the price calculator...

Discussion in 'JavaScript' started by GoldDog, May 17, 2005.

  1. #1
    Now that the price calculator is working smoothly (see previous post - thanks frankm), I've got to throw a wrench in the works. Whereas the last version recalculated price based on one set price and the quantity chosen, this version has different price options.

    Previous version (with a few tweaks):
    
    function reCalc() {
    	si = document.forms.eQty.qty.selectedIndex;
    	v = si*#thispic.price#+#thispic.price#;
    	document.getElementById('subT').innerHTML = v;
    }
    PHP:
    (Note that I had to add the price again, because otherwise the calculated price did not pick up the original value. Odd, but it works.)

    This is where it gets strange... #thispic.price# is the price for the item specified in the dB query. However, each item can have several variations, which are retrieved from the dB like so (query name="addon"):
    
    SELECT *
    FROM ProductStyles
    WHERE ProductID = #Val(url.ID)#
    PHP:
    So the form will look something like this:
    
    Please specify type: <select name="type" onchange="reCalc()">
    	<option value="#thispic.price#"> #thispic.ProductName#
    	<cfoutput query="addon" group="title">
    	<option value="#price#"> #title#</cfoutput>
    </select>
    
    Please specify quantity: <select name="qty" onchange="reCalc()">
    	<cfloop index="i" from="1" to="10" step="1">
    	<option> #i#</cfloop>
    </select>
    PHP:
    (in the 1st menu, ColdFusion loops through the query results. The 2nd still displays only quantity selected.)

    The issue here is that I want to recalculate price everytime either menu is changed. If a different price point is selected in the 1st menu, the displayed price ("subT") must be recalculated according to the quantity specified in the 2nd. My thought was to merely change the function to look like this:
    
    function reCalc() {
    	si = document.forms.eQty.qty.selectedIndex;
    	tp = document.forms.eQty.type.selectedIndex;
    	v = si*tp+tp;
    	document.getElementById('subT').innerHTML = v;
    }
    PHP:
    Needless to say, it doesn't work (or I wouldn't be writing this). anybody have any ideas?

    thanks again
     
    GoldDog, May 17, 2005 IP