Google Answers Logo
View Question
 
Q: Javascript question: How can I have several scripts on one page? ( No Answer,   3 Comments )
Question  
Subject: Javascript question: How can I have several scripts on one page?
Category: Computers > Programming
Asked by: ekle-ga
List Price: $5.00
Posted: 19 Jan 2005 11:12 PST
Expires: 18 Feb 2005 11:12 PST
Question ID: 459942
I would like to have several conversion scripts run on a single html page... 
Right now, one will work, but the others will not. Want to have them
all available and function.

Thanks in advance!
Example of 2 of the scripts:

<p>
<table>
<script>
<!-- // --> <h1>Your browser does not support <a
href="http://www.netscape.com/comprod/products/navigator/version_2.0/script/script_info/">JavaScript</a>,
sorry</h1>.
<!-- // -->The conversion table below will not work with your browser<p><hr>

<!--
function Area() {
	this.mm2=0.000001
	this.cm2=0.0001
	this.decm=0.01
	this.dekm=100
	this.xxx2=0.09290304/144
	this.ft2=0.09290304
	this.centiare=1
	this.meter2=1 
	this.yd2=0.09290304*9 
	this.are2=100
	this.acre=0.09290304*43560
	this.cacre=0.09290304*36000
 	this.hectare=10000 
	this.km2=1000000
	this.mi2=0.09290304*27878400



}

data = new Area();

function checkNum(str) {
	for (var i=0; i<str.length; i++) {
	var ch = str.substring(i, i + 1)
	if (ch!="." && ch!="+" && ch!="-" && ch!="e" && ch!="E" && (ch < "0"
|| ch > "9")) {
		alert("Please enter a valid number.");
		return false
		}
	}
	return true
}

function normalize(what,digits) {
	var str=""+what;
	var pp=Math.max(str.lastIndexOf("+"),str.lastIndexOf("-"));
	var idot=str.indexOf(".");
	if (idot>=1) {
		var ee=(pp>0)?str.substring(pp-1,str.length):"";
		digits+=idot;
		if (digits>=str.length)
			return str;
		if (pp>0 && digits>=pp)
			digits-=pp;
		var c=eval(str.charAt(digits));
		var ipos=digits-1;
		if (c>=5) {
			while (str.charAt(ipos)=="9") ipos--;
			if (str.charAt(ipos)==".") {
				var nc=eval(str.substring(0,idot))+1;
				if (nc==10 && ee.length>0) {
					nc=1;
					ee="e"+(eval(ee.substring(1,ee.length))+1);
				}
				return ""+nc+ee;
			}
			return str.substring(0,ipos)+(eval(str.charAt(ipos))+1)+ee;
		} else
			var ret=str.substring(0,digits)+ee;
			for (var i=0; i<ret.length; i++)
				if (ret.charAt(i)>"0" && ret.charAt(i)<="9")
					return ret;
			return str;
	 }
	 return str;
}

function compute(obj,val) {
	if (obj[val].value) {
		var uval=0;
		uval = obj[val].value*data[val];
		for (var i in data)
			obj[i].value=normalize(uval/data[i],8);
	}
}

// -->

</SCRIPT>

<left>
<p>
<TR>
<TD ALIGN="left">
<TABLE ID="mens suits" BORDER=0 CELLSPACING=3 CELLPADDING=1 WIDTH=525>
<TR>
<TD COLSPAN=8 BGCOLOR="#003060" HEIGHT=15>
<P ALIGN=LEFT><FONT SIZE="3"
FACE="Arial,Helvetica,Sans-serif,sans-serif"></FONT><FONT
COLOR="#efefef" SIZE="3"
FACE="Arial,Helvetica,Sans-serif,sans-serif"><B>Area</B></FONT><B></B></P>
                                                            </TD>
                                                            </TR>

</p>
</left>  


  

</br>
</br>
<P><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3 WIDTH="100%">

<CENTER>
<table border="0">
     <colgroup>
        <col width="270">
        <col width="20">
        <col width="270">
     </colgroup>

<center>

<tr><td align="right"><b>Quadratmillimeter</b></br>&nbsp;mm&#178;</right></td>
<td><center><input type="text" name="mm2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square millimeter</b></br>&nbsp;mm&#178;,&nbsp;sq
mm</left></td>
</tr>
</center>

<tr><td align="right"><b>Quadratzentimeter</b></br>cm&#178;</right></td>
<td><center><input type="text" name="cm2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square centimeter</b></br>&nbsp;cm&#178;,&nbsp;sq
cm</left></td>
</tr>
</center>

<tr><td align="right"><b>Quadratdezimeter</b></br>dm&#178;</right></td>
<td><center><input type="text" name="decm" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square decimeter</b></br>&nbsp;dm&#178;,&nbsp;sq dm</left></td>
</tr>
</center>



