0

I make a pop up form using java script and i'm kinda new in java script . The pop up form has TextBox and a anchor . Now my question is how can i call the on click event of the button and also get the button using c# code.

<script type="text/javascript">
        function showBox() {
            var width = document.documentElement.clientWidth + document.documentElement.scrollLeft;

            var layer = document.createElement('div');
            layer.style.zIndex = 2;
            layer.id = 'layer';
            layer.style.position = 'absolute';
            layer.style.top = '0px';
            layer.style.left = '0px';
            layer.style.height = document.documentElement.scrollHeight + 'px';
            layer.style.width = width + 'px';
            layer.style.backgroundColor = 'black';
            layer.style.opacity = '.6';
            layer.style.filter += ("progid:DXImageTransform.Microsoft.Alpha(opacity=60)");
            document.body.appendChild(layer);

            var div = document.createElement('div');
            div.style.zIndex = 3;
            div.id = 'box';
            div.style.position = (navigator.userAgent.indexOf('MSIE 6') > -1) ? 'absolute' : 'fixed';
            div.style.top = '200px';
            div.style.left = (width / 2) - (400 / 2) + 'px';
            div.style.height = '100px';
            div.style.width = '400px';
            div.style.backgroundColor = 'white';
            div.style.border = '2px solid silver';
            div.style.padding = '20px';
            document.body.appendChild(div);

            var p = document.createElement('p');
            p.innerHTML = 'Input BFG';
            div.appendChild(p);

            var b = document.createElement("INPUT")
            b.placeholder = "BFG";
            div.appendChild(b);

            var a = document.createElement('a');
            a.innerHTML = 'Close window';
            a.href = 'javascript:void(0)';
            a.id = "btnSave"
            a.onclick = function () {
                document.getElementById(a)
                document.body.removeChild(document.getElementById('layer'));
                document.body.removeChild(document.getElementById('box'));

            };

            div.appendChild(a);
        }
    </script>

Note: i don't have the html part of the popup form its created only using java script. any help would be truly appreciated

  • your onclick handler should have a post or a get call so that yourpage.cs receives whatever data you are trying to pass to it. – pcalkins Jul 30 '19 at 23:40
  • would you guid me to do that sir? , i just copy this line of code in article – Von Justine Napalang Jul 30 '19 at 23:43
  • For plain Javascript, you can use a utility function like what is mentioned here: https://stackoverflow.com/questions/247483/http-get-request-in-javascript I would learn Javascript first, and then move to using jQuery or something similar for all of this. In jQuery it'd just be a call to .get or .post with callbacks for updating the client side after the server-side processes it's part. – pcalkins Jul 30 '19 at 23:52

0 Answers0