473,800 Members | 2,613 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Script Help

Help..

We cannot get this script to work..can someone take a look at it and make
suggestions?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>Conver t Temperature</title>
<script language="javas cript">
<!-- hide from incompatible browsers
function convert_celcius (){
(document.fahre nheit.value - 32)*5/9;
}
function convert_fahrenh eit(){
(document.celci us.value * 1.8)+32;
}
//stop hiding from incompatable browsers -->
</script>
</head>
<body><pre>
<h1>Convert Temperature</h1>
<h3>Enter the temperature in Celcius</h3>
<input type="text" name="fahrenhei t"
onChange="fahre nheit.value";>
<input type="button" value="Convert to Celcius"
onClick="alert( 'Converted to celcius' + convert_celcius[])";><br />
<h3>Enter the temperature in Fahrenheit</h3>
<input type="text" name="celcius"
onChange="celci us.value";>
<input type="button" value="Convert to Fahrenheit"
onClick="alert( 'Converted to Fahrenheit ' + convert_fahrenh eit[]";>
</pre></body>
</html>
Jul 23 '05 #1
6 1619
"Brian" <jo*@joe.com> wrote in message news:2t******** *****@uni-berlin.de...
Help..

We cannot get this script to work..can someone take a look at it and make
suggestions?


[snip]

<html>
<head>
<title>Conver t Temperature</title>
<script type="text/javascript">
function convert_celcius () {
var what = document.getEle mentById("fahre nheit").value;
var temp = (what - 32) * 5 / 9;
document.getEle mentById("celci us").value = temp;
return what + " C = " + temp + " F";
}
function convert_fahrenh eit() {
var what = document.getEle mentById("celci us").value;
var temp = (what * 1.8) + 32;
document.getEle mentById("fahre nheit").value = temp;
return what + " F = " + temp + " C";
}
</script>
</head>
<body>
<pre>
<h1>Convert Temperature</h1>
<h3>Enter the temperature in Celcius</h3>
<input type="text" name="celcius">
<input type="button" value="Convert to Fahrenheit"
onClick="alert( convert_fahrenh eit())">
<br />
<h3>Enter the temperature in Fahrenheit</h3>
<input type="text" name="fahrenhei t">
<input type="button" value="Convert to Celcius"
onClick="alert( convert_celcius ())">
</pre>
</body>
</html>
Jul 23 '05 #2
On Tue, 19 Oct 2004 14:30:12 -0500, Brian <jo*@joe.com> wrote:
Help..

We cannot get this script to work..
In future, please explain what you mean. We can't read minds: you need to
state what *should* occur, what *does* occur, and possibly why that's a
problem.

As things stand, the reasons are clear, here.
can someone take a look at it and make suggestions?
Certainly.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
You should include the URL.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">

Omitting it can fail to switch some browsers into "strict rendering" mode.

[snip]
<script language="javas cript">
The language attribute has been deprecated for several years now. Instead,
use the (required) type attribute.

