Hello.
The following code has been shortened just to the main area. It's a form
validation problem. When I hit 'submit', the form is supposed to check if a
selection out of the drop down menu has been selected. If not then it's
suppose to generate an error message.
The question is with the variables and arguments passed to the function. I
already checked with Firebug, and this variable:
var sel_opt = the_sel.options[the_sel.selecte dIndex];
is working...'sel_ opt' has a value of 'option'..so I'm guessing that it's
defined..becaus e if it wasn't then it would say 'undefined'.
If it is defined then why isn't my code checking if something was selected?
....
function attachHandlers( ){
var the_button = document.getEle mentById("my_bu tton");
the_button.oncl ick=function(){ return checkFormFields ();};
var radio_buttons = document.getEle mentsByName("be auty");
for (var i=0; i < radio_buttons.l ength; i++)
{
if (i 0)
{
radio_buttons[i].onclick=remove RadioOpts;
}
else
{
radio_buttons[i].onclick=addRad ioOpts;
}
}
var chkbox_sel = document.getEle mentById("check choice");
chkbox_sel.oncl ick=addCheckOpt s;
}
....
function checkFormFields ()
{
.....
var sel_opt = the_sel.options[the_sel.selecte dIndex];
....
}
....
correct=checkSe lOpts(sel_opt, error);
if (!correct)
{
error_mes += errors[error.val] + '<br>';
sel_opt.focus() ;
}
....
....
function checkSelOpts(ci ty_opts, error){
if (city_opts!= -1 && city_opts.value !="none")
{
return true;
}
error.val=4;
return false;
}
....
Hopefully you can follow this..
--
Message posted via WebmasterKB.com
The following code has been shortened just to the main area. It's a form
validation problem. When I hit 'submit', the form is supposed to check if a
selection out of the drop down menu has been selected. If not then it's
suppose to generate an error message.
The question is with the variables and arguments passed to the function. I
already checked with Firebug, and this variable:
var sel_opt = the_sel.options[the_sel.selecte dIndex];
is working...'sel_ opt' has a value of 'option'..so I'm guessing that it's
defined..becaus e if it wasn't then it would say 'undefined'.
If it is defined then why isn't my code checking if something was selected?
....
function attachHandlers( ){
var the_button = document.getEle mentById("my_bu tton");
the_button.oncl ick=function(){ return checkFormFields ();};
var radio_buttons = document.getEle mentsByName("be auty");
for (var i=0; i < radio_buttons.l ength; i++)
{
if (i 0)
{
radio_buttons[i].onclick=remove RadioOpts;
}
else
{
radio_buttons[i].onclick=addRad ioOpts;
}
}
var chkbox_sel = document.getEle mentById("check choice");
chkbox_sel.oncl ick=addCheckOpt s;
}
....
function checkFormFields ()
{
.....
var sel_opt = the_sel.options[the_sel.selecte dIndex];
....
}
....
correct=checkSe lOpts(sel_opt, error);
if (!correct)
{
error_mes += errors[error.val] + '<br>';
sel_opt.focus() ;
}
....
....
function checkSelOpts(ci ty_opts, error){
if (city_opts!= -1 && city_opts.value !="none")
{
return true;
}
error.val=4;
return false;
}
....
Hopefully you can follow this..
--
Message posted via WebmasterKB.com
Comment