Hi all, newbie here.
Could someone help me with this two function javascript?
In the first function, I want to check the value of a form field called "proj_sel_wrtype". It is a radio button field that
will be equal to either "Posting" or "Project".
If the value is "Posting" then; check to see if another field, "proj_sel_posting_type" contains a value; if it does not, then
throw up a javascript alert. The value is selected from a drop down menu.
In the second function, if "proj_sel_wrtype" is equal to "Project" then; check to see if a third field, "proj_sel_activity"
contains a value; if it does not, then throw up a javascript alert. The value is selected from a drop down menu.
I call the js functions from the form submit button using the onClick event. The problem is that if either
"proj_sel_posting_type" or "proj_sel_activity" is left blank the form gets processed anyway. Here is the code: - - - - -
<script language="javascript">
function evaluate_1(wr1)
{
if (icsworkrequest.proj_sel_wrtype.value == "Posting")
{
if (icsworkrequest.proj_sel_posting_type == "")
{
alert("For POSTINGS, select POSTING TYPE. \n Click OK to contine.");
icsworkrequest.proj_sel_posting_type.focus();
return false;
}
}
return true;
}
function evaluate_2(wr2)
{
if (icsworkrequest.proj_sel_wrtype.value == "Project")
{
if (icsworkrequest.proj_sel_activity == "")
{
alert("For PROJECTS, select PROJECT TYPE. \n Click OK to contine.")
icsworkrequest.proj_sel_activity.focus();
return false;
}
}
return true;
}
</script>
---------------------------------
In the submit button I have,
"onClick = "return evaluate_1(icsworkrequest); return evaluate_2(icsworkrequest)"
'icsworkrequest' is the name given to the form, and I realize I'm no good at javascript.
Thanks for any help,
Chris
~`^%
Horus Kol
11-25-2004, 01:35 PM
where does the value for those variables come from? A select box? what is the default setting/value?
shadowspell
11-25-2004, 02:11 PM
Hi Horus Kol,
The variable "proj_sel_wrtype" is used for two radio buttons. One button's value is "Posting", the other button's value is "Project". The default selection is "Project". It will not be possible to leave one unselected.
The variable "proj_sel_posting_type" has a value that is selected from a drop-down or list menu. This menu list will show 'only' if "Posting" was selected previously. It has no default value since a user may just bypass this and allow the default which may be wrong.
The variable "proj_sel_activity" has a value that is selected from a drop-down or list menu. This menu list will show 'only' if "Project" was selected previously. It has no default value since a user may just bypass this and allow the default which may be wrong.
I don't want to get into theory, just want to check for nulls in the latter two variables and deliver a javascript alert box if it is left blank.
Horus Kol
11-25-2004, 02:37 PM
just trying to get a better handle of what's where....
how are the functions called? from a submit button?
that will be why the form is always submitted.
if you change it to a button button, so no default page action is taken, and then in your evaluate functions you can use a javascript submit command:
function evaluate_1(wr1)
{
if (icsworkrequest.proj_sel_wrtype.value == "Posting")
{
if (icsworkrequest.proj_sel_posting_type == "")
{
alert("For POSTINGS, select POSTING TYPE. \n Click OK to contine.");
icsworkrequest.proj_sel_posting_type.focus();
}
else
{
document.getElementById("form_name").submit();
}
}
}