dfowler Posted December 12, 2007 Share Posted December 12, 2007 Hey guys, I'll get right down to it. Here is the code: function refreshPrice() { var selectedradio; for (i=0;i<document.getElementById('appform').elements.length;i++) { ele = document.getElementById('appform').elements[i]; if (ele.type == 'radio' && ele.name == 'coverage' && ele.checked) { selectedradio = ele; break; } } price = (document.getElementById('equipment').checked ? 225 : 0) + (document.getElementById('technical').checked ? 0 : 0) + (document.getElementById('personal').checked ? 48 : 0) + pricekeys[selectedradio.value]; document.getElementById('totalprice').innerHTML = '$'+price.toString(); } I need the equipment(225), technical(0), and personal(48) to be modified depending on what their value is in a database. Anybody know how to do this? Link to comment https://forums.phpfreaks.com/topic/81384-solved-dynamic-values-in-function/ Share on other sites More sharing options...
nogray Posted December 12, 2007 Share Posted December 12, 2007 In your php file price = (document.getElementById('equipment').checked ? <?PHP echo $EquipValue;?> : 0) + (document.getElementById('technical').checked ? <?PHP echo $TechValue;?> : 0) + (document.getElementById('personal').checked ? <?PHP echo $PersValue;?> : 0) + pricekeys[selectedradio.value]; given the $EquipValue, $TechValue and $PersValue is the value from your db. Link to comment https://forums.phpfreaks.com/topic/81384-solved-dynamic-values-in-function/#findComment-413217 Share on other sites More sharing options...
dfowler Posted December 14, 2007 Author Share Posted December 14, 2007 will this work even if this is from an external javascript document? Link to comment https://forums.phpfreaks.com/topic/81384-solved-dynamic-values-in-function/#findComment-415054 Share on other sites More sharing options...
phpQuestioner Posted December 14, 2007 Share Posted December 14, 2007 You can include your "price" variable in your PHP page and then link to your External JavaScript or you can convert you JS file to a PHP file and set the header to be a JavaScript file; then link it like you would any other external JS file - except your script extension would no longer be "js"; it would be "php". It's up to you how you want to do it; the first way, I mentioned, is probably the easiest way. Link to comment https://forums.phpfreaks.com/topic/81384-solved-dynamic-values-in-function/#findComment-415085 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.