Link to home
Start Free TrialLog in
Avatar of red_75116
red_75116Flag for United States of America

asked on

Passing parameter from HTML to javascript function

I am trying to pass a html control value to a javascript function.   My field is ifWOnumber, but when it opens the page the URL says


csserialization_printWO?number=undefined


        function PrintThisPage(ord_no) {
            var sOption = "toolbar=yes,location=no,directories=yes,menubar=yes,";
            var ord = document.getElementById("ifWOnumber").value;
            sOption += "scrollbars=yes,width=750,height=600,left=100,top=25";
            var winprint = window.open("CSSerialization_PrintWO.aspx?number=" + ord, "Print", sOption);

            winprint.focus();
        }

What am I doing wrong?
Avatar of Gary
Gary
Flag of Ireland image

Assuming inline js

var ord = document.getElementById("<%= ifWOnumber.ClientID %>").value;
Avatar of red_75116

ASKER

The pop up window opens, but this is the URL on the page
CSSerialization_PrintWO.aspx?number=undefined
If you view the page source what is the id of ifWOnumber - is it just ifWOnumber or some .net inspired ID
Use UniqueID to get the required value:
var ord = document.getElementById("<%= ifWOnumber.UniqueID %>").value;

Your control's container is introducing prefixes thus the need for UniqueID to identify the control. This solution only works for inline JS not if the method is declared in a JS file.

Where is PrintThisPage called/declared?Inline?
Using a custom control called inputfield and the id is ifWOnumber
ASKER CERTIFIED SOLUTION
Avatar of Gary
Gary
Flag of Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial