dennisT
dennisT

Reputation: 57

jquery, variable is undefined when the value has string characters

I am declaring a variable in jquery. The value is a part number from a data warehouse. It is always a string even though most of the time it is a string of numbers. When the part id is all numbers like '4125052' there are no errors but if the first digit is a string like 'B4125052' then I get the error-- `Error: 'B4125052' is undefined. When I go to view/source on the outputted page I see the value as $itemid=B4125052; (no quotes).

    <%string id = Model.Part.Select(x => x.Id).FirstOrDefault().Trim(); %>
    <%int partsetupid = Model.PartSetUp.PartSetUpID; %>
    <%int numtoprint = Model.NumContinuationTCs; %>
    <script language="javascript" type="text/javascript">
     $(this).ready(function () {
             var $theHtml = null;
             var $itemid=null;
             var $partsetupid=null;
             $itemid=<%=id%>;
             setupid=<%=partsetupid%>;
                theHtml = $("html").html()
             $.download('<%= Url.Action("TravelCardReport","Reports") %>', { filename_: $itemid, format: "pdf", numtoprint_:<%=numtoprint%>, html_: theHtml,partsetupid_:setupid }, "post");
             $('#Wrapper').hide();
         });
        </script>

Upvotes: 0

Views: 208

Answers (1)

Joe
Joe

Reputation: 15812

Change

$itemid=<%=id%>;

to

$itemid="<%=id%>";

Upvotes: 1

Related Questions