473,396 Members | 1,726 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.

undefined field error message

Hi,
I have a script that is supposed to check if one of the radio buttons
in a form is checked and either display an "alert" or go to another
page.

<html>
<head>
<title></title>
</head>
<body>
<script type="text/Javascript">
function getRadioButtonChecked (radio){
for (var i = 0; i < radio.length; i++){
if (radio[i].checked){
return true;
}
}
return false;
}
</script>

<form name="myform" method="post" action="somefile.php">
<input id="req_any" name="req_any" type="radio" value="AVM-MC1"
onClick="if (this.checked)
document.getElementById('qty_AVM-MC1').value='1'; else
document.getElementById('qty_AVM-MC1').value='0'">Product1<br />
<input type="hidden" id="qty_AVM-MC1" name="qty_AVM-MC1" value="0">
<input id="req_any" name="req_any" type="radio" value="AVM-HTC1"
onClick="if (this.checked)
document.getElementById('qty_AVM-HTC1').value='1'; else
document.getElementById('qty_AVM-HTC1').value='0'">Product2<br />
<input type="hidden" id="qty_AVM-HTC1" name="qty_AVM-HTC1" value="0">
<br />
<span style="margin-left:40%;">
<input name="OK" type="submit" value="Add" onClick="if
(getRadioButtonChecked(document.getElementById('re q_any'))){document.location.href='anotherfile.php' ;
return true;} else{ alert('You must select one of the required
options.'); return false;}">
</span>
<span style="margin-left:50;">
<input name="Cancel" type="button" value="Cancel"
onClick="document.location.href='cancel.php'">
</span>
</form>
</body>

When I click on the "Add" button, I get a javascript error saying
"radio is not defined". What am I doing wrong?

Feb 27 '06 #1
3 1901
Hi Lee,
thanks a lot for the info.
The page is generated dynamically through a php file. I made the
changes you suggested and thsi the resuting page, which seems to
satisfy your suggestions. Thejavascript console still shows the same
error message: "error: radio is not defined".

<html>
<head>
<title></title>
<script type="text/Javascript">
function getRadioButtonChecked (radio){
for (var i = 0; i < radio.length; i++){
if (radio[i].checked){
alert(radio+i+' is checked');
return true;
}
}
alert("You must select one of the required options.");
return false;
}
</script>
</head>

<body topmargin="70">
<form name="error_form" method="post" action="add_additional.php"
onsubmit="return getRadioButtonChecked('req_any')">
<div class="msgDiv">
<div width="300" class="contentMsgHeader">
Error message is printed here...<br />
</div>
<span class="contentMsg">
<input class="errorFormInput"
name="req_any"
type="radio"
value="AVM-MC1"
onClick="this.form.qty_AVM-MC1.value=if
(this.checked)?1:0">Prodcut1</span><br />
<input type="hidden"
id="qty_AVM-MC1"
name="qty_AVM-MC1" value="0">
<span class="contentMsg">
<input class="errorFormInput"
name="req_any"
type="radio"
value="AVM-HTC1"
onClick="this.form.qty_AVM-HTC1.value=if
(this.checked)?1:0">Prodcut2</span><br />
<input type="hidden"
id="qty_AVM-HTC1"
name="qty_AVM-HTC1"
value="0">
</div>
</div>
<br /><span style="margin-left:40%;">
<input name="OK"
type="submit"
value="Add Additional">
</span>
<span style="margin-left:50;">

<input name="Cancel"
type="button"
value="Cancel"
onClick="document.location.href='cancel_addition.p hp'">
</span>
</form>
</body>

Thanks for your help.

Feb 28 '06 #2

Xerxes wrote:
Hi Lee,
thanks a lot for the info.
The page is generated dynamically through a php file. I made the
changes you suggested and thsi the resuting page, which seems to
satisfy your suggestions. Thejavascript console still shows the same
error message: "error: radio is not defined".
The error message is correct.
function getRadioButtonChecked (radio){
for (var i = 0; i < radio.length; i++){
if (radio[i].checked){
alert(radio+i+' is checked');
return true;
}
}
alert("You must select one of the required options.");
return false;
}


You have an input element with the value of "req_any" for the name
attribute. When the form gets submitted, you pass a _string_ to your
function getRadioButtonChecked. However, in your function, you're
trying to use "radio" as an object, when in reality you passed to it a
string. Try modifying your code like so:

javascript:

function getRadioButtonChecked(myForm)
{
for(var i = 0; i < myForm.elements["req_any"].length; i++)
{
if(myForm.elements["req_any"][i].checked)
{
alert("radio " + i + " is checked");

return true;
}
}

alert("You must select one of the required options.");

return false;
}

html:

<form [...add form attributes...] onsubmit = "return
getRadioButtonChecked(this)">
[...add your form controls...]
</form>

Feb 28 '06 #3
Thanks alot for your help. Your suggestion worked.

Feb 28 '06 #4

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

Similar topics

1
by: Stu | last post by:
I am trying to build the xerces shared library with 2.3.0 version of their source code on an AIX 5.1 32 bit machine with the following version of the g++ compiler /usr/local/bin/g++ -v Reading...
4
by: Mike | last post by:
I am having a problem when a field is spaces being undefined. I wasn't sure if the problem was Excel or Javascript, so I thought I would post here first. The users are able to select from a drop...
0
by: Dave | last post by:
Hi everyone, (I already posted this to the VS.NET IDE news group without any responses, so I'm attempting one more time in this group) The issue I'm having is occuring in the IDE of VS.NET...
10
by: Sharon | last post by:
Hi! Does anyone know why the onclick in the following popup menu gives the error:"Val is undefined"? Does it have something to do with the fact that it is called within the variable tablePop?...
2
by: Denis Perelyubskiy | last post by:
Hello, I have a form with an input field, a textarea, having a value of "" Also, I have some javascript code, which may be reduced to the following: function validate(mycode) {...
8
by: tshad | last post by:
I have a function that formats currency to add commas and $. But I also check to see if the field is empty and if it is I return. The problem is that the field now contains the word...
6
by: blackdogharry | last post by:
Hi, I am a novice VBA user. My access version is 2007 on Windows XP PC. I need to create a query that will take pre-existing text values of the B_status field (such as "Received_Emailed",...
3
by: blackrunner | last post by:
ERROR in my Query?! ERROR: Element GESCHLECHT is undefined in FORM. i think everything ok. Maby somebody can help me here Element GESCHLECHT is undefined in FORM. The error occurred...
4
by: cyberlei | last post by:
hi all, I`m getting this error Notice: Undefined index: user in c:\inetpub\wwwroot\login.php on line 96 Notice: Undefined variable: message in c:\inetpub\wwwroot\login.php on line 101 Could...
4
by: mattehz | last post by:
Hey there, I am trying to upload old source files and came across these errors: Warning: Invalid argument supplied for foreach() in /home/mattehz/public_html/acssr/trunk/inc_html.php on line 59...
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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
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,...
0
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,...
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.