Home » Forum
NoNumber!

Joomla!® Websites & Extensions
development  -  support  -  consultancy

I try to respond within 48 hours (excluding weekends).
If I haven't responded by then, feel free to post a reminder or bug me via email.

My last reply was: 3 Hours, 10 Minutes ago.

Welcome, Guest
Please Login or Register.    Lost Password?

Custom Code, Form with JavaScript
(1 viewing) (1) Guest
Go to bottomPage: 1
TOPIC: Custom Code, Form with JavaScript
#4763
Custom Code, Form with JavaScript 2 Years, 3 Months ago  
Can anyone help at all?

You see, the code I am about to past works brilliantly in a normaal html page, it adds the calculation down the bottom, but it doesnt work in joomla article with this cool plugin,

anyhelp would be appreciated

thanks


<script type="text/javascript">
  calculate = function(totalElement)
  {
      if (totalElement)
      {  
          var calculation  = '';
          var overall = '';
          var fields = new Array();
          var theElement = document.getElementById(totalElement);
          var userInputs = myform.elements;
          var the_type = '';
          for (var f = 0; f < userInputs.length; f++)
          {
              if (userInputs[f].className=='special_value')
              {
                  if (userInputs[f].type=='select-one')
                  {
                      if(userInputs[f].options[userInputs[f].selectedIndex].value)
                      {
                          fields[f] = userInputs[f].options[userInputs[f].selectedIndex].value;
                      }
                      else
                      {
                          fields[f] = 0;
                      }
                  }
                  else if(userInputs[f].type=='radio' || userInputs[f].type=='checkbox')
                  {
                      if (userInputs[f].checked)
                      {
                          fields[f] = userInputs[f].value;
                      }
                      else
                      {
                          fields[f] = 0;
                      }
                  }
                  else
                  {
                      if (userInputs[f].value)
                      {
                          fields[f] = userInputs[f].value;
                      }
                      else
                      {
                          fields[f] = 0;
                      }
                  }
              }
          }
                    
          for (var i=0; i<fields.length; i++)
          {
              calculation += fields[i];
            
              if (i!=fields.length-1)
              {
                  calculation += '+';
              }
          }
        
          if (calculation!='')
          {
              overall = eval(calculation).toFixed(2);
          }
        
          if (overall!='')
          {
              theElement.innerHTML = '£'+overall;
          }
      }
  }
</script>


<h1>Javacsript Forum Calculator</h1>

<p>
  Enter some numbers, click some checkboxes and radio buttons and watch the value change (bottom of the page).
</p>

<form name="myform">

  <h2>Radio Button</h2>
<input onclick="calculate('total');" name="price111" value="100" class="special_value" type="radio">100<br>
  <input onclick="calculate('total');" name="price111" value="200" class="special_value" type="radio">200<br>
  <input onclick="calculate('total');" name="price111" value="300" class="special_value" type="radio">300<br>
  <input onclick="calculate('total');" name="price111" value="400" class="special_value" type="radio">400<br><br>

  <h2>Checkboxes</h2>
  <input onclick="calculate('total');" name="price112" value="400" class="special_value" type="checkbox">400<br>
  <input onclick="calculate('total');" name="price112" value="600" class="special_value" type="checkbox">600<br>
  <input onclick="calculate('total');" name="price112" value="700" class="special_value" type="checkbox">700<br>
  <input onclick="calculate('total');" name="price112" value="900" class="special_value" type="checkbox">900<br><br>

  <h2>Drop Down Menu</h2>
  <select onchange="calculate('total');" name="price5" class="special_value">
    <option value="0"></option>
    <option value="900">9k</option>
    <option value="500">5k</option>
    <option value="400">4k</option>
  </select>

  <br><br><br>
  <div id="total"></div>

  <input onclick="calculate('total');" name="button" value="re-calculate" type="button">

</form>

cullen90
Posts: 1
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
 
#4764
Custom Code, Form with JavaScript 2 Years, 3 Months ago  
You have posted this in the Open discussion.
But are you using Sourcerer?

If not, do!
And use the Sourcerer editor button to convert the code to 'double bracket syntax'.
Take a look here for more help:
http://www.nonumber.nl/sourcerer

If you can't get it to work like you want, please give the url of the page where you are trying this.
Peter van Westen
Admin
Posts: 9091
User OfflineClick here to see the profile of this user
The administrator has disabled public write access.
Need to contact me directly? Go to my contact page.
If you use any NoNumber! extensions, please post a rating and a review at the Joomla! Extensions Directory.
Are you happy with the support? Please consider buying a License Code to help me to continue development and support.
 
Go to topPage: 1
Moderators: Peter van Westen
MaxCDN | Content Delivery Network | Accelerate your site to the max
Open Source Training | Online Joomla! Training and Support
hosting joomla