Problem with confirm box in javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • swethak
    New Member
    • May 2008
    • 118

    #1

    Problem with confirm box in javascript

    Hi,


    I want to applying the styles for confirm box. For this purpose i have used below code.

    Here i am writting my code
    Code:
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
    <title>untitled</title>
    <meta http-equiv="content-type" content="application/xhtml+xml; charset=utf-8" />
    <script type="text/javascript">
    function doConfirm(v)
    {
    var b = document.getElementById('btn');
    b.value = 'Display dialog [last return value: ' + v + '/' + (v ? 'OK' : 'Cancel') + ']';
    }
    
    function setDisp(id, disp, some)
    {
    document.getElementById(id).style.display = disp;
    return some;
    }
    </script>
    <style type="text/css">
    #confirm {
    position: absolute;
    top: 40px;
    left: 70px;
    border: outset #000 10px;
    padding: 1em 3em;
    display: none;
    background: #a5c4cc;
    }
    
    #ok {
    background: #a5cca8;
    }
    
    #cancel {
    background: #d6a4a4;
    }
    
    #ok, #cancel {
    padding: 2px;
    margin:2px;
    }
    </style>
    </head>
    <body>
    <div id="confirm">
    <div><strong>Are</strong> <em>you</em> <span style="text-decoration: underline;">sure</span>?</div>
    <input type="button" id="ok" value="OK" onClick="setDisp('confirm', 'none','yes');" />
    <input type="button" id="cancel" value="Cancel" onClick="setDisp('confirm', 'none','no');" />
    </div>
    <input type="button" id="btn" value="Display dialog" onClick="setDisp('confirm', 'block','');" />
    </body>
    </html>

    In above code i have to set return value to the function setDisp() as true/false when click on ok ,cancel buttons. That means when i used the function setDisp() directly then it displayed the pop up window consists the ok,Cancel buttons.When i click on ok this function setDisp() returns true and when click on cancel this function setDisp() returns false. That is my requirement .Any body could you please help me how can get the Requirement.



    Thanks
    Swetha
  • paulrajj
    New Member
    • Sep 2008
    • 47

    #2
    try something like this in your javascript code
    Code:
    function setDisp(id, disp, some)
    {
    
    document.getElementById(id).style.display = disp;
    if(some != '') 
    {
    	doConfirm(some); 
    }
    return some;
    
    }

    Comment

    • swethak
      New Member
      • May 2008
      • 118

      #3
      Hi,



      I tried like this .But i am not getting. please advice me.









      Thanks
      Sravani

      Comment

      • paulrajj
        New Member
        • Sep 2008
        • 47

        #4
        hi,

        just make a little change in doConfirm function then try it out. It works fine in both IE and FF.
        Code:
        function doConfirm(v)
        {
        var b = document.getElementById('btn');
        (v == 'yes') ? z = 'OK' : z = 'Cancel';
        b.value = 'Display dialog [last return value: ' + v + '/' + (z) + ']';
        }

        Comment

        Working...