<script type="text/javascript">
<!-- hide from incompatible browsers
Such browsers aren't in use anymore. If I remember correctly, even
Netscape 2 understood what a SCRIPT element is, and Netscape 4 (and its
generation) are considered the oldest browsers to be considered (and even
that's debatable).
function convert_celcius (){
(document.fahre nheit.value - 32)*5/9;
It's unreasonable to assume that this will obtain a reference to the
control, fahrenheit. You also fail to do anything with the result.

Read the FAQ (<URL:http://jibbering.com/faq/>) and its notes
(<URL:http://www.jibbering.c om/faq/faq_notes/faq_notes.html> ). It contains
information on how to reference elements. You'll either need to include a
FORM, or reference the element with its id.
}
function convert_fahrenh eit(){
(document.celci us.value * 1.8)+32;
The same applies here.
}
//stop hiding from incompatable browsers -->
This should be deleted along with the other SGML comment delimiter.
</script>
</head>
<body><pre>
Why a PRE element? I don't see any preformatted text.
<h1>Convert Temperature</h1>
<h3>Enter the temperature in Celcius</h3>
You shouldn't skip heading levels. If you want to change the style of a
heading, use CSS.
<input type="text" name="fahrenhei t"
onChange="fahre nheit.value";>
That doesn't do anything. It also suffers from the "bad referencing",
earlier.

For future reference, code inside an intrinsic event can use the this
operator to refer to the current element.
<input type="button" value="Convert to Celcius"
onClick="alert( 'Converted to celcius' + convert_celcius[])";>
Functions are called using parentheses, not square brackets.
<br />


You're not writing XHTML, so the slash above is invalid.

From this point on, the mistakes above are repeated.

[snip]

Here's a reworked version of your page:

<URL:http://www.mlwinter.pw p.blueyonder.co .uk/clj/brian/basic.html>

It also includes input validation (will accept integers, reals, and
scientific notation) and number formatting (currently set to display 2
decimal places - the toFixed function handles that).

You'll probably want to ignore the isReal and toFixed functions at the
moment. They aren't really readable. If you want to see the effects of
toFixed, the arguments are:

n - The number to format.
p - The number of decimal places to display. Rounding is performed
automatically. The number here must be no less than 0, and no
more than 20 (the default is zero - return an integer).
g - The grouping symbol to use every three digits (the default is
no symbol).

For example,

toFixed(1234.56 , 1, ',')

will produce the string, "1,234.6".

Hope that helps,
Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #3
On Tue, 19 Oct 2004 19:59:00 GMT, McKirahan <Ne**@McKirahan .com> wrote:

[snip]
var what = document.getEle mentById("fahre nheit").value;
[snip]
<input type="text" name="fahrenhei t">


Mind explaining that, please?

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #4
"Michael Winter" <M.******@bluey onder.co.invali d> wrote in message
news:opsf4zjctt x13kvk@atlantis ...
On Tue, 19 Oct 2004 19:59:00 GMT, McKirahan <Ne**@McKirahan .com> wrote:

[snip]
var what = document.getEle mentById("fahre nheit").value;


[snip]
<input type="text" name="fahrenhei t">


Mind explaining that, please?

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.


What is your question?

I suppose you are suggesting that I use "id=";
I tested this under IE which supports "name=".

Or did you want a reference to a form field?

Would you prefer the following?

<html>
<head>
<title>Conver t Temperature</title>
<script type="text/javascript">
function convert_celcius () {
var what = document.getEle mentById("fahre nheit").value;
var temp = (what - 32) * 5 / 9;
document.getEle mentById("celci us").value = temp;
return what + " F = " + temp + " C";
}
function convert_fahrenh eit() {
var what = document.getEle mentById("celci us").value;
var temp = (what * 1.8) + 32;
document.getEle mentById("fahre nheit").value = temp;
return what + " C = " + temp + " F";
}
</script>
</head>
<body>
<pre>
<h1>Convert Temperature</h1>
<h3>Enter the temperature in Celcius</h3>
<input type="text" id="celcius">
<input type="button" value="Convert to Fahrenheit"
onClick="alert( convert_fahrenh eit())">
<br />
<h3>Enter the temperature in Fahrenheit</h3>
<input type="text" id="fahrenheit" >
<input type="button" value="Convert to Celcius"
onClick="alert( convert_celcius ())">
</pre>
</body>
</html>

Note that the "return" statements were switched from before.
Jul 23 '05 #5
On Wed, 20 Oct 2004 09:53:30 GMT, McKirahan <Ne**@McKirahan .com> wrote:

[snip]
I suppose you are suggesting that I use "id=";
You have to!
I tested this under IE which supports "name=".
Incorrectly.
Or did you want a reference to a form field?
That would do just as well. Probably better, in fact.
Would you prefer the following?


Yes. :)

[snip]

Mike

--
Michael Winter
Replace ".invalid" with ".uk" to reply by e-mail.
Jul 23 '05 #6
McKirahan wrote:

<--snip-->

What is your question?

I suppose you are suggesting that I use "id=";
Personally, I would use name= and the forms collection.
I tested this under IE which supports "name=".
IE supports a lot of things that isn't cross-browser. Thats why it sucks
as a test browser.
Or did you want a reference to a form field?
Thats more cross-browser and more backwards compatible.
Would you prefer the following?
No, see the notes.
<html>
<head>
<title>Conver t Temperature</title>
<script type="text/javascript">
function convert_celcius () {
var what = document.getEle mentById("fahre nheit").value;
var what = document.forms['formName'].elements['farenheit'].value;

var temp = (what - 32) * 5 / 9;
document.getEle mentById("celci us").value = temp;
var what = document.forms['formName'].elements['celsius'].value = temp;
return what + " F = " + temp + " C";
}
function convert_fahrenh eit() {
var what = document.getEle mentById("celci us").value;
var what = document.forms['formName'].elements['celcius'].value;
var temp = (what * 1.8) + 32;
document.getEle mentById("fahre nheit").value = temp;
var what = document.forms['formName'].elements['farenheit'].value = temp;

return what + " C = " + temp + " F";
}
</script>
</head>
<body>
<pre>
<h1>Convert Temperature</h1>
<h3>Enter the temperature in Celcius</h3>
<form name="formName" action="">
<input type="text" id="celcius">
<input type="text" name="celcius">
<input type="button" value="Convert to Fahrenheit"
onClick="alert( convert_fahrenh eit())">
<br />
<h3>Enter the temperature in Fahrenheit</h3>
<input type="text" id="fahrenheit" >
<input type="text" name="fahrenhei t">
<input type="button" value="Convert to Celcius"
onClick="alert( convert_celcius ())">


<form>

Drop the pre's

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
6558
by: dpackwood | last post by:
Hello, I have two different scripts that do pretty much the same thing. The main perl script is on Windows. It runs and in the middle of it, it then calls out another perl script that then should run on a Unix box I have. Both scripts run ok, except for the part when Windows try's to call out the Unix script. I have it set up where the Unix is mapped through a drive letter and can drop stuff into the Unix box. It is going through another...
4
4190
by: hupjack | last post by:
I finally joined the millions of cell phone users out there. I'm the 2nd phone on what is now a family share plan. (Our two cell phones use minutes from a central 400 minute peak time pool.) Looking at the verizon wireless website, minutes used are displayed only as two different totals for our 2 phones. Dialing in from a phones to check remaining minutes, the minutes are presented the same way, broken down by each phone but not...
14
2623
by: Akbar | last post by:
Hey there, Big-time curiosity issue here... Here's the test code (it's not that long)... it's to display a large number of image links with captions, ideally pulled in from an external file (that part's not here -- spotlighting the problem code): --------BEGIN CODE PAGE------------ <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
8
4234
by: Johnny Knoxville | last post by:
I've added a favicon to my site (http://lazyape.filetap.com/) which works fine if you add the site to favourites the normal way, but I have some JavaScript code on a couple of pages with a link, which when you click it bookmarks the site (much easier). The favicon is never saved if the site is bookmarked this way. Does anyone have any ideas how to fix this?? This is the code: <script language="JavaScript">
4
1806
by: Derek | last post by:
I have the following script in a page and it gets an error in IE 6. Says something about an invalid argument but the line number doesn't help since I can't see the javascript code when viewing source. I have this script in a popup page where the user selects a user ID (id) and that value is then placed into one of the parent window's form text field called "userId". This script works fine in the latest Mozilla and Mozilla Firefox but...
0
3232
by: ZMan | last post by:
Scenario: This is about debugging server side scripts that make calls to middle-tier business DLLs. The server side scripts are legacy ASP 3.0 pages, and the DLLs are managed DLLs converted/developed with VB.NET. What I want from debugging is to be able to step into the methods in the DLLs called from ASP scripts using Visual Studio .NET. Background: For typical script debugging issues, you can read and follow the two documents on...
9
4921
by: Harry Smith | last post by:
While reading the documentation on IsStartupScriptRegistered, there is a reference to "client startup script" as "Determines if the client startup script is registered with the Page object." What is meant by "Client Start Script"? Thanks, Harry
3
3688
by: Angus | last post by:
I have a web page with a toolbar containing a Save button. The Save button can change contextually to be a Search button in some cases. Hence the button name searchsavechanges. The snippet of html is: <a class="searchsavechanges btn btn3d tbbtn" href="javascript:" style="position:static"> <div id="TBsearchsavechanges">Search</div> </a>
3
1739
by: David | last post by:
On Sun, May 4, 2008 at 4:43 AM, lev <levlozhkin@gmail.comwrote: Hi, I started tidying up the script a bit, but there are some parts I don't understand or look buggy. So I'm forwarding you the version I have so far. Look for the comments with my e-mail address in them for more information. If I have time I'll tidy up the script some more when I have more info about those issues.
1
47492
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click on a link and after a moment or two a file download dialog box pops-up in your web browser and prompts you for some instructions, such as “open” or “save“. I’m going to show you how to do that using a perl script. What You Need Any recent...
0
9691
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9551
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10507
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10255
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10036
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5473
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5607
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4150
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2948
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.