HTML Tutorial


 Forum HomeForum Home   FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
RegisterRegister - Not registered yet? Got something to say? Join HTML Code Tutorial!
Java script help
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript
View previous topic :: View next topic  
Author Message
dlsdawg



Joined: 22 Jan 2006
Posts: 55

PostPosted: Mon Nov 02, 2009 3:06 pm     Java script help Reply with quote

Long time since my last post...

I'm working on a site rebuild and it has a java script that calulates KW-Hrs with a multiplier to I'm working on a site rebuild and it has a java script that calculates KW-Hrs with a multiplier to give you the amount that you would save each month using this company. It works great as it is, but they want to have a drop down menu to pick multiple energy suppliers. Each supplier has a different rate thus a different multiplier for ten different suppliers in the New England States. To complicate all of this, the multiplier for each of these companies change each month thus making it a nightmare to change.

My question is this: To do this would I need to use a Java Script, ASP, or PHP to get this to work. Also could this be linked back to a Access Data Base to make the monthly changes??

Below is the test site and click on the Services button. Yes I know Frames is not the best choice, but they like it... Smile


http://www.dldawg.com/haecpower

Thanks
Dale
BennyBolton



Joined: 07 Nov 2009
Posts: 7

PostPosted: Sun Nov 08, 2009 9:26 pm     Reply with quote

<script language="javascript">

/************************************************************
*** Developed by Benjamin Bolton of Huge Works ***
*************************************************************/

function Calculate(){
var items=document.getElementById("select").options,i,selected=0;
for (i=0;i<items.length;i++){
if (items[i].selected==1){
selected=items[i];
i=items.length;
}
}
if (selected!=0){
document.getElementById("output").innerHTML=document.getElementById("txt").value*selected.value
}
}
</script>
<select id="select">
<option value="1">Multiplier = 1</option>
<option value="2">Multiplier = 2</option>
<option value="3">Multiplier = 3</option>
<option value="4">Multiplier = 4</option>
<option value="5">Multiplier = 5</option>
</select><br>
<input id="txt"><button onclick="Calculate()">Calculate</button><br><div id="output"></div>

This code here should do the trick and it is easy to edit. Very Happy
dlsdawg



Joined: 22 Jan 2006
Posts: 55

PostPosted: Sun Nov 08, 2009 11:19 pm     Reply with quote

Quote:

<select id="select">
<option value="1">Multiplier = 1</option>
<option value="2">Multiplier = 2</option>
<option value="3">Multiplier = 3</option>
<option value="4">Multiplier = 4</option>
<option value="5">Multiplier = 5</option>


Is the option value number in the java script picked up by option in the form?

Code:
  <option>ME - Bangor Hydro</option>


in my line of code from the form do I leave is as option or change it to option value?

And with the Multiplier do I replace the number with the multiplier?

How come with the option value you need quotes and with the Multiplier you don't?

Thanks again for the code Benjamin! I will take a look at it in the morning since its late here.

Will let you know how I make out with it. I don't do enough java programming to remember all of this. I'm sure glad all of you are around!!

Take Care
Dale
BennyBolton



Joined: 07 Nov 2009
Posts: 7

PostPosted: Sun Nov 08, 2009 11:57 pm     Reply with quote

with <option value="x">, x is the multiplier, where it says "multiplier = x", it is just the text in the drop down list. with <option value="x">, it doesn't realy need the quotations, it could just be <option value=x>.
dlsdawg



Joined: 22 Jan 2006
Posts: 55

PostPosted: Mon Nov 09, 2009 9:11 pm     Java Script Calculator Reply with quote

Hi Benny....

I followed your code and worked on it today and have atleast one error. Here is my code as you sent it with a minor change;

Code:


<script language="javascript">

function Calculate(){
var items=document.getElementById("select").options,i,selected=0;
for (i=0;i<items.length;i++){
if (items[i].selected==1){
selected=items[i];
i=items.length;
}
}
if (selected!=0){
document.getElementById("output").innerHTML=document.getElementById("txt").value*selected.value
}
}
</script>
<select id="select">
 <option value=".01114">CT - C L &amp; P</option>
 <option value=".02225">MA - NGRID</option>
 <option value=".00336">MA - NSTAR</option>
 <option value=".01234">MA - WMECO</option>
 <option value=".02345">ME - Bangor Hydro</option>
 <option value=".02451 ">ME - CMP</option>
 <option value=".01784">NH - NGRID</option>
 <option value=".01478">NH - NHEC</option>
 <option value=".01224">NH - PSNH</option>
 <option value=".01567">NH - Unitil</option>
 <option value=".01168">RI - National Grid</option>
</select><br>

<input id="txt"><button onclick="Calculate()">Calculate</button><br><div id="output"></div>



When I run this on a test page I get the following error;

Code:


Line 41
Char. 1
Error Object doesn't support this properly or method




Like 41 is this;

Code:

<input id="txt"><button onclick="Calculate()">Calculate</button><br><div id="output"></div>


I'm looking at the code for the button and don't see a problem. I also need a text box for putting in the electrical usage or was that combined into the text box that shows on the page?

Oh, your code with your name poped up on the page so I pulled it out, will put it back in....

Thanks
Dale
Display posts from previous:   
Post new topic   Reply to topic    HTML Help Forum Index -> Javascript All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
HTML Help Archive
Powered by phpBB © 2001, 2005 phpBB Group
HTML Help topic RSS feed 

 
DARFUR
HOSTING / DESIGN
MAKE MONEY

Home
  |   Tutorials   |   Forum   |   Quick List   |   Link Directory   |   About
Copyright ©1997-2002 Idocs and ©2002-2007 HTML Code Tutorial