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?
red_75116Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GaryCommented:
Assuming inline js

var ord = document.getElementById("<%= ifWOnumber.ClientID %>").value;
0
red_75116Author Commented:
The pop up window opens, but this is the URL on the page
CSSerialization_PrintWO.aspx?number=undefined
0
GaryCommented:
If you view the page source what is the id of ifWOnumber - is it just ifWOnumber or some .net inspired ID
0
Exploring ASP.NET Core: Fundamentals

Learn to build web apps and services, IoT apps, and mobile backends by covering the fundamentals of ASP.NET Core and  exploring the core foundations for app libraries.

Miguel OzSoftware EngineerCommented:
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?
0
red_75116Author Commented:
Using a custom control called inputfield and the id is ifWOnumber
0
GaryCommented:
The ID is generated at run time, you need to use

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

not

var ord = document.getElementById("ifWOnumber").value;

There is not ID of ifWOnumber when the html is generated.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.