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

Home Posts Topics Members FAQ

another document.[formName] has no properties error

apologies in advance, as not only am i new to learning how to code
javascript properly, i'm new to the groups posting thing...

i am developing in firefox 1.0+, but will be working in an msie 6.0+
produciton environment ( not my choice, but when is it ever? ).

the desired output is that when the end-user selects two radio buttons,
one from each 'group', the form / page will open an alert window
displaying the values of the radio buttons selected without having the
end-user left-click on a submit button.

i cannot figure out why I'm getting the "document.[formName] has no
properties" error mesasage in the javascript console.

any advice, assistance, comments or suggestions will be appreciated.

michael
this is what i've got thus far - - -

( located within the head tags )

<script language = "javascript " type = "text/javascript">
var myFirstVariable = "";
var mySecondVariabl e = "";

function optionSelected ()
{
for (i = 0; i < 4; i++);
{
if (document.[formName].myFirstVariabl e[i]checked == true);
{
firstVariableNa me = document.[formName].myFirstVariabl e.value;
}
}
for (i = 0; i < 1; i++);
{
if (document.[formName].mySecondVariab le[i].checked == true);
{
seconVariableNa me = document.[formName].mySecondVariab le.value;
}
}
alert("the radio buttons selected were + " + firstVariableNa me + " and
" + secondVariableN ame + ".");
}

</script>

....and then my form looks like...

( located within the body tags )

<form name = "formName">
<p>
<input type = "radio" name = "myFirstVariabl e" value = "option1"
onClick = "optionSelected ()">Option1<b r>
<input type = "radio" name = "myFirstVariabl e" value = "option2"
onClick = "optionSelected ()">Option2<b r>
<input type = "radio" name = "myFirstVariabl e" value = "option3"
onClick = "optionSelected ()">Option3<b r>
<input type = "radio" name = "myFirstVariabl e" value = "option4"
onClick = "optionSelected ()">Option4<b r>
<input type = "radio" name = "myFirstVariabl e" value = "option5"
onClick = "optionSelected ()">Option5<b r>
</p>
<p>
<input type = "radio" name = "mySecondVariab le" value = "option1"
onClick = "optionSelected ()">Option1<b r>
<input type = "radio" name = "mySecondVariab le" value = "option2"
onClick = "optionSelected ()">Option2<b r>
</p>
</form>

Oct 9 '05 #1
7 2954
michael wrote:
function optionSelected ()
{
for (i = 0; i < 4; i++);

The semicolon should be omitted here.
{
if (document.[formName].myFirstVariabl e[i]checked == true);
{


Again, the semicolon should be omitted here and the form field should be
referenced as follows:

document.forms[formName].elements['myFirstVariabl e'][i].checked
JW

Oct 9 '05 #2
michael wrote:
apologies in advance, as not only am i new to learning how to code
javascript properly, i'm new to the groups posting thing...

i am developing in firefox 1.0+, but will be working in an msie 6.0+
produciton environment ( not my choice, but when is it ever? ).

the desired output is that when the end-user selects two radio buttons,
one from each 'group', the form / page will open an alert window
displaying the values of the radio buttons selected without having the
end-user left-click on a submit button.

i cannot figure out why I'm getting the "document.[formName] has no
properties" error mesasage in the javascript console.

any advice, assistance, comments or suggestions will be appreciated.

michael
this is what i've got thus far - - -

( located within the head tags )

<script language = "javascript " type = "text/javascript">
The language attribute is depreciated, keep the text attribute. You
may find it easier to read your code if you don't leave spaces between
the attribute name, the '=' and the value:

<script type="text/javascript">

var myFirstVariable = "";
var mySecondVariabl e = "";
You have made two global variables that clash with the names you've
used in your forms. They may make life difficult, so either chose
better names or don't use them at all.

function optionSelected ()
{
for (i = 0; i < 4; i++);
If you declare variables inside a function without using 'var', the
variables become global. That can cause real problems with counters
in particular. Always keep variables local unless there is a really
good reason for them to be global.

for (var i=0; i<4; i++);

{
if (document.[formName].myFirstVariabl e[i]checked == true);


You have a couple of problems here. Firstly, you are using square
brackets incorrectly - they are used to access a property of an
object, they can't be used on their own. Read the FAQ:

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

Given that your form is called 'formName', you can reference it as:

document.formNa me;
or
document.forms['formName'];

The second method is preferred. You can generally do the same thing
with form controls:

document.formNa me.myFirstVaria ble;
or
document.forms['formName'].elements['myFirstVariabl e'];

or some combination of the two. Again, the second is preferred.

*But*, whenever there are a number of form controls with the same name
(like radio buttons) then you will get back a collection, not a single
element:

var rButtons = document.formNa me.myFirstVaria ble;

Now, to get the one that is checked:

var firstSelected;
for (var i=0, j=rButtons.leng th; i<j; i++){
if (rButtons[i].checked){
firstValue = rButtons[i].value;
}
}

Note that you don't have to compare (rButtons[i].checked == true)
because if it's checked, rButtons[i].checked will return true anyway
(or false if it's not).

Often the best way to get a reference to something that has been
clicked on is to use 'this', it give a reference directly to the
element without the hassle of hard-coded form or control names.
Here's some play code that should get you going:

<script type="text/javascript">

function showChecked(f)
{
var el;
var message = '';
var buttonNames = ['myFirstVariabl e','mySecondVar iable'];

for (var i=0, j=buttonNames.l ength; i<j; i++){
el = f.elements[buttonNames[i]];
message += buttonNames[i] + ': ' + getValue(el) + '\n';
}
alert(message);
}

function getValue(r)
{
var i=r.length;
while (i--){
if (r[i].checked) return r[i].value;
}
return 'None selected';
}

</script>

<form name="formName" action="" onclick="showCh ecked(this);">
<p>
<input type="radio" name="myFirstVa riable"
value="option1" >Option1<br>
<input type="radio" name="myFirstVa riable"
value="option2" >Option2<br>
<input type="radio" name="myFirstVa riable"
value="option3" >Option3<br>
<input type="radio" name="myFirstVa riable"
value="option4" >Option4<br>
<input type="radio" name="myFirstVa riable"
value="option5" >Option5<br>
</p>
<p>
<input type="radio" name="mySecondV ariable"
value="option1" >Option1<br>
<input type="radio" name="mySecondV ariable"
value="option2" >Option2<br>
</p>
</form>
Incidentally, at least one radio button should always be selected.

[...]
--
Rob
Oct 9 '05 #3
Janwillem,

thanks for the heads up.

remeber reading that there's supposed to be a semicolon at the end of
each sentence.

i see how i was making some assumptions in my coding in trying to
retrieve the values selected from the form.

michael

Oct 10 '05 #4
Rob,

thanks for the example. now i'm just trying to get it working with the
real stuff.

a couple questions if i may, as i'm just wanting to get a better
understanding of the thought process -

1. what does the f in the showChecked (f) function represent? ( same
would be asked about the variable el within the same function and the r
in getValue (r) function)

2. how would you suggest working in an "if" so that the script wouldn't
run unless a radio button from each group were selected? ( i know the
script would be run for both selections, i mean to not show the alert
until both have been selected )

michael

Oct 10 '05 #5
On 10/10/2005 17:55, michael wrote:

[snip]
remeber reading that there's supposed to be a semicolon at the end of
each sentence.


It is good practice to include a semicolon at the end of most
statements, but control structures are generally an exception; they
should be followed by blocks.

myFunction(...) ;
myVariable = ...;
return myValue;

but

if(...) {...}
while(...) {...}

[snip]

Mike
Please quote /relevant/ material when replying to posts in this group
(as demonstrated above). If you have to use Google Groups, use the 'show
options' link and select 'Reply' from the revealed panel (not the later
link).

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Oct 10 '05 #6
michael said the following on 10/10/2005 12:55 PM:
Janwillem,
This is Usenet, not email. Quote what you are replying to please. It
makes the conversation easier to follow.
thanks for the heads up.

remeber reading that there's supposed to be a semicolon at the end of
each sentence.
"Supposed to be"? No.
Recommended? Yes, in some places.
But, I have yet to see a script that will properly execute with a ; at
the end but won't execute without it.
i see how i was making some assumptions in my coding in trying to
retrieve the values selected from the form.


Ain't scripting fun?

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Answer:It destroys the order of the conversation
Question: Why?
Answer: Top-Posting.
Question: Whats the most annoying thing on Usenet?
Oct 10 '05 #7
michael said the following on 10/10/2005 1:06 PM:
Rob,

thanks for the example. now i'm just trying to get it working with the
real stuff.


Please quote what you are replying to.

If you want to post a followup via groups.google.c om, don't use the
"Reply" link at the bottom of the article. Click on "show options" at
the top of the article, then click on the "Reply" at the bottom of the
article headers.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Oct 10 '05 #8

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

Similar topics

2
6156
by: Miles Davenport | last post by:
My Javascript is rather rusty :( ... and I need to do change some form values, in the folowing way: (1). I have the following a href (wrapped in PHP), which calls processForm. ==== <input type="hidden" name="myHiddenValue"> href="javascript:void(0)" onClick="processForm(\'' . $form_name
5
9081
by: Jeff | last post by:
Hi, I am trying to set the value of one drop down select box to the value of another drop down select box. I have the following in a function. document.formname.boxto.options.v alue = document.formname.boxfrom.options.value; but I need to change the above line to allow the 4 references to "boxto" and "boxfrom" to be dynamic so their values can be passed to the
3
4678
by: Don | last post by:
I can successfully force submission of a <form> using "document.formname.submit()". But, the submission doesn't appear to occur when used with Netscape. Anybody know why this is happening, and what I can do to get around this? Thanks, Don -----------== Posted via Newsfeed.Com - Uncensored Usenet News ==---------- http://www.newsfeed.com The #1 Newsgroup Service in the World!
6
3694
by: skubik | last post by:
Hi everyone. I'm attempting to write a Javascript that will create a form within a brand-new document in a specific frame of a frameset. The problem is that I can create the form and input element using createElement(), but when I go to append the form element into the new document, the script halts and I get the following error in my Javascript Console (Firefox 1.0): __tmp_newDoc.body has no properties.
2
2812
by: Scott | last post by:
I need to write a function that copies variables to fields. I've used an array and loop because it's neater than writing a similar sentence out 10 times. var myString = new String("id,callername,address,phone,phoneb,email,sqft,source,action,status"); var myFields = myString.split(','); //myValues is an array of values passed to the function var myValues =
4
2255
by: Bugs | last post by:
Hi, I wonder if anyone can help me out. I'm building a vb.net application that has a form with a panel that contains several other sub forms (as a collection of controls). What I'm wanting to do is call a generically named public sub in the top-most sub form in the panel. I have the name of the top-most form as a string (eg. g_TopForm = "frmCustomers") and I can reference the form with:
8
2036
by: Geoff Cox | last post by:
Hello, When using Internet Explorer, on networked PCs in a college, to view a page of mine with Javascript code in it the "stack overflow" error message appears. When I access the same file from my home PC no such message. Is it possible for this to be caused by any IE setting?
3
3487
by: droesler | last post by:
I have a function that receives a form name and field name. someFunc(formName, fieldName) { var fieldVal = document.forms.elements.value; } This triggers the 'has no properties error. An alert message shows the correct values are being passed in. If I hardcode var fieldVal = document.realFormName.realFieldName.value;
23
5923
by: Stanimir Stamenkov | last post by:
<form name="myForm" action="..."> <p><input type="text" name="myElem"></p> </form> As far as I was able to get the following is the standard way of accessing HTML form elements: document.forms.elements But I have also seen the following:
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
9092
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6815
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
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.