iPower Hosting
 
Home Register FAQ Members List Calendar Search Today's Posts Mark Forums Read Web Directory

Go Back   Webmaster Forum > Designing and Developing Websites > Programming > Ajax / Javascript

Ajax / Javascript Discussions and help on Ajax and Javascript coding.

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 03-10-2007, 03:46 AM
spinker.spanker spinker.spanker is offline
Persona Non Grata
 
Join Date: Mar 2007
Posts: 72
iTrader: (0)
spinker.spanker is on a distinguished road
Default Creating a simple function script

I know this might be a stupid question, but I really need help on this one because I don't know Javascript at all and I was hoping someone here might be able to help me out.

I have a form where someone will enter a number, say "25" lets call this field "L". They will then press the calculate key and 4 different answers will appear.

#1 - will be the answer of 25*2.05
#2 - will be the answer of 25*1.99
#3 - will be the answer of 25*1.62
#4 - will be the answer of 25*.95

If someone could help me out and explain how I should write this I would appreciate it.
Reply With Quote
Sponsored Links
Register and sign in to hide this ad block

  #2 (permalink)  
Old 03-10-2007, 05:55 AM
killerkev06 killerkev06 is offline
Persona Non Grata
 
Join Date: Mar 2007
Posts: 124
iTrader: (0)
killerkev06 is on a distinguished road
Default

Maybe something like this will help you get started:

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" 
 "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 
<head> 
 <meta http-equiv="Content-Type" content="text/html; charset:utf-8"> 
 <title></title> 
 <script type="text/javascript"> 
function calculate() { 
 var L = document.getElementById('L'); 
 // You should add a check here to make sure the value is numeric 
 var str = ""; 
 str += "#1 " + L.value + " * 2.05 = " + (L.value * 2.05); 
 str += "\n#2 " + L.value + " * 1.99 = " + (L.value * 1.99); 
 str += "\n#3 " + L.value + " * 1.62 = " + (L.value * 1.62); 
 str += "\n#4 " + L.value + " * 0.95 = " + (L.value * 0.95); 
 alert(str); 
} 
function init() { 
 // Attach behaviors 
 var calc = document.getElementById('calc'); 
 calc.onclick = calculate; 
} 
window.onload = init; 
 </script> 
</head> 
<body> 
<form action=""> 
 <div> 
 <input type="text" id="L"> 
 <input type="button" id="calc" value="Calculate"> 
 </div> 
</form> 
</body> 
</html>
Reply With Quote
  #3 (permalink)  
Old 03-10-2007, 07:04 AM
spinker.spanker spinker.spanker is offline
Persona Non Grata
 
Join Date: Mar 2007
Posts: 72
iTrader: (0)
spinker.spanker is on a distinguished road
Default

Thank you so much! Is there a way to get the answer to print write below the input box? Maybe inside a DIV? I tried document.write and that just shows instead of the form. I don't want the answer to appear in a pop up window. Any help would be appreciated? Thanks
Reply With Quote
  #4 (permalink)  
Old 03-10-2007, 11:20 AM
killerkev06 killerkev06 is offline
Persona Non Grata
 
Join Date: Mar 2007
Posts: 124
iTrader: (0)
killerkev06 is on a distinguished road
Default

You'll want to use innerHTML;

Quote:
<input type="button" onclick="document.getElementById('myLayer').innerH TML='something'" />
<br />
<div id="myLayer"></div>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

All times are GMT. The time now is 12:47 PM.



Freelance Web Designers
Work At Home Forum
Ad Marketplace
Online Deals and Bargains
midPhase Web Hosting - $7.95/month - 500 GB B/W! Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0