<tr><td align="right"><b>Quadratmeter</b></br>m&#178;</right></td>
<td><center><input type="text" name="meter2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square meter</b></br>&nbsp;m&#178;,&nbsp;sq m</left></td>
</tr>

<tr><td align="right"><b>Quadratdekameter</b></br>&nbsp;</right></td>
<td><center><input type="text" name="dekm" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square
dek(c)ameter</b></br>&nbsp;dam&#178;,&nbsp;sq dam</left></td>
</tr>
</center>

<tr><td align="right"><b>Quadratkilometer</b></br>km&#178;</right></td>
<td><center><input type="text" name="km2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square kilometer</b></br>&nbsp;km&#178;,&nbsp;sq km</left></td>
</tr>

<tr><td align="right"><b>Hektar</b></br>&nbsp;</right></td>
<td><center><input type="text" name="hectare" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>hectare</b></br>&nbsp;ha</left></td>
</tr>

<tr><td align="right"><b>Ar</b></br>&nbsp;</right></td>
<td><center><input type="text" name="are" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>are</b></br>&nbsp;a</left></td>
</tr>

<tr><td align="right"><b></b></br>&nbsp;</right></td>
<td><center><input type="text" name="centiare" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>centiare</b></br>&nbsp;ca</left></td>
</tr>



<p>
<td  align="center"
      <tr>
   <td align="center"><input name="clear1" type="reset" value="Clear"> &nbsp; </td>
        </tr>
  
</center>
</p>



<tr><td align="right"><b>Quadratzoll</b></br>&nbsp;</right></td>
<td><center><input type="text" name="xxx2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square inch</b></br>&nbsp;in&#178;,&nbsp;sq in</left></td>
</tr>
</center>

<tr><td align="right"><b>Quadratfuss</b></br>&nbsp;</right></td>
<td><center><input type="text" name="ft2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)" </td>
<td align="left"><b>square foot</b></br>&nbsp;ft&#178;,&nbsp;sq ft</left></td>
</tr>
</center>

<tr><td align="right"><b>Quadratyard</b></br>&nbsp;</right></td>
<td><center><input type="text" name="yd2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square yard</b></br>&nbsp;yd&#178;,&nbsp;sq yd</left></td>
</tr>

<tr><td align="right"><b>Quadratmeile</b></br>&nbsp;mi&#178;</right></td>
<td><center><input type="text" name="mi2" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>square mile</b></br>&nbsp;mi&#178;,&nbsp;sq mi</left></td>
</tr>

<tr><td align="right"><b>Acker</b></br>&nbsp;</right></td>
<td><center><input type="text" name="acre" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>acre</b></br>&nbsp;ac</left></td>
</tr>

<tr><td align="right"><b></b></br>&nbsp;</right></td>
<td><center><input type="text" name="cacre" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</td>
<td align="left"><b>acre&nbsp;(commercial)</b></br>&nbsp;ac</left></td>
</tr>

</center>
</table>

</p>











<p>

<table>
<script>
<!-- // --> <h1>Your browser does not support <a
href="http://www.netscape.com/comprod/products/navigator/version_2.0/script/script_info/">JavaScript</a>,
sorry</h1>.
<!-- // -->The conversion table below will not work with your browser<p><hr>

<!--
function DISTANCE() {
	this.mm=0.001
	this.cm=0.01
	this.dcm=0.10
	this.dam=10
	this.inch=0.3048/12
	this.ft=0.3048
	this.meter=1 
	this.yd=0.9144  
	this.km=1000
	this.mi=0.3048*5280 
	this.nmi=1852 
}

data = new DISTANCE();

function checkNum(str) {
	for (var i=0; i<str.length; i++) {
	var ch = str.substring(i, i + 1)
	if (ch!="." && ch!="+" && ch!="-" && ch!="e" && ch!="E" && (ch < "0"
|| ch > "9")) {
		alert("Please enter a valid number.");
		return false
		}
	}
	return true
}

function normalize(what,digits) {
	var str=""+what;
	var pp=Math.max(str.lastIndexOf("+"),str.lastIndexOf("-"));
	var idot=str.indexOf(".");
	if (idot>=1) {
		var ee=(pp>0)?str.substring(pp-1,str.length):"";
		digits+=idot;
		if (digits>=str.length)
			return str;
		if (pp>0 && digits>=pp)
			digits-=pp;
		var c=eval(str.charAt(digits));
		var ipos=digits-1;
		if (c>=5) {
			while (str.charAt(ipos)=="9") ipos--;
			if (str.charAt(ipos)==".") {
				var nc=eval(str.substring(0,idot))+1;
				if (nc==10 && ee.length>0) {
					nc=1;
					ee="e"+(eval(ee.substring(1,ee.length))+1);
				}
				return ""+nc+ee;
			}
			return str.substring(0,ipos)+(eval(str.charAt(ipos))+1)+ee;
		} else
			var ret=str.substring(0,digits)+ee;
			for (var i=0; i<ret.length; i++)
				if (ret.charAt(i)>"0" && ret.charAt(i)<="9")
					return ret;
			return str;
	 }
	 return str;
}

