PDA

View Full Version : frames and forms


Kevin
02-13-2003, 08:46 PM
Doing some basic work with forms and there values.
I think I have a good start here but keep running into the same errors. object dosent exist.

Can you take a look and advise?

I don't mean the entire form at once, of course time permitting:)
that would be great. But if you could take a look at say the radio group and the check boxes that would be great.

insight always appreciated

Thank You
Kevin
http://home.ix.netcom.com/~krr/frameA.html
The code
*******

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function checkFormFields ()
{
function getRadio ()
{
var RadioValue = 0;
var n = RadioBtn.length;
if (n)
{
for (var i=0; i<n; i++)
{
if (RadioBtn[i].checked)
{
RadioValue = RadioBtn[i].value;
break;
} /* if */
} /* for */
} /* if */
} /* end getRadio */

function ChkBoxState ()
{
if(chkbx1.checked)
chk1 = chkbx1.value;
if(chkbx2.checked)
chk2 = chkbx2.value;
if (chkbx3.checked)
chk3 = chkbx3.value;
} /* end ChkBoxState() */

function GetSelected ()
{
var SelectList = document.form.SelectList;
var counter;
var curIndex;
for (counter = 0; counter < SelectList.options.length; counter++)
{
if (SelectList.options[counter].selected)
mySelected = document.form.SelectList.options[counter].index;
} /* for */
} /* GetSelected() */

var myTextField = document.form.textfield.value;
var myTextArea = document.form.TextArea.value;

var MyString= RadioValue + " is selected.<br><br>"
MyString += chk1 + " is selected.<br>"
MyString += chk2 + " is selected.<br>"
MyString += chk3 + " is selected.<br><br>"
MyString += mySelected + " is selected<br><br>"
MyString += myTextField + " is in the input text box.<br><br>"
MyString += myTextArea + " is in the text area box.<br><br>"


parent.fraB.document.write (MyString);
parent.fraB.document.close();


} /* end CheckFormFields() */


//-->
</script>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<h1 align="center">Frames and Forms </h1>
<form>
<p>
<input type="radio" name="RadioBtn" value="Radio 1">Radio1<br>
<input type="radio" name="RadioBtn" value="Radio 2">Radio2<br>
<input type="radio" name="RadioBtn" value="Radio 3">Radio3
</p>
<p>
<input type="checkbox" name="chkbx1">Check1<br>
<input type="checkbox" name="chkbx2">Check2<br>
<input type="checkbox" name="chkbx3">Check3
</p>
<p>Select One
<select name="SelectList">
<option value="Select1" selected> Select1 </option>
<option value="Select2"> Select2 </option>
<option value="Select3"> Select3 </option>
<option value="Select4"> Select4 </option>
<option value="Select5"> Select5 </option>
</select>
</p>
<p>A few words
<input type="text" name="textfield" value="default text">
</p>


<p>
<textarea name="TextArea" cols="50" rows="6">word
word a
word b
word c
word d
</textarea>
</p>


<p>
<input type="button" value="Show Selections" onClick="checkFormFields(this.form)"; name="show">
</p>
<p>
<input type="reset" name="Reset" value="Reset form">
<br>
</p>
</form>
<h1 align="left">&nbsp;</h1>
</body>
</html>

arnyinc
02-14-2003, 01:22 PM
I made quite a few changes and got it working up until a frames error. I'm fairly certain you can't nest functions. If you want to split things up between functions, you set it up like the following and then call the validate() function. This will then make a call to all the functions inside it.

function validate(){
validate_checkboxes();
validate_textarea();
validate_textfield();
}

function validate_checkboxes(){
//stuff
}

function validate_textarea(){
//stuff
}

function validate_textfield(){
//stuff
}

I just combined all your stuff into one function though.


<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function checkFormFields(myform)
{
var chk1, chk2, chk3;
var RadioValue = 0;
var n = myform.RadioBtn.length;
if (n)
{
for (var i=0; i<n; i++)
{
if (myform.RadioBtn[i].checked)
{
RadioValue = myform.RadioBtn[i].value;
break;
} /* if */
} /* for */
} /* if */

if(myform.chkbx1.checked)
chk1 = myform.chkbx1.value;
if(myform.chkbx2.checked)
chk2 = myform.chkbx2.value;
if (myform.chkbx3.checked)
chk3 = myform.chkbx3.value;

var SelectList = myform.SelectList;
var counter;
var curIndex;
for (counter = 0; counter < SelectList.options.length; counter++)
{
if (SelectList.options[counter].selected)
mySelected = myform.SelectList.options[counter].index;
} /* for */

var myTextField = myform.textfield.value;
var myTextArea = myform.TextArea.value;

var MyString = "";
MyString += RadioValue + " is selected.<br><br>"
if (chk1!="")
MyString += chk1 + " is selected.<br>"
if (chk2!="")
MyString += chk2 + " is selected.<br>"
if (chk3!="")
MyString += chk3 + " is selected.<br><br>"
MyString += mySelected + " is selected<br><br>"
MyString += myTextField + " is in the input text box.<br><br>"
MyString += myTextArea + " is in the text area box.<br><br>"


parent.fraB.document.write (MyString);
parent.fraB.document.close();
} /* end CheckFormFields() */

