Question

I actually got it to work using the code below.Thanks to all who gave me their inputs, but have to say I had difficulties getting it to work properly. Hope it will be helpful to somebody else who is new in javascript.

function SelectedRow() {
            (function () {
                if (window.addEventListener) {
                    window.addEventListener('load', run, false);
                } else if (window.attachEvent) {
                    window.attachEvent('onload', run);
                }

                function run() {
                    var table = document.getElementById('alternativeCableTable');
                    table.onclick = function (event) {
                        var target = event.target || event.srcElement;
                        while (target && target.nodeName != 'TR') { 
                            target = target.parentElement;
                        }              
                        var cells = target.cells;              
                        if (!cells.length || target.parentNode.nodeName == 'THEAD') {
                            return;
                        }
                        var stockcode = document.getElementById('stockcode');
                        var wiretype = document.getElementById('wiretype');
                        var wirelength = document.getElementById('wirelength');
                        var terminalA = document.getElementById('termA');
                        var sealA = document.getElementById('sealA');
                        var terminalB = document.getElementById('termB');
                        var sealB = document.getElementById('sealB');
                        stockcode.value = cells[0].innerHTML;
                        wiretype.value = cells[1].innerHTML;
                        wirelength.value = cells[2].innerHTML;
                        terminalA.value = cells[3].innerHTML;
                        sealA.value = cells[4].innerHTML;
                        terminalB.value = cells[5].innerHTML;
                        sealB.value = cells[6].innerHTML;
                        alert("The select data is sent to print page");
                        window.open("http://10.19.13.67/ReworkLabels/PrintLabelPage.aspx?stockcode=" + decodeURIComponent(stockcode.value) + "&wiretype=" + decodeURIComponent(wiretype.value) + "&wirelength=" + decodeURIComponent(wirelength.value)
                       + "&terminalA=" + decodeURIComponent(terminalA.value) + "&sealA=" + decodeURIComponent(sealA.value) + "&terminalB=" + decodeURIComponent(terminalB.value) + "&sealB=" + decodeURIComponent(sealB.value),"_blank");

                    };

                }

            })();
        }
Was it helpful?

Solution 2

Try

 window.open("http://Testing/ReworkLabels/Default.aspx?"+f1.value+"&"+f2.value,"my window");

instead.

OTHER TIPS

Use Local Storage, instead of passing URL parameters and/or cookies, as the later two have a lot of limitations.

See an example how to do so in http://www.webdesignerdepot.com/2013/04/how-to-use-local-storage-for-javascript/

If you need these values for some reason server-side, then you could utilize JSON serialization to pass the values as POST parameters. (Or just HTML forms with hidden inputs; Do not forget to put name attributes on the html form elements that needs to be submitted to server.)

EDIT: On second reading of your question, it looks like you just need 2 simple string values. In this case check the value properties of the two input elements. https://developer.mozilla.org/en/docs/Web/API/HTMLInputElement

Also you might want to give names to these GET parameters, e.g.

window.open("http://Testing/ReworkLabels/Default.aspx?f1="+encodeURIComponent(f1.value)+"&f2="+encodeURIComponent(f2.value),"my window");

See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent for more information about encodeURIComponent function.

See Retrieve GET variables from URL in ASPX in order to read these parameters in the target ASP.NET page.

Also make sure to not print their values directly (but properly escaped), to avoid cross site scripting (XSS) vulnerability.

See http://msdn.microsoft.com/en-us/library/ff649310.aspx and How do you avoid XSS vulnerabilities in ASP.Net (MVC)?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top