Radio Button, Javascript, and a confirm or messagebox

Rani

Well-known member
Joined
Nov 19, 2005
Messages
71
Programming Experience
Beginner
I am having two radio buttons on the page with Yes/No option and a payment received button right next to the radio buttons.
First time when the page is loaded, one of the two radio buttons is selected based on the boolean type field value in the database 0 OR 1.
when the user decides to change the value from yes to No and click the payment received button, I not only want to make changes to the database field but also show a confirm box for the user to be sure and then change the field value.

I am having javascript function in my html page,
I have two radio buttons, and a regular submit button,
In my code behind page i am writing an if statement and want to prompt the confirm box before i make the changes to the data field in the database.

right now when i run the program it changes the value in database, but does not show me the box.

Please help me.
Thanks/Saru
 
here it is: I tried this and it still does not call my javascript function. instead it shows only a empty msg box with ok and cancel button

VB.NET:
IfMe.rdoYes.Checked Then
Response.Write("<script>confirm()</script>")
Dim sql1 AsString = "update CollegeCreditRegForm set paymentreceived = 1 where ccid = " & ds.Tables(0).Rows(0).Item("ccid") & " and ordernumber = " & Session("id")
Dim da1 AsNew SqlDataAdapter(sql1, con)
da1.Fill(ds)
ElseIfMe.rdoNo.Checked Then
Response.Write("<script>confirm()</script>")
Dim sql1 AsString = "update CollegeCreditRegForm set paymentreceived = 0 where ccid = " & ds.Tables(0).Rows(0).Item("ccid") & " and ordernumber = " & Session("id")
Dim da1 AsNew SqlDataAdapter(sql1, con)
da1.Fill(ds)
EndIf
 
Last edited by a moderator:
My javascript is:

HTML:
function confirm() 
{ if (confirm("Are you sure?")==true) return true; 
else return false; }
 
Last edited by a moderator:
maybe you should name you rmethod something else than the Javascript 'confirm' method?
 
i used this javascript in another project when i had to use datagrid. there i was able to call this function in itemdatabound.

the same function is not working when i am using <asp:button>.
I can't call onclick="confirm()";because the button does not have click property.

changing the name of the function confirm would not make the difference.

 
The asp:button is really an Input tag client side. You may attach any valid DOM attribute to the element:
VB.NET:
Button1.Attributes.Add("onclick", "myConfirm();")
The asp:button also got the OnClientClick property that translates to the same.
 
you are writing back the line of code that i already having trouble with.

seems like you did not understand the problem i have.

I have a javascript function name ----confirm--
On the page i have two rdo button yes/no.
the page is loaded the first time per the value in the db yes or no
On the page when it appears for ex No, the user wants to change the option to Yes. In that case they would select yes and click a button --Change Payment--
so the changepayment on click event will fire.
when the changepayment event fires on the click of the change payment button, i am changing the value in the database and before that i want to call the javascript function ---confirm--- to show the message box for the user "are you sure?"
where and how would i call so the javascript function confirm msg shows up.
 
Client click event happens before server postback and server click event. use the client Javascript confirm code to get a decision, store the value in a hidden field, then when server postbacks check the confirm return value by getting it from that field.
 
confirm box

this is how far i have gotten. I have made progress.

When user wants to change the paymet from Yes to No using rdoYes/rdoNo radio buttons and click the ChangePayment button, i am showing a confirm box.

I am able to show the confirm box with Ok and Cancel option with a message "Are you sure?"

I am able to change the value in the db, but if they choose to cancel it does not cancel. Instead the value is changed in the db and it does not cancel on the page.

**Please see my code attachment*

I did not follow your tip. can you please be more specific. I am new to this field.

thank you for your time and patience.
 

Attachments

  • confirm.txt
    1.7 KB · Views: 30
Add a HiddenField control to the page and change your Javascript to this:
HTML:
function confirmit() { 
document.getElementById("HiddenField1").innerText=confirm("Are you sure?");
}
In your btnchangepayment.Click do:
VB.NET:
If HiddenField1.Value = "true" Then
'database update code
End If
 
Thank you very much for your response. I am at home and my project is at work.
Just one more question i have in my btnchangepayment_click procudure,
I have these db update code. Do i include your line for both rdo checked like

If hiddenfield1.value = true and
If Me.rdoYes.Checked Then
Dim sql1 As String = "update CollegeCreditRegForm set paymentreceived = 1 where ccid = " & ds.Tables(0).Rows(0).Item("ccid") & " and ordernumber = " & Session("id")
Dim da1 As New SqlDataAdapter(sql1, con)
da1.Fill(ds)

Else if hiddenfield1.value=false then
Dim sql1 As String = "update CollegeCreditRegForm set paymentreceived = 0 where ccid = " & ds.Tables(0).Rows(0).Item("ccid") & " and ordernumber = " & Session("id")
Dim da1 As New SqlDataAdapter(sql1, con)
da1.Fill(ds)
End If

**Is only one hidden field is required?

Thanks so very much for your help.
 
Back
Top