473,666 Members | 2,640 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to access forms in Mozilla ?

Hi there,

I've got a strange problem.
Used to use IE.
Now switched to Mozilla (1.4).
This works fine in IE but produces nothing (not even an errormessage)
in Mozilla:

<HEAD>
......
<script language="JavaS cript">
<!--
function calc()
{
var i;
var j;
i = calcform.T1.val ue;
j = 2*i;
calcform.T2.val ue = j;
}
-->
</script>
</HEAD>
<BODY>
<form name="calcform" >
<input type='text' id="T1" value='2'>
<input type="button" id="B1" value="multiply by 2" onClick="calc() ">
<input type='text' value='' id=T2>
</form>
.....

Mozilla seems to be unable to access the value of the first (or any)
input type of the form.

Is this a feature of Mozilla, or am I making a mistake somewhere?

Please help !!

Bart

--
Bart Broersma
br************* ********@tiscal i.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 20 '05 #1
12 1356

"Bart" <br************ *********@tisca li.nl> schreef in bericht
news:os******** *************** *********@4ax.c om...

This works fine in IE but produces nothing (not even an errormessage)
in Mozilla:


The proper syntax in Mozilla is:
document.forms['formname'].elements['elementname']

This will also work in IE.

See: http://jibbering.com/faq/
JW

Jul 20 '05 #2
Bart wrote:
This works fine in IE but produces nothing (not even an errormessage)
in Mozilla:
Well, it *does* produce at least one error. Read
<3F************ **@PointedEars. de>. Mozilla/3.0+
log script errors in their JavaScript console.
[...]
<script language="JavaS cript">
<script type="text/javascript">
<!--
function calc()
{
var i;
var j;
i = calcform.T1.val ue;
j = 2*i;
calcform.T2.val ue = j;
}
-->
//-->

Otherwise the comment-closing `--' is considered the JavaScript
decrement operator.
[...]
Mozilla seems to be unable to access the value of the first (or any)
input type of the form.

Is this a feature of Mozilla, or am I making a mistake somewhere?
Yes :)

Try

function calc(oForm)
{
var j = 2 * oForm.elements["T1"].value;
oForm.elements["T2"].value = j;
return j; // a function should always return a value
}

...
<input
type="button"
id="B1"
value="multiply by 2"
onClick="calc(t his.form)"


instead.
PointedEars
Jul 20 '05 #3
In article <3F************ **@PointedEars. de>, Thomas 'PointedEars' Lahn
<Po*********@we b.de> writes:
-->


//-->

Otherwise the comment-closing `--' is considered the JavaScript
decrement operator.


I beg to differ. If it were considered the decrement operator, then it would
throw an error since you can't decrement > and there is nothing after it to
decrement. That makes it an incomplete statement and as such - its an error.

But since no browser (modern) throws an error on it, then it must be safe to
assume that its *not* considered a decrement operator in that context and is
regarded as an incomplete closing comment.
--
Randy
Jul 20 '05 #4
Op Sat, 27 Dec 2003 02:49:47 +0100 schreef Thomas 'PointedEars' Lahn
<Po*********@we b.de>:

<script type="text/javascript"> Yeah, use this syntax now in aal new scripts...

Try

function calc(oForm)
{
var j = 2 * oForm.elements["T1"].value;
oForm.elements["T2"].value = j;
return j; // a function should always return a value
}

...
<input
type="button"
id="B1"
value="multiply by 2"
onClick="calc(t his.form)"
>


instead.
PointedEars


Works fine thanx.

This seems to work fine also though:

function calc()
{
var i = document.calcfo rm.T1.value;
var j = 2*i;
document.calcfo rm.T2.value = j;
}
Which syntax is the preferred one, or is this jus a matter of style
....

Thanks all of you.
Now I've been able to fix my 2 by 2 calculator for statistical
analysis.

