Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Here's a challenge 1

Status
Not open for further replies.

gms27

Technical User
Aug 19, 2005
27
PT
I there,

I'm using this javascriptkit.com word counter to count words in my web site:

<script language="JavaScript">

function countit(){

/*Word count script
By JavaScript Kit (Over 400+ free scripts here!
*/

var formcontent=document.wordcount.wordcount2.value
formcontent=formcontent.split(" ")
document.wordcount.wordcount3.value=formcontent.length
}
</script>
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="100%"><textarea rows="12" name="wordcount2" cols="60" wrap="virtual"></textarea></td>
</tr>
<tr>
<td width="100%"><div align="right"><p><input type="button" value="Calculate Words"
onClick="countit()"> <input type="text" name="wordcount3" size="20"></p>
<div align="center"><center><p><font face="arial" size="-2">This free script provided by</font>
<font face="arial, helvetica" size="-2"><a href=" Kit</a></font></p>
</center></div></div></td>
</tr>
</table>
</form>

I would like to know how can i make the result of the word count be multiplyed by selecting one of the currencies in this menu:

<form name="form1" method="post" action="">
<select name="Currency" id="Currency">
<option value="0" selected>Select Currency</option>
<option value="0.09">Euros</option>
<option value="0.11">US Dollars</option>
<option value="0.06">GB Pounds</option>
<option value="0.25">Reais</option>
<option value="0.13">CA Dollars</option>
<option value="9.2">AOA</option>
<option value="2916.45">MZM</option>
<option value="9.92">CVA</option>
</select>
</form>

Here's the general ideia: A visitor would count his text's words in the word count text box, then he would select the type of currency he would like, and automatically the result of the multiplication of the number of words by the value of the currency would appear in a small text box next to the menu.


I know that this is not much but if someone can make this work i will include his name/nickname/web page in my web site's thanks page. :)


Thanks in advance.

BTW: The web page is Some opinions about it would be very welcomed (good or bad)
 
Code:
<html>
<head>
<script>
function countit(){
var formcontent=document.getElementById("wordcount2").value;
formcontent = formcontent.split(" ");
var count = formcontent.length
document.getElementById("count").value = count ; 
document.getElementById("countx").value = (count * document.getElementById("Currency").value); 
}
</script>
</head>
<body>
<table border="1">
    <tr>
      <td width="100%"><textarea rows="12" name="wordcount2" cols="70" wrap="virtual"> Paste your text here.</textarea></td>
    </tr>
    <tr>
      <td>
		<form name="form1" method="post" action="">
			<input type="button" value="Calculate Words" onClick="countit()"> 
			<input name="count" id="count" type="text" id="price" size="20">  
			<input name="countx" id="countx" type="text" id="price" size="20">  
		  	<select name="Currency" id="Currency">
				<option value="0" selected>Select Currency</option>
				<option value="0.09">Euros</option>
				<option value="0.11">US Dollars</option>
				<option value="0.06">GB Pounds</option>
				<option value="0.25">Reais</option>
				<option value="0.13">CA Dollars</option>
				<option value="9.2">AOA</option>
				<option value="2916.45">MZM</option>
				<option value="9.92">CVA</option>
		  	</select>
		</form>
</body>
</html>

I don't know the answer but my good friend Google does.
 
This works for me:

Code:
<html>
<head>
	<script type="text/javascript">
	<!--

		function calculateCost(currencyMultiplier, frm) {
			var numberOfWords = 7;
			frm.elements['finalCost'].value = (parseFloat(currencyMultiplier) * numberOfWords).toFixed(2);
		}

	//-->
	</script>
</head>

<body>
	<form name="form1" method="post" action="">
		<select name="Currency" id="Currency" onchange="calculateCost(this.value, this.form);">
			<option value="0" selected>Select Currency</option>
			<option value="0.09">Euros</option>
			<option value="0.11">US Dollars</option>
			<option value="0.06">GB Pounds</option>
			<option value="0.25">Reais</option>
			<option value="0.13">CA Dollars</option>
			<option value="9.2">AOA</option>
			<option value="2916.45">MZM</option>
			<option value="9.92">CVA</option>
		</select>
		<input type="text" name="finalCost" value="" />
	</form>
</body>
</html>

Replace the "numberOfWords" variable with your word count in the calculation line.

Hope this helps,
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
To j4606: When i enter your code an error message appears

Invalid Markup -it contains a duplicate attribute- <input

<input name="count" id="count" type="text" id="price" size="20">
<input name="countx" id="countx" type="text" id="price" size="20">


To BillyRayPreacherSon: Sorry i dont know much about codes, i can only recognize what to put in head and body...
 
Code:
<html>
<head>
<script>
function countit(){
var formcontent=document.getElementById("wordcount2").value;
formcontent = formcontent.split(" ");
var count = formcontent.length
document.getElementById("count").value = count ; 
document.getElementById("countx").value = (count * document.getElementById("Currency").value); 
}
</script>
</head>
<body>
<table border="1">
    <tr>
      <td width="100%"><textarea rows="12" name="wordcount2" cols="70" wrap="virtual"> Paste your text here.</textarea></td>
    </tr>
    <tr>
      <td>
		<form name="form1" method="post" action="">
		  	<select name="Currency" id="Currency">
				<option value="0" selected>Select Currency</option>
				<option value="0.09">Euros</option>
				<option value="0.11">US Dollars</option>
				<option value="0.06">GB Pounds</option>
				<option value="0.25">Reais</option>
				<option value="0.13">CA Dollars</option>
				<option value="9.2">AOA</option>
				<option value="2916.45">MZM</option>
				<option value="9.92">CVA</option>
		  	</select>
			<input type="button" value="Calculate Words" onClick="countit()"> 
			<input name="count" id="count" type="text" size="20">  
			<input name="countx" id="countx" type="text"  size="20">  
		</form>
</body>
</html>
;/

I don't know the answer but my good friend Google does.
 
Sorry i dont know much about codes, i can only recognize what to put in head and body...

All you need to modify in my code is to add whatever calculation you are using to count the number of words - you already have this, so it should plug right in.
Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
thanks j4606! it works fine now ;)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top