Click to See Complete Forum and Search --> : Confirmation of Yes/No from a pop-up box using javascript


andreshcs
03-11-2006, 08:29 AM
I'm trying to make a pop-up message box where there is a confirmation of yes/no... when user click on a button, this confirmation message box will pop up and showing the value of selection that the user made ( let's say the value is get from the dropdownlist1 )... so the user will either press ok to confirm it or cancel to return to that page... where ok will bring the user to next page... i'm using this code and i'm not sure where i went wrong or i missed out something... thanks...

mainpage.aspx:
<SCRIPT language="javascript">
function getMessage()
{
var ans;
ans=window.confirm('Are you sure?');
//alert (ans);
if (ans==true)
{
//alert('Yes');
document.Form1.hdnbox.value='Yes';
}
else
{
//alert('No');
document.Form1.hdnbox.value='No';}

}
</SCRIPT>

<form id="Form1" method="post" runat="server">
<asp:button id="Button1" style="Z-INDEX: 101; LEFT: 352px; POSITION: absolute; TOP: 152px" runat="server" Height="72px" Width="120px" Text="Button"></asp:button>
<asp:DropDownList id="dropdownlist1" style="Z-INDEX: 102; LEFT: 360px; POSITION: absolute; TOP: 104px" runat="server" Width="112px" AutoPostBack="True">
<asp:ListItem Value="Please Select" Selected="True">Please Select</asp:ListItem><asp:ListItem Value="Pen">Pen</asp:ListItem>
<asp:ListItem Value="Eraser">Eraser</asp:ListItem>
</asp:DropDownList></form>

mainpage.aspx.vb:
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Button1.Attributes.Add("onclick", "getMessage()")
Response.Write(Request.Form("hdnbox"))
End Sub

i do feel that there is something wrong with this code... where hsould i improve it or i wrote wrongly ??? please help... thanks a lot guys...

takkie
03-13-2006, 01:02 PM
is your question, why is not doing the response.write(request.form("hdnbox"))??

If it is, it wont. b/c javascript is client side, and the response.write is being run when the page loads, at that point, the value is nothing...

andreshcs
03-13-2006, 07:50 PM
thanks for your reply... that means i put the code in a wrong place is it ? hmm... then is my script in the client side any problem with that ??? i'm not too sure about all this javascript stuffs...

takkie
03-14-2006, 02:50 PM
personally, i havent try this... but i would think it should work..

you keep the part of the javascript... but instead of doing this, document.Form1.hdnbox.value='Yes';... just do a return true or return false.

(for simplicity - in your getMessage function, just do it with 1 line, "return confirm("are you sure blah blah");"

let say the trigger is the dropdownlist, then you set property "autopostback" to true, and then in the onselectionchange event of that dropdownlist, you put your code in there... (you said you want to direct the user to some other page, just response.redirect, or response.transfer, depending on what you need)

if, let say the trigger is not ddl, its a button, you can just put this response.redirect thing in the click event....

tak

TheLastBurden
04-11-2006, 06:48 AM
See if this helps

http://aspnet.4guysfromrolla.com/articles/021104-1.aspx