Bart
--
Bart Broersma
br************* ********@tiscal i.nl
(ff _ANTISPAM_ wegpoetsen uit dit adres natuurlijk)
Jul 20 '05 #5
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
function calc(oForm)
{
var j = 2 * oForm.elements["T1"].value;
oForm.elements["T2"].value = j;
return j; // a function should always return a value
Could be shortened to
return oForm.elements["T2"].value *= 2;

However, what I really wanted to say was that a function should *not*
always return a value. It should only return a value when it makes
sense.

This function is being used in a context where its return value is
ignored, so there is no reason to complicate the code and make it
look like the return value is important, when it isn't.

And why that value? Why not the previous value of the input element?
If you can't answer that question, then there is no need for the
return at all.

(Or, with a different perspective: functions always return a value -
sometimes it's just the default "undefined" )
<input .... onClick="calc(t his.form)"
>


/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #6
Lasse Reichstein Nielsen <lr*@hotpop.com > writes:
Could be shortened to
return oForm.elements["T2"].value *= 2;


Forget that, I can't read well enough to distinguish T1 and T2 :P

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
function calc(oForm)
{
var j = 2 * oForm.elements["T1"].value;
oForm.elements["T2"].value = j;
return j; // a function should always return a value
Could be shortened to
return oForm.elements["T2"].value *= 2;

However, what I really wanted to say was that a function should *not*
always return a value. It should only return a value when it makes
sense.


Since a function call as an expression can be used in different
contexts, it is simply good style that is returns a useful value,
and may it be only a value indicating success or failure of the
performed operation(s).
(Or, with a different perspective: functions always return a value -
sometimes it's just the default "undefined" )


And because `undefined' is not as easy to handle, a return value
is recommended. BTW: Mozilla/5.0's JavaScript console (rv:1.5+)
yields a warning if a function does not (always) return a value
-- for good reasons.
PointedEars
Jul 20 '05 #8
"Thomas 'PointedEars' Lahn" <Po*********@we b.de> wrote in message
news:3F******** ******@PointedE ars.de...
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
function calc(oForm)
{
var j = 2 * oForm.elements["T1"].value;
oForm.elements["T2"].value = j;
return j; // a function should always return a value
<snip>However, what I really wanted to say was that a function
should *not* always return a value. It should only return
a value when it makes sense.
Since a function call as an expression can be used in
different contexts,


In this respect I would go along with Lasse's "when it makes sense". If
a program wanted to know the value of twice the type-converted numeric
equivalent of the value in a form field then it would make sense to
write a function that read the field, did the math and returned the
value, but I don't see it making sense to assign that value to another
field and then return the value. To me that would suggest that the
function design was not suited to the task(s).

Take a function that sets the top, left, width and height of an
arbitrary absolutely positioned DIV element, a reasonable task to be
allotted to a function in many circumstances (especially if repeatedly
executed on differing DIVs). I cannot see any gain in returning any one
of the many possible individual values and I certainly would not want to
be executing such a heavyweight (in terms of the work the browser might
have to do as a consequence) function just to find out the value of
whatever it was that I had decided the function should return.

Functions may be used in different contexts and can be designed for that
use, but some functions should be designed for use in one context, it
does not make sense to be using them in other contexts and it would
probably be counterproducti ve to attempt to design them in a way that
attempted to make sense in other contexts.
it is simply good style that is returns a useful value,
Style to some extent will always be subjective. There are certainly
plenty of bad styles, we see them paraded through c.l.j on a daily
basis, so there must be better styles and should be good styles. But I
suspect that there cannot be a universal and absolute "correct" style.
Source code formatting is an example where "correct" style is to some
extent subjective. It is widely agreed that source code should be
indented to express its block structure, so code indenting is "good
style". But there are two widespread schools of code indenting (and
numerous less common variants) with the adherents to either recommending
(and teaching) that theirs is the best (possibly just because they find
it the easiest to quickly comprehend) but no real objective grounds for
choosing one over the other. Or at least, when I have read people
claiming that there are reasons for choosing one formatting style over
the other those reasons have never been backed up with anything
substantial or objective.

The use of return statements seems to fall into a similar area. For
example, it has been proposed that functions should not have multiple
exit points, only one return statement at the end (and possibly only
then if a value was to be explicitly returned). Similarly, it has been
proposed that it a statement uses a return statement in any branch of
its code it should have an explicit return statement at every exit
point. Obviously, being mutually exclusive, those two proposals could
not both represent an objectively correct approach to the use of return
statements.

Then there was the suggestion that object methods could always return -
this - whenever they were not returning something specific, so that the
objects could be interacted with using code such as:-

var x = objRef.doThis() .doThat().doThe Other().getX();

-as opposed to:-

objRef.doThis() ;
objRef.doThat() ;
objRef.doTheOth er();
var x = objRef.getX();

The nice thing about that last example was that it was expressed as a
personal style and accompanied with an explanation of the
consequences/uses of the resulting code. So it was very much up to the
reader to make an informed decision about its value and whether they
wanted to adopt it as a style, keep it in mind as a possible
method/strategy or forget about it entirely.
and may it be only a value indicating success or failure
of the performed operation(s).
When knowing the outcome of on operation is important/useful then
returning some indicating value is the obvious approach. But the
original function was using the value it was returning prior to any
consideration of the appropriateness of its use. So maybe it should have
been something more like:-

function twiceT1(oForm){
return (2 * oForm.elements["T1"].value);
}
....
var nTempValue = twiceT1(oForm);
if(!isNaN(nTemp Value)){
oForm.elements["T2"].value = nTempValue;
}
....

- in which nobody would even question the return value in the -
twiceT1 - function, though it would still be questionable whether any
function containing the second block of code needed to be returning a
value.
(Or, with a different perspective: functions always return
a value - sometimes it's just the default "undefined" )


And because `undefined' is not as easy to handle,


Undefined is not that difficult to handle, and if the function call has
no interest in the returned value it doesn't mater much what value it
was anyway. Granted, if the function was expected to return a value that
could be used as an indicator of its success/failure undefined would
probably never be the best value to be deliberately returning, but a
function that intended to return an object may still usefully return
undefined when it failed.
a return value is recommended.
In isolation that statement must be true just because you have
recommended it. But I don't think that you have backed that
recommendation up with anything more than personal opinion.
BTW: Mozilla/5.0's JavaScript console (rv:1.5+) yields a
warning if a function does not (always) return a value
Constructors do not necessarily (usually) have return statements and all
functions may be invoked as constructors, so can Mozilla really tell
when a function without a return statement is never a constructor (and
in any application rather than just the page context of its current
use)? Otherwise this sounds like a recipe for getting developers to
switch off the reporting of warnings in the JavaScript console to avoid
being swamped with what would be little more than uninformed opinion.

You seem to place a lot of faith in the authors of Mozilla. Personally I
find the claim that the Pope is granted divine infallibility more
credible than the implication that something is correct just because
that is the way it is implemented in Mozilla.
-- for good reasons.


A good reason usually being one that can be backed up with well
reasoned, substantial and convincing arguments.

Richard.
Jul 20 '05 #9
Thomas 'PointedEars' Lahn <Po*********@we b.de> writes:
Since a function call as an expression can be used in different
contexts, it is simply good style that is returns a useful value,
and may it be only a value indicating success or failure of the
performed operation(s).
The problem is that it is hard to guess what a useful value is, before
you actually need to use it. Failure or success is best indicated by a
boolean (unless you use exceptions, which is what they are there
for). As I said, a function that sets a property value would be more
useful returning the old value than the new ... but that would be
inconsistent with how the assignment operator works. And in object
oriented methodology, a setter usually doesn't return anything.

Just because a function *can* return a value, I don't think it should.
Just because the language doesn't have procedures (like Pascal) or
functions returning the void type (like Java), doesn't mean that you
should change the underlying design of your program.

A function should return a value only when that value is needed.
Everything else just adds clutter to the program and makes it harder
to maintain ... e.g., when the function later starts needing to
return a value that is different from the one you first guessed at.
And because `undefined' is not as easy to handle, a return value
is recommended.
How is it not easy to handle? It's a better return value than "null",
which is what I would otherwise suggest for a function with no obvious
return value.
BTW: Mozilla/5.0's JavaScript console (rv:1.5+)
yields a warning if a function does not (always) return a value
-- for good reasons.


I can't see that. Can you explain how to trigger such a warning?

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #10

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

Similar topics

11
12077
by: Google Mike | last post by:
I've got RH9 Linux with default PHP. Is there a way to send email on Linux to an Exchange Server from PHP and/or other tools when there is *NOT* SMTP access? Has anyone figured out a way to use PHP to get inside an OWA (Microsoft Outlook Web Access) website to send email that way? The reason I ask is because my corporate office is going to do away with our rogue SMTP server access and force everything through Exchange
39
5672
by: Zak McGregor | last post by:
Hi all Are there any good solutions to aligning form field names and input boxes without resorting to tables? I am struggling to do this nicely at the moment. Thanks Ciao Zak
4
3958
by: Marc Elser | last post by:
Hi Everybody, Can someone please tell me how to access the form name if there's a form field named "name", for example: <form name="myform"> <input type="text" name="name" value="Marc"> <input type="button" onClick="alert(this.form.name);"> </form>
6
5244
by: Jon Davis | last post by:
I recently learned how to do an <OBJECT> alternative to <IFRAME> in current browsers using: <object id="extendedhtml" type="text/html" data="otherpage.html" width="250" height="400"></object> My question is how do I access the document DOM of this object in Javascript? For example, "alert(extendedhtml.innerHTML);" doesn't work and produces an unknown error. I'd like to both read and write to the document's body element's innerHTML...
6
4739
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much appreciated. Thanks in advance
3
3839
by: Manuel | last post by:
My web app was running fine until I decided to change the custom errors parameter in the Web.config file. I set it to "On" and the app stopped working in IE but it works fine in Mozilla! So I turned back to: <customErrors mode="Off" /> and now the problem doesn't go away (in IE). Whenever I click anywhere past the login page it returns back to the login page.
1
1413
by: littlefool | last post by:
Hi, I'm trying to access a XML file in Firefox. It works perfect in IE (with the ActiveXObject), but in Firefox displays it an empty page. I found on the web examples how to do that, but I still have problems with it. Can anyone help me with this? This is the XML-file <?xml version="1.0" encoding="UTF-8"?> <constituencyseats>
8
13158
by: Behzad | last post by:
Hi all, Is there anybody out there who knows how to embed Mozilla engin in CSharp application. There are some useful articles in codeproject.com that show how to work around this issue with IE ; but need embed mozilla in my windows form. thanks in advance Behzad
7
2022
by: JDOMPer | last post by:
Don’t misunderstand me – I use AJAX, but I think there is a far simpler, elegant alternative that just uses Javascript, the DOM and Php ( hence - JDOMP) for data transfers, and is cross-browser without the need for work arounds. JDOMP works in recent versions of Explorer, Mozilla, Safari and Opera. Please note I will not deal with security issues which are always an issue whenever there is access to a database. You can simply change text on...
0
8454
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
8883
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...
0
8787
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8645
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...
1
6203
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4200
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
4372
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2013
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1778
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.