//-->
</script>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<h1 align="center">Frames and Forms </h1>
<form>
<p>
<input type="radio" name="RadioBtn" value="Radio 1">Radio1<br>
<input type="radio" name="RadioBtn" value="Radio 2">Radio2<br>
<input type="radio" name="RadioBtn" value="Radio 3">Radio3
</p>
<p>
<input type="checkbox" name="chkbx1">Check1<br>
<input type="checkbox" name="chkbx2">Check2<br>
<input type="checkbox" name="chkbx3">Check3
</p>
<p>Select One
<select name="SelectList">
<option value="Select1" selected> Select1 </option>
<option value="Select2"> Select2 </option>
<option value="Select3"> Select3 </option>
<option value="Select4"> Select4 </option>
<option value="Select5"> Select5 </option>
</select>
</p>
<p>A few words
<input type="text" name="textfield" value="default text">
</p>


<p>
<textarea name="TextArea" cols="50" rows="6">word
word a
word b
word c
word d
</textarea>
</p>


<p>
<input type="button" value="Show Selections" onClick="checkFormFields(this.form)"; name="show">
</p>
<p>
<input type="reset" name="Reset" value="Reset form">
<br>
</p>
</form>
<h1 align="left"> </h1>
</body>
</html>

Kevin
02-14-2003, 05:10 PM
I was able to resolve everything but how to pass the value of the select list and the chk boxes.

Can you take a look and advise?
http://home.ix.netcom.com/~krr/framesNforms.html

insight always appreciated
Thank You
Kevin Raleigh :thumbsup:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function checkFormFields (MyForm)
{
var RadioValue = 0;
var n = MyForm.RadioBtn.length;
if (n)
{
for (var i=0; i<n; i++)
{
if (MyForm.RadioBtn[i].checked)
{
RadioValue = MyForm.RadioBtn[i].value;
break;
} /* if */
} /* for */
} /* if */

if(MyForm.chkbx1.checked)
var chk1 = MyForm.chkbx1.value;
if(MyForm.chkbx2.checked)
var chk2 = "CheckBox 2";
if (MyForm.chkbx3.checked)
var chk3 = "CheckBox 3";

var counter;
var curIndex;
for (counter = 0; counter < MyForm.SelectList.options.length; counter++)
{
if (MyForm.SelectList.options[counter].selected)
mySelected = MyForm.SelectList.options[counter].index;
} /* for */

var myTextField = MyForm.textfield.value;
var myTextArea = MyForm.TextArea.value;

var MyString = "";
MyString += "<br><h1 align='center'>Selections<\/h1>";
MyString += "<b>Radio Group<\/b><br>";
MyString += " " + RadioValue + " is selected.<br><br>";
MyString += "<b>Check Box(s)<\/b><br>";
if (chk1)
MyString += " " + chk1 + " is selected.<br>";
if (chk2)
MyString += " " + chk2 + " is selected.<br>";
if (chk3)
MyString += " " + chk3 + " is selected.<br>";

MyString += "<br><b>Select List<\/b><br>";
MyString += " " + mySelected + " is selected<br>";

MyString += "<br><b>Text Field<\/b><br>";
MyString += myTextField + " is in the input text box.<br><br>";
MyString += "<b>Text Area<\/b><br>";
MyString += myTextArea + " is in the text area box.<br><br>";

parent.fraB.document.write (MyString);
parent.fraB.document.close();

} /* end CheckFormFields() */

//-->
</script>

</head>

<body bgcolor="#FFFFFF" text="#000000">
<br>
<h1 align="center">Frames and Forms </h1>
<form>
<p>
<input type="radio" name="RadioBtn" value="Radio Button 1">Radio1<br>
<input type="radio" name="RadioBtn" value="Radio Button 2">Radio2<br>
<input type="radio" name="RadioBtn" value="Radio Button 3">Radio3
</p>
<p>
<input type="checkbox" name="chkbx1">Check 1<br>
<input type="checkbox" name="chkbx2">Check 2<br>
<input type="checkbox" name="chkbx3">Check 3
</p>
<p>Select One
<select name="SelectList">
<option value="Select1" selected> Select 1 </option>
<option value="Select2"> Select 2 </option>
<option value="Select3"> Select 3 </option>
<option value="Select4"> Select 4 </option>
<option value="Select5"> Select 5 </option>
</select>
</p>
<p>A few words
<input type="text" name="textfield" value="default text">
</p>


<p>
<textarea name="TextArea" cols="40" rows="6">word
word a
word b
word c
word d
</textarea>
</p>

<p>
<input type="button" value="Show Selections" onClick="checkFormFields(this.form)"; name="show">
</p>

<p>
<input type="reset" name="Reset" value="Reset form">
<br>
</p>
</form>
<h1 align="left">&nbsp;</h1>
</body>
</html>