473,396 Members | 1,968 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

using var syntax problem

Hi All,

Newbie here needing some syntax assistance. Here is the code:

function fnSelectOption(fieldname)
{
document.mainform. + fieldname + .value = "value";
}

It obvliously bombs where I am trying to ref the param "fieldname". I
realize it is a simple syntax issue but I cannot seem to figure it out. Any
help is greatly appreicated.

JC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #1
10 1173
<script language="jscript">
function fnSelectOption(fieldname)
{
// mainform is referenced in the forms collection and
// fieldname is referenced by name as a form element.
document.forms("mainform")(fieldname).value = "value";
}

</script>
</head>

<body>
<form name="mainform" >
<input type="text" name="text1" width="22">
<input type="button" value="Click Me" onclick="fnSelectOption('text1')";>
</form>

</body>

"DakotaCom" <jc******@rivervalleyit.com> wrote in message news:3f********@corp.newsgroups.com...
Hi All,

Newbie here needing some syntax assistance. Here is the code:

function fnSelectOption(fieldname)
{
document.mainform. + fieldname + .value = "value";
}

It obvliously bombs where I am trying to ref the param "fieldname". I
realize it is a simple syntax issue but I cannot seem to figure it out. Any
help is greatly appreicated.

JC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----

Jul 20 '05 #2
MikeB wrote:
<script language="jscript">
No need for jscript here, just use:
<script type="text/javascript">
function fnSelectOption(fieldname)
{
// mainform is referenced in the forms collection and
// fieldname is referenced by name as a form element.
document.forms("mainform")(fieldname).value = "value";
}


This should be:
document.forms["mainform"][fieldname].value = "value";

(document.forms is not a function and you will get errors in other browsers
than IE)
JW

Jul 20 '05 #3
"MikeB" <m.byerleyATVerizonDottieNettie> wrote in message
news:R8********************@comcast.com...
<script language="jscript">
function fnSelectOption(fieldname)
{
// mainform is referenced in the forms collection and
// fieldname is referenced by name as a form element.
document.forms("mainform")(fieldname).value = "value";
}

<snip>

An obvious alternative to using IE specific code and shielding it form
non-IE browsers is by specifying the language attribute as jscript would
be to use the standard javascript/ECMA Script square bracket notation
property accessor syntax. Which is also fully supported by JScript:-

document.forms['mainform'][fieldname].value = "value";
-or-
document.forms['mainform'].elements[fieldname].value = "value";
-or-
document.forms.mainform.elements[fieldname].value = "value";

<URL: http://www.jibbering.com/faq/#FAQ4_39 >

Richard.
Jul 20 '05 #4
Thanks for the reponses! This seems to work for what I need, it also seems
to be the cleanest:

document.mainform[fieldname].value = "value";

JC
"MikeB" <m.byerleyATVerizonDottieNettie> wrote in message
news:R8********************@comcast.com...
<script language="jscript">
function fnSelectOption(fieldname)
{
// mainform is referenced in the forms collection and
// fieldname is referenced by name as a form element.
document.forms("mainform")(fieldname).value = "value";
}

</script>
</head>

<body>
<form name="mainform" >
<input type="text" name="text1" width="22">
<input type="button" value="Click Me" onclick="fnSelectOption('text1')";>
</form>

</body>

"DakotaCom" <jc******@rivervalleyit.com> wrote in message

news:3f********@corp.newsgroups.com...
Hi All,

Newbie here needing some syntax assistance. Here is the code:

function fnSelectOption(fieldname)
{
document.mainform. + fieldname + .value = "value";
}

It obvliously bombs where I am trying to ref the param "fieldname". I
realize it is a simple syntax issue but I cannot seem to figure it out. Any help is greatly appreicated.

JC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #5
Thanks for the reponses! This seems to work for what I need, it also seems
to be the cleanest:

document.mainform[fieldname].value = "value";

JC
"MikeB" <m.byerleyATVerizonDottieNettie> wrote in message
news:R8********************@comcast.com...
<script language="jscript">
function fnSelectOption(fieldname)
{
// mainform is referenced in the forms collection and
// fieldname is referenced by name as a form element.
document.forms("mainform")(fieldname).value = "value";
}

</script>
</head>

<body>
<form name="mainform" >
<input type="text" name="text1" width="22">
<input type="button" value="Click Me" onclick="fnSelectOption('text1')";>
</form>

</body>

"DakotaCom" <jc******@rivervalleyit.com> wrote in message

news:3f********@corp.newsgroups.com...
Hi All,

Newbie here needing some syntax assistance. Here is the code:

function fnSelectOption(fieldname)
{
document.mainform. + fieldname + .value = "value";
}

It obvliously bombs where I am trying to ref the param "fieldname". I
realize it is a simple syntax issue but I cannot seem to figure it out. Any help is greatly appreicated.

JC


-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----




-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 100,000 Newsgroups - 19 Different Servers! =-----
Jul 20 '05 #6
"DakotaCom" <jc******@rivervalleyit.com> writes:

Please don't top post, or at least trim your quotes.
Thanks for the reponses! This seems to work for what I need, it also seems
to be the cleanest:

document.mainform[fieldname].value = "value";


