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


        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 ="CSSerialization_PrintWO.aspx?number=" + ord, "Print", sOption);


What am I doing wrong?
Who is Participating?
GaryConnect With a Mentor Commented:
The ID is generated at run time, you need to use

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


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

There is not ID of ifWOnumber when the html is generated.
Assuming inline js

var ord = document.getElementById("<%= ifWOnumber.ClientID %>").value;
red_75116Author Commented:
The pop up window opens, but this is the URL on the page
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

If you view the page source what is the id of ifWOnumber - is it just ifWOnumber or some .net inspired ID
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?
red_75116Author Commented:
Using a custom control called inputfield and the id is ifWOnumber
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.