function compute(obj,val) {
	if (obj[val].value) {
		var uval=0;
		uval = obj[val].value*data[val];
		for (var i in data)
			obj[i].value=normalize(uval/data[i],8);
	}
}

// -->

</SCRIPT>

<left>
<p>
<TR>
<TD ALIGN="left">
<TABLE ID="mens suits" BORDER=0 CELLSPACING=3 CELLPADDING=1 WIDTH=525>
<TR>
<TD COLSPAN=8 BGCOLOR="#003060" HEIGHT=15>
<P ALIGN=LEFT><FONT SIZE="3"
FACE="Arial,Helvetica,Sans-serif,sans-serif"></FONT><FONT
COLOR="#efefef" SIZE="3"
FACE="Arial,Helvetica,Sans-serif,sans-serif"><B>Distance</B></FONT><B></B></P>
                                                            </TD>
                                                            </TR>

</p>
</left>  


</br>
</br>
<P><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3 WIDTH="100%">

<CENTER>
<table border="0">
     <colgroup>
        <col width="270">
        <col width="20">
        <col width="270">
     </colgroup>

<center>



<tr><td align="right"><b>Millimeter</b></br>mm</right></td>
<td><center><input type="text" name="mm" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br> </td>
<td align="left"><b>millimeter</b></br>mm</left></td>
</tr>
</center>

<tr><td align="right"><b>Zentimeter</b></br>cm</right></td>
<td><center><input type="text" name="cm" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br> </td>
<td align="left"><b>centimter</b></br>cm</left></td>
</tr>
</center>

<tr><td align="right"><b>Dezimeter</b></br>dm</right></td>
<td><center><input type="text" name="dcm" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br> </td>
<td align="left"><b>decimeter</b></br>dm</left></td>
</tr>
</center>



<tr><td align="right"><b>Meter</b></br>m</right></td>
<td><center><input type="text" name="meter" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br> </td>
<td align="left"><b>meter</b></br>m</left></td>
</tr>
</center>

<tr><td align="right"><b>Dekameter</b></br>dam</right></td>
<td><center><input type="text" name="dam" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br> </td>
<td align="left"><b>dek(c)ameter</b></br>dam</left></td>
</tr>
</center>

<tr><td align="right"><b>Kilometer</b></br>km</right></td>
<td><center><input type="text" name="km" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br></td>
<td align="left"><b>kilometer</b></br>km</left></td>
</tr>
</center>

<p>
<td  align="center"
      <tr>
   <td align="center"><input name="clear1" type="reset" value="Clear"> &nbsp; </td>
        </tr>
  
</center>
</p>

<tr><td align="right"><b>Zoll</b></br>('')</right></td>
<td><center><input type="text" name="inch" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)" </td>
<td align="left"><b>inch</b></br>in,('')</left></td>
</tr>
</center>
         
<tr><td align="right"><b>Fuss</b></br>(')</right></td>
<td><center><input type="text" name="ft" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br></td>
<td align="left"><b>foot</b></br>ft,(')</left></td>
</tr>
</center>



<tr><td align="right"><b>Yard</b></br>&nbsp;</right></td>
<td><center><input type="text" name="yd" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br> </td>
<td align="left"><b>yard</b></br>yd</left></td>
</tr>
</center>



<tr><td align="right"><b>Meile</b></br>&nbsp;</right></td>
<td><center><input type="text" name="mi" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br></td>
<td align="left"><b>mile</b></br>mi</left></td>
</tr>

<tr><td align="right"><b>Seemeile</b></br>sm</right></td>
<td><center><input type="text" name="nmi" size="11" onchange="if
(checkNum(this.value))compute(this.form,this.name)"</br></td>
<td align="left"><b>mile (nautical)</b></br>nm</left></td>
</tr>

</center>
</table>
</p>
Answer  
There is no answer at this time.

Comments  
Subject: Re: Javascript question: How can I have several scripts on one page?
From: dpakoh-ga on 19 Jan 2005 14:45 PST
 
I think this should be written by using setTimeout("method()",1000);
Subject: Re: Javascript question: How can I have several scripts on one page?
From: ekle-ga on 19 Jan 2005 16:10 PST
 
Hi dpakoh-ga!  Thank you for the quick reply....

That sounds ok, but I have no idea what that means or where to add it.
I understand the code, sort of, but have no idea what makes it work
(and not work).
Do you know how o make this work?
m
Subject: Re: Javascript question: How can I have several scripts on one page?
From: eliteskills-ga on 18 Feb 2005 10:55 PST
 
You can either:

Make sure the variable names are not duplicated thought all the codes 

or

you can just add html iframes each containing a script.



I would choose option two.

I'm too lazy to fix the scripts.

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy