cakeday
10-03-2003, 03:38 PM
I am not copying and pasting the whole code..
But what i am trying to do is simple,
When, someone clicks on a listbox and when they select NULL the value is "A", then the alert box should display and should not let them go to the next page on the web.
What am i doing wrong??
submit_param is the submit button.
When the click on the submit button and when lstlob.value="A" then the alert should display.
function lob_validate()
{
if (this.document.f3.submit_param.onclick)
{
if (document.f5.lstlob.value == "A") {
alert("Please select a Line of Business.")
return false;
}
}
<BODY>
<SELECT id=lstlob name=lstlob>
<OPTION value="A" default></OPTION>
<OPTION Value="0">All</OPTION>
</body>
Thank you!
simpson97
10-03-2003, 04:31 PM
Try something like this
<html>
<head>
<script>
function lob_validate(form) {
if (form.lstlob.value == "A") {
alert("Please select a Line of Business.")
return false;
}
}
</script>
<BODY>
<form action="yourscript.cgi" method="post">
<SELECT id=lstlob name=lstlob>
<OPTION value="A" default>select option</OPTION>
<OPTION Value="0">All</OPTION>
<input type="submit" value="Submit" onclick="return lob_validate(this.form)">
</form>
</body>
</html>
Bob
cakeday
10-07-2003, 01:43 PM
Still now working.
It displays the Alert message but then, it still passes the form variable parameter to the next webpage and displays the next page instead of staying on the same page.
I am displaying my entire code now, since i have more than 1 functions and more than 1 forms..
<HTML>
<HEAD>
<SCRIPT>
function set_startdate()
{
if (this.document.f3.submit_param.onclick)
{
this.document.f3.i_startdate.value =
this.document.f1.day.options[this.document.f1.day.selectedIndex].text + "-" +
this.document.f1.month.options[this.document.f1.month.selectedIndex].text + "-" +
this.document.f1.year.options[this.document.f1.year.selectedIndex].text ;
}
if (this.document.f4.submit_all.onclick)
{
this.document.f4.i_startdate.value =
this.document.f1.day.options[this.document.f1.day.selectedIndex].text + "-" +
this.document.f1.month.options[this.document.f1.month.selectedIndex].text + "-" +
this.document.f1.year.options[this.document.f1.year.selectedIndex].text ;
}
}
function set_enddate()
{
if (this.document.f3.submit_param.onclick)
{
this.document.f3.i_enddate.value =
this.document.f1.day.options[this.document.f2.day.selectedIndex].text + "-" +
this.document.f1.month.options[this.document.f2.month.selectedIndex].text + "-" +
this.document.f1.year.options[this.document.f2.year.selectedIndex].text ;
}
if (this.document.f4.submit_all.onclick)
{
this.document.f4.i_enddate.value =
this.document.f1.day.options[this.document.f2.day.selectedIndex].text + "-" +
this.document.f1.month.options[this.document.f2.month.selectedIndex].text + "-" +
this.document.f1.year.options[this.document.f2.year.selectedIndex].text ;
}
}
function set_lob()
{
if (this.document.f3.submit_param.onclick)
{
this.document.f3.i_lob.value = this.document.f5.lstlob.value;
}
if (this.document.f4.submit_all.onclick)
{
this.document.f4.i_lob.value = this.document.f5.lstlob.value;
}
}
function lob_validate() {
if (f5.lstlob.value == "A") {
alert("Please select a Line of Business.")
return false;
}
}
function set_flag()
{
if (this.document.f3.submit_param.onclick)
{
this.document.f3.i_flag.value = "N"
}
if (this.document.f4.submit_all.onclick)
{
this.document.f4.i_flag.value = "Y"
}
}
function get_values()
{
set_startdate();
set_enddate();
set_lob();
set_flag();
return lob_validate();
}
function populate(objForm,selectIndex)
{
timeA = new Date(objForm.year.options[objForm.year.selectedIndex].text,
objForm.month.options[objForm.month.selectedIndex+1].value,1);
timeDifference = timeA - 86400000;
timeB = new Date(timeDifference);
var daysInMonth = timeB.getDate();
for (var i = 0; i < objForm.day.length; i++)
{
objForm.day.options[0] = null;
}
for (var i = 0; i < daysInMonth; i++)
{
objForm.day.options[i] = new Option(i+1);
}
objForm.day.options[0].selected = true;
}
function populate_myform(objForm)
{
var timeC = new Date();
var thisYear = timeC.getYear();
var yearArray = new Array(thisYear-23,
thisYear-22,thisYear-21,thisYear-20,thisYear-19,
thisYear-18,thisYear-17,thisYear-16,thisYear-15,
thisYear-14,thisYear-13,thisYear-12,thisYear-11,
thisYear-10,thisYear-9,thisYear-8,thisYear-7,
thisYear-6,thisYear-5,thisYear-4,thisYear-3,
thisYear-2,thisYear-1,thisYear,thisYear+1,thisYear+2);
var dayArray = new Array("1","2","3","4","5","6","7","8","9",
"10","11","12","13","14","15","16","17","18","19","20","21",
"22","23","24","25","26","27","28","29","30","31");
//Do year stuff here
for (var i = 0; i < objForm.year.length; i++)
{
objForm.year.options[0] = null;
}
for (var i = 0; i < yearArray.length; i++)
{
objForm.year.options[i] = new Option(yearArray[i]);
}
objForm.year.options[3].selected = true;
//Do day stuff here
for (var i = 0; i < objForm.day.length; i++)
{
objForm.day.options[i] = null;
}
for (var i = 0; i < dayArray.length; i++)
{
objForm.day.options[i] = new Option(dayArray[i]);
}
objForm.day.options[0].selected = true;
}
function run_forms()
{
populate_myform(this.document.f1);
populate_myform(this.document.f2);
populate_myform(this.document.f3);
populate_myform(this.document.f4);
populate_myform(this.document.f5);
}
// End
-->
</script>
</HEAD>
<BODY onLoad="run_forms();">
<TABLE border="0">
<FORM name="f1">
<TR>
<TD class="heading"> From Date</TD>
<TD> </TD>
<TD class="heading">Through Date(Inclusive) </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
<TD> </TD>
</TR>
<TR>
<TD>
<SELECT NAME="month" onChange="populate(this.form,this.form.month.selectedIndex);">
<option VALUE="00">Jan</option>
<option VALUE="01">Feb</option>
<option VALUE="02">Mar</option>
<option VALUE="03">Apr</option>
<option VALUE="04">May</option>
<option VALUE="05">Jun</option>
<option VALUE="06">Jul</option>
<option VALUE="07">Aug</option>
<option VALUE="08">Sep</option>
<option VALUE="09">Oct</option>
<option VALUE="10">Nov</option>
<option VALUE="11">Dec</option>
</SELECT>
<SELECT NAME="day"></SELECT>
<SELECT NAME="year" onChange="populate(this.form,this.form.year.selectedIndex);">
</SELECT>
</TD> </FORM>
<FORM name="f2">
<TD ALIGN="left">
<SELECT NAME="month" onChange="populate(this.form,this.form.month.selectedIndex);">
<option VALUE="00">Jan</option>
<option VALUE="01">Feb</option>
<option VALUE="02">Mar</option>
<option VALUE="03">Apr</option>
<option VALUE="04">May</option>
<option VALUE="05">Jun</option>
<option VALUE="06">Jul</option>
<option VALUE="07">Aug</option>
<option VALUE="08">Sep</option>
<option VALUE="09">Oct</option>
<option VALUE="10">Nov</option>
<option VALUE="11">Dec</option>
</SELECT> <SELECT NAME="day"> </SELECT>
<SELECT NAME="year" onChange="populate(this.form,this.form.year.selectedIndex);"> </SELECT>
</TD>
</FORM>
<FORM name="f3" method="GET" action = <%= v_psppagename %> >
<TD></TD>
<TD>
<INPUT type="submit" value="Submit" id="submit_param" onClick = "get_values();">
<INPUT type="hidden" name="i_startdate">
<INPUT type="hidden" name="i_enddate">
<INPUT type="hidden" name="i_lob">
<INPUT type="hidden" name="i_flag">
<INPUT type="hidden" name="i_pagenum" value=<%= i_pagenum %>>
</TD>
<TD></TD>
<TD><FONT size="4"> <B> OR </FONT></B></TD>
<TD></TD>
</FORM>
<FORM name="f4" method="GET" action = <%= v_psppagename %> >
<TD>
<INPUT type="submit" value="Submit" id="submit_all" onClick = "get_values();">
<INPUT type="hidden" name="i_startdate">
<INPUT type="hidden" name="i_enddate">
<INPUT type="hidden" name="i_lob">
<INPUT type="hidden" name="i_flag">
<INPUT type="hidden" name="i_pagenum" value=<%= i_pagenum %>>
</TD>
</FORM>
</TR>
<FORM name="f5">
<TR></TR>
<TR></TR>
<TR></TR>
<TR>
<TD class="heading">Line of Business</TD>
</TR>
<TR colspan="7">
<TD colspan="7">
<SELECT id=lstlob name=lstlob>
<OPTION value="A" default>Select LOB</OPTION>
<OPTION Value="0">All</OPTION>
</FORM>
</TD>
</TR>
</TABLE>
</BODY>
</CENTER>
Please debug this code, it is getting on my nerves. Thank you!
</HTML>
sam2003
10-07-2003, 02:14 PM
forget everything use button instead of submit.
function lob_validate() {
if (document.f5.lstlob.value == "A")
{
alert("Please select a Line of Business.");
}
else
{
document.f5.submit();
}
}
cakeday
10-07-2003, 02:32 PM
still not working.. still goes to the next page and does the same thing that it was doing earlier..
Please help me. It has to be something minor...=(
sam2003
10-07-2003, 02:48 PM
sorry I gave u wrog answer I mixed up with some one else
just give me some time I know your problem I am busy with customer right now I'll write u back
javascript_ss
10-07-2003, 03:06 PM
Hello,
I was having a similar problem ,, see my post "onsubmit return not working"
I had a onsubmit in the form tag .. It worked in IE 6.0 , but with Netscape 7.0 , after the alert message, it went to the next page , taking the incorrect user input.
Well I tried sam2003's method posted above by using onclick for the submit button (Actually I changed the submit button type BUTTON instead of type submit.
Thanks SAM2003;)
sam2003
10-07-2003, 03:13 PM
use your form like this
<FORM name="f5" onsubmit="return get_values();">
<TR></TR>
<TR></TR>
<TR></TR>
<TR>
<TD class="heading">Line of Business</TD>
</TR>
<TR colspan="7">
<TD colspan="7">
<SELECT id=lstlob name=lstlob>
<OPTION value="A" default>Select LOB</OPTION>
<OPTION Value="0">All</OPTION>
<INPUT type="submit" value="Submit" id="submit_all" >
</FORM>
cakeday
10-16-2003, 03:18 PM
It is still not working..
I cannot have the SUBMIT button in the same form as the form that has the LIST BOX.
And also, i have 2 SUBMIT BUTTONS on the same webpage.
please help. i am supposed to get this done by the end of the day today.
THank you.
cakeday
10-16-2003, 03:54 PM
function lob_validate()
{
if (document.f5.lstlob.value == "A")
{
alert("Please select a Line of Business.");
document.f5.lstlob.focus();
return false;
}
}
This is how my lob_validate() function looks like..
And this is how i get the values for all the functions that are on the webpage, when clicked on the submit button
function get_values()
{
set_startdate();
set_enddate();
set_lob();
set_flag();
lob_validate();
}
For some reason my return false; doesn't look like it is working.. LIke i said, my SUBMIT BUTTON(s) and the list box have a seperate form of their own for other reasons... I am so confused..
When the lstlob.value=="A", the alert pops up, then it focuses on the list box like it is supposed to but then it still takes the user to the next webpage.. WHY DOES IT DO THIS??
cakeday
10-16-2003, 04:30 PM
It has been fixed.. thank you..