"*Seems* to work" is correct, at least for the browser you used.
It fails in, e.g., Mozilla/Netscape, because they don't make the form
a property of the document element.

Use
document.forms['mainform'] (or the equivalent: document.forms.mainform)
instead of just
document.mainform
That is the minimum you can write that works in all Javascript enabled
browsers.

Personally I prefer to use the "elements" collection, so it is
document.forms['mainform'].elements[fieldname].value = "value"
I think it is most consistent.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
How come you guys always answer AFTER you've had your coffee.... ;-)

"Richard Cornford" <Ri*****@litotes.demon.co.uk> wrote in message
news:bs*******************@news.demon.co.uk...
"MikeB" <m.byerleyATVerizonDottieNettie> wrote in message
news:R8********************@comcast.com...
<script language="jscript">
function fnSelectOption(fieldname)
{
// mainform is referenced in the forms collection and
// fieldname is referenced by name as a form element.
document.forms("mainform")(fieldname).value = "value";
}

<snip>

An obvious alternative to using IE specific code and shielding it form
non-IE browsers is by specifying the language attribute as jscript would
be to use the standard javascript/ECMA Script square bracket notation
property accessor syntax. Which is also fully supported by JScript:-

document.forms['mainform'][fieldname].value = "value";
-or-
document.forms['mainform'].elements[fieldname].value = "value";
-or-
document.forms.mainform.elements[fieldname].value = "value";

<URL: http://www.jibbering.com/faq/#FAQ4_39 >

Richard.

Jul 20 '05 #8
Lasse Reichstein Nielsen wrote:
"DakotaCom" <jc******@rivervalleyit.com> writes:
Thanks for the reponses! This seems to work for what I need, it also seems
to be the cleanest:

document.mainform[fieldname].value = "value";
"*Seems* to work" is correct, at least for the browser you used.
It fails in, e.g., Mozilla/Netscape, because they don't make the form
a property of the document element.


WFM in Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7a)
Gecko/2004010908.

But I agree to the rest of your statements because of
[example using document.forms]
That is the minimum you can write that works in all Javascript enabled
browsers.
[...]

PointedEars
Jul 20 '05 #9
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
WFM in Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7a)
Gecko/2004010908.


Mozilla makes the form a property of the document if it is named using
the name attribute, and not if it is named only using the id attribute.
In the example I used (as most of the code I write) I only used id.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #10
Lasse Reichstein Nielsen wrote:
Thomas 'PointedEars' Lahn <Po*********@web.de> writes:
WFM in Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7a)
Gecko/2004010908.
Mozilla makes the form a property of the document if it is named using
the name attribute, and not if it is named only using the id attribute.


True. Interestingly, it makes form elements a property of the form
object even if only the ID attribute is used.
In the example I used (as most of the code I write) I only used id.


You know, my magic Crystal Ball[tm] is still on holiday :)

Besides, you know that you become incompatible with older browsers
when using only the ID attribute for naming elememts but also access
them through collections/arrays?
PointedEars
Jul 20 '05 #11

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

Similar topics

16
by: George Sakkis | last post by:
I'm sure there must have been a past thread about this topic but I don't know how to find it: How about extending the "for <X> in" syntax so that X can include default arguments ? This would be very...
19
by: Nicolas Fleury | last post by:
Hi everyone, I would to know what do you think of this PEP. Any comment welcomed (even about English mistakes). PEP: XXX Title: Specialization Syntax Version: $Revision: 1.10 $...
121
by: typingcat | last post by:
First of all, I'm an Asian and I need to input Japanese, Korean and so on. I've tried many PHP IDEs today, but almost non of them supported Unicode (UTF-8) file. I've found that the only Unicode...
12
by: Phil Powell | last post by:
<cfquery name="getAll" datasource="#request.dsn#"> SELECT U.userID, U.fname, U.lname, U.phone, U.lastLoggedIn, U.choiceId, U.experience, T.label AS teamLabel, R.label AS roleLabel FROM User U...
5
by: Tom | last post by:
I've used heredocs for single SQL statements without a problem. Also, I've tried this using the SQL form on PhpMyAdmin and it works so I conclude it should work in PHP. Problem: getting syntax...
9
by: Bern McCarty | last post by:
I am porting stuff from MEC++ syntax to the new C++/CLI syntax. Something that we did in the old syntax that proved to be very valuable was to make sure that the finalizer would purposefully...
4
by: Regnab | last post by:
I've got a form - "frmLookup" (with a subform) that works very happily on its own. The form has a list box, which when updated requeries the subform to display the appropriate results. The...
1
by: ligong.yang | last post by:
Hi all, I got tortured by a very weird problem when I was using k. wilder's random generator class in my program. PS: wilder's generator class can be found at...
7
by: bryant | last post by:
Hi all. I am new to ASP and working in Expression Web. The following query displays the information I need in the gridview for a single record. SELECT "OE_HDR"."ORD_NO", "OE_HDR"."CUST_NAM",...
5
by: lokeshrajoria | last post by:
hello everyone, i am new in this community. i have some problem in checking and validation of data acording to syntax. which i have given below.. my problem is i want to check...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...
0
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.