Jump to content

[SOLVED] Dynamic Values in Function


dfowler

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.