0

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>
1
  • You have almost answered your own question "[..] I see the value as $itemid=B4125052;(no quotes)." Commented Sep 15, 2011 at 21:48

1 Answer 1

1

Change

$itemid=<%=id%>;

to

$itemid="<%=id%>";
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Znarkus that worked like a charm. I tried putting quotes around it but I was concatenating them not just placing quotes directly around the variable.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.