Click here to Skip to main content
15,899,313 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi every body,

I want to when i ckeck some checkbox in ASP.net Page
that execute javascript method,
this method take id of hiddenfield as parameter,
then this javascript method check the value of hiddenfield and if the value equal to specific value
then messagebox appear and if i accept then checkbox is checked else not checked.
the is like that:

JavaScript
function CheckHiddenfieldValue(hdhiddenfieldID)
        {
            var hiddenField = document.getElementById(hiddenID);
            
            if (hiddenField.value == 'N') 
            {
                alert('any thing');
            }
        }


That is my checkbox:

ASP.NET
<asp:CheckBox id="chkSpecific" runat="server" onclick="CheckHiddenfieldValue('<%= Hidden1.ClientID %>')" visible = "false">


and that is Hiddenfield:

ASP.NET
<asp:hiddenfield id="Hidden1" runat="server">
Posted
Updated 20-Oct-11 11:12am
v3

My friend there is no MessageBoxShow method or routine in javascript. You have to use a
JavaScript
confirm("Are you sure you want to delete this ?");
or some custom framework like jQuery [^] or Dojo [^]dialog.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 20-Oct-11 15:54pm    
Good answer, my 5.
At the same time, I advised an alternative, just because usability of a modal dialog is, well, limited.
Please see my solution, with reference to a previous one (:-).
--SA
Wonde Tadesse 20-Oct-11 16:02pm    
Thanks --SA
As soon as you planned to use modal dialog, the advice by Wonde would work just fine for you.

I only want to note that any kind of modal behavior would be somewhat annoying the the user, who mostly would prefer just to stay on a single page and not distracted by any other window until she or he decides to navigate away. So, you really might want to use a check box.

In this case, you need to use checkbox.checked. Also, comparison with null makes no sense; you just need to write "if (checkbox.checked)". You can find a sample of whole thing in my previous solution: HTML Forms with JavaScript[^].

Good luck,
—SA
 
Share this answer
 
v3
Comments
Wonde Tadesse 20-Oct-11 16:04pm    
My 5+. for alternate option.
Sergey Alexandrovich Kryukov 20-Oct-11 16:23pm    
Thank you, Wonde.
--SA
MrLonely_2 20-Oct-11 17:16pm    
Thanks man, but i hope you to write the javascript method according to my case,
I updated my question to be more clear, as i am beginner in javascrpit,
Please test your code before and i am appreciate your effort,
Thank you very much gentle man
Sergey Alexandrovich Kryukov 21-Oct-11 20:25pm    
Sorry, but being a beginner does not mean be a kid from kindergarten required being fed from a spoon. I'm just trying to help more people by one shot. So, I though you will be quite able to convert referenced code into your case. If you cannot, it's your turn to ask what was your problem, not my turn to do it per your order. Isn't that fair? (By the way, I wonder, was that you who down-voted this post, perhaps, on these grounds?) I'm really sorry if you expected me to be more gentle that I am. :-)

Cheers,
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900