Click to See Complete Forum and Search --> : Alert message box


Squall Leonhart
11-17-2003, 06:53 PM
Hi, everyone
Please take a look at following code


<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="HM_Loader.js" TYPE='text/javascript'></SCRIPT>
<script language="JavaScript" type="text/javascript">

function whichChoice(YesNo)
{
if (confirm("Are you sure you want to delete this article?")){

window.location.href='updateRequest.asp?state=delete'


}
}

</script>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<form name="frmDelete" method="post" onSubmit="return dateDiff(this);">
<table ALIGN=CENTER border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<th colspan="6" height="25"><b>Choose the items you want to delete</b></th>
</tr>
<tr>
<td width=1%>&nbsp</td>
<td align=center><span class="gen"><b>Description</b></span></td>
<td width=2%>&nbsp</td>

</tr>
<tr>
<td width=1%></td>
<td align=center><select name="selectDel" style="width:300px;" size="6" multiple="multiple">
<% Do while not rsEdit.eof %>
<option value="<%=rsEdit.fields("ID")%>"><%=rsEdit.fields.item("description").value%></option>
<% rsEdit.Movenext
Loop
%>
</select></td>
<td width=2%>&nbsp</td>
</tr>
</form>
<tr><td><br></td></tr>
<tr>
<th colspan="13" height="25"><input type="submit" name="erase" value="DELETE" onclick="whichChoice()"></th>
</tr>
</table>
</BODY>
</HTML>

As you can see when I click the Delete button, I will get the message box asking me "Are you sure you want to delete this article?". But before that I want Javascript function to check whether or not any value from listbox 'selectDel' is selected. And if no value from listbox is selected, then I want to show the alert message box like "Items are not selected"

So I tried the code like

<script language="JavaScript" type="text/javascript">

function whichChoice(YesNo)
{
if (document.frmDelete.selectDel.value == ""){ Alert "Items are not selected"
else
}
if (confirm("Are you sure you want to delete this article?")){

window.location.href='updateRequest.asp?state=delete'


}
}

</script>

Code doesn't work. I don't know how I am going to solve this.
:(
Please help me.

Jona
11-17-2003, 06:59 PM
function whichChoice(YesNo){
if(document.frmDelete.selectDel.options[document.frmDelete.selectDel.options.selectedIndex].index==0){ alert("Items are not selected");
} else {
if(confirm("Are you sure you want to delete this article?")){
location.href='updateRequest.asp?state=delete';
} }
}


[J]ona

Squall Leonhart
11-18-2003, 11:55 AM
Thank you for reply. Jona.:)

But problem remains when I clicked delete button, it doesn't generate message box "items are not selected". It only generated errors. And when I chose the first record from listbox and clicked delete, message "Items are not selected" appears. And message "Are you sure delete this?" appears ok when I chose second item or third item from listbox.
Wonder what's wrong with it:(

Squall Leonhart
11-18-2003, 02:41 PM
Guys, please help me:(

Jona
11-18-2003, 03:34 PM
I don't quite understand that. :p What error did you get?

[J]ona

Squall Leonhart
11-18-2003, 04:08 PM
Thank you for reply.
Jona, please copy and paste this code to blank notepad and try to click delete button.

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="HM_Loader.js" TYPE='text/javascript'></SCRIPT>
<script language="JavaScript" type="text/javascript">

function whichChoice(YesNo){
if(document.frmDelete.selectDel.options[document.frmDelete.selectDel.options.selectedIndex].index==0){ alert("Items are not selected");
} else {
if(confirm("Are you sure you want to delete this article?")){
location.href='updateRequest.asp?state=delete';
} }
}
</script>
<title>IT Request Edit</title>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<form name="frmDelete" method="post" onSubmit="return dateDiff(this);">
<table ALIGN=CENTER border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<th colspan="6" height="25"><b>Choose the items you want to delete</b></th>
</tr>
<tr>
<td width=1%> </td>
<td align=center><span class="gen"><b>Description</b></span></td>
<td width=2%> </td>

</tr>
<tr>
<td width=1%></td>
<td align=center><select name="selectDel" style="width:300px;" size="6" multiple="multiple">
<option>1</option>
<option>2</option>
<option>3</option>
</select></td>
<td width=2%> </td>
</tr>
</form>
<tr><td><br></td></tr>
<tr>
<th colspan="13" height="25"><input type="submit" name="erase" value="DELETE" onclick="whichChoice()"></th>
</tr>
</table>
</BODY>
</HTML>

when I clicked delete button, it doesn't generate message box "items are not selected". It only generated errors. And when I chose the first record from listbox and clicked delete, message "Items are not selected" appears. And message "Are you sure delete this?" appears ok when I chose second item or third item from listbox.
Wonder what's wrong with it

Squall Leonhart
11-18-2003, 06:05 PM
Please help me:(

Scriptage
11-18-2003, 07:30 PM
wow how many people here post code before checking?

<HTML>
<HEAD>
<SCRIPT LANGUAGE="JavaScript1.2" SRC="HM_Loader.js" TYPE='text/javascript'></SCRIPT>
<script language="JavaScript" type="text/javascript">

function whichChoice(){
if(document.frmDelete.selectDel.options.selectedIndex<0){ alert("Items are not selected");
} else {
if(confirm("Are you sure you want to delete this article?")){
location.href='updateRequest.asp?state=delete';
} }
}
</script>
<title>IT Request Edit</title>
</HEAD>
<BODY LEFTMARGIN=0 MARGINWIDTH="0" MARGINHEIGHT="0">
<form name="frmDelete" method="post" onSubmit="return dateDiff(this);">
<table ALIGN=CENTER border="0" cellpadding="3" cellspacing="1" width="100%">
<tr>
<th colspan="6" height="25"><b>Choose the items you want to delete</b></th>
</tr>
<tr>
<td width=1%> </td>
<td align=center><span class="gen"><b>Description</b></span></td>
<td width=2%> </td>

</tr>
<tr>
<td width=1%></td>
<td align=center><select name="selectDel" style="width:300px;" size="6" multiple="multiple">
<option>1</option>
<option>2</option>
<option>3</option>
</select></td>
<td width=2%> </td>
</tr>
</form>
<tr><td><br></td></tr>
<tr>
<th colspan="13" height="25"><input type="submit" name="erase" value="DELETE" onclick="whichChoice()"></th>
</tr>
</table>
</BODY>
</HTML>

Jona
11-18-2003, 08:40 PM
My bad, Scriptage. Didn't check it, didn't think about it... Kind of in a rush but saw the question... Have had too much homework lately... Can't blame a 14-year-old for such a mistake can you? :rolleyes: lol. Just kiddin'... :D

[J]ona

Squall Leonhart
11-19-2003, 11:04 AM
Thanks it works now.:)