?
Solved

Javascript using pop-up menu value

Posted on 2007-10-02
3
Medium Priority
?
259 Views
Last Modified: 2008-01-09
I have a javascript that is supposed perform math functions, involving a look up based on what a user elects in a pop-up menu. I made an if-else thing that is supposed to look up the pop-up menu's choice and use various values based on that number. The problem is it only looks p the value when I first open the page. Even though the script is run with an "onclick" it never find the value the pop-p menu has selected by the user.

 function calcROI()
 
 {


      var ROI;
      var INVESTMENT;
      var PROFIT;
      var INVEST_TOT;
      var WEEKLY_COM;
      var NUMBER_COM;
      var BOTTOM_COM;
      var WEEKLY_FRA;
      var NUMBER_FRA;
      var ROYALT_FRA;

 
INVESTMENT = document.inputform.investment.value;


if (document.inputform.investment.value = .01)
 {
INVEST_TOT = 70000;
 }

else if (document.inputform.investment.value = .009)
 {
INVEST_TOT = 45000;
 }
else
{
INVEST_TOT = 15000;

}

     

     
WEEKLY_COM = document.inputform.weekly_company.value;
NUMBER_COM = document.inputform.number_company.value;
BOTTOM_COM = (document.inputform.company_bottom_line.value / 100);
WEEKLY_FRA = document.inputform.weekly_franchise.value;
NUMBER_FRA = document.inputform.number_franchise.value;
ROYALT_FRA = (document.inputform.royalty_franchise.value / 100);
     

      ROI_COM = (((((WEEKLY_COM * 52) * BOTTOM_COM) * NUMBER_COM) * INVESTMENT) / INVEST_TOT);
      ROI_FRA = (((((WEEKLY_FRA * 52) * ROYALT_FRA) * NUMBER_FRA) * INVESTMENT) / INVEST_TOT);
      ROI = Math.round((ROI_COM + ROI_FRA)*100);
      PROFIT_COM = ((((WEEKLY_COM * 52) * BOTTOM_COM) * NUMBER_COM) * INVESTMENT);
      PROFIT_FRA = ((((WEEKLY_FRA * 52) * ROYALT_FRA) * NUMBER_FRA) * INVESTMENT);
      PROFIT = Math.round(PROFIT_COM + PROFIT_FRA);

PROFIT_DONE = "$" + addCommas(PROFIT)
ROI_DONE = ROI + "%"      
      document.inputform.profit_increase.value = PROFIT_DONE;
      document.inputform.roi.value = ROI_DONE;
      document.inputform.investment.value = INVESTMENT
      return false

 }
0
Comment
Question by:daneveland
  • 2
3 Comments
 
LVL 19

Accepted Solution

by:
dakyd earned 2000 total points
ID: 20002207
Without seeing the rest of your setup, we can't be sure.  The one thing that does look wrong, though, is that you're using a single = to test for equality.  In javascript, one equal sign is an assignment operator, and will always return a non-false value.  The logical test for equals is two consecutive equal signs (==).

So, try changing your if-else to this:
if (document.inputform.investment.value == .01)
{
INVEST_TOT = 70000;
 }
else if (document.inputform.investment.value == .009)
 {
INVEST_TOT = 45000;
 }
else
{
INVEST_TOT = 15000;
}

Hope that helps, but if not, can we see how this is being called?  Particularly the onclick & the first time the pop up loads.
0
 

Author Comment

by:daneveland
ID: 20002243
Here is the button and the pop-up

<p class="roi_questions"><select class="roi_form_field_pop_up" name="investment">
              <option label="Significant" value=".01" selected>
                Significant ($70,000)
              </option>
              <option label="Medium" value=".009">
                Medium ($45,000)
              </option>
              <option label="Small" value=".008">
                Light ($15,000)
              </option>
            </select>Select the investment you would like to make in increasing your sales.</p>
            <p class="roi_form_buttons"><button onclick="return calcROI()">Click to calculate ROI</button></p>
0
 

Author Comment

by:daneveland
ID: 20002289
It was the equal sign thing. THANK YOU!!!!!
0

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

601 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question