File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes in Jquery getting  two value undefined Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "in Jquery getting  two value undefined" Watch "in Jquery getting  two value undefined" New topic
Author

in Jquery getting two value undefined

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055



I have added one button called Add onclick it calls insertProjectAllcation(prjid.val(),allcationpercentage.val()), but in the firefox console its showing prjid is undefined.Please help where I am going wrong.



http://www.lifesbizzare.blogspot.com || OCJP:81%
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Why is all that HTML in a string?

In any case prjid (please use real words in variable names -- makes them much easier to read) is not defined. You are treating it like a global variable, and its not.

And as you are using jQuery, why would you define event handlers with onclick rather than with jQuery?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 1055

Bear Bibeault wrote:Why is all that HTML in a string?

In any case prjid (please use real words in variable names -- makes them much easier to read) is not defined. You are treating it like a global variable, and its not.

And as you are using jQuery, why would you define event handlers with onclick rather than with jQuery?


Sorry Bear, I didnt get what you are trying to convey?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Vishal Hegde wrote:I didnt get what you are trying to convey?

Three things:
  • Building up HTML markup in strings is not a good thing to do. Do you find any of that readable? How hard will it be to maintain? Can you easily see what's being created?
  • You can't reference variables that are not in scope.
  • When using jQuery you should never use the onclick, or other "on" attributes in markup. Rather, use the jQuery handler binding methods to bind event handlers.

  • Ryan Tracy
    Ranch Hand

    Joined: Mar 21, 2001
    Posts: 33
    prjid is out of scope. You probably want to use the jquery selector inside the onclick instead of the variable you are using there. However, you are using jQuery so you should be able to just declare the on click event outside of all the crazy htmlData stuff you got going on there. I understand you sometimes have to based on what you are trying to accomplish, but you could just hold the html in a hidden div and call $(div).html() to get the content formatted nicely. I hope I helped. GL
    Vishal Hegde
    Ranch Hand

    Joined: Aug 01, 2009
    Posts: 1055

    One more doubt, I need to add taglib within the htmldata ..I tried the below code, is this correct?

    Vishal Hegde
    Ranch Hand

    Joined: Aug 01, 2009
    Posts: 1055

    Bear Bibeault wrote:
    Vishal Hegde wrote:I didnt get what you are trying to convey?

  • You can't reference variables that are not in scope.


  • Dear Bear,

    I am confused here, can you please let me know which reference variable is a Global variable in here? and how Global Variable cannot be in Scope.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61413
        
      67

    Unless there's something you're not showing us, there is no global variable.

    And again, building up all that HTML in a string is pretty awful. Why do you need to do it that way?
    Vishal Hegde
    Ranch Hand

    Joined: Aug 01, 2009
    Posts: 1055

    Bear Bibeault wrote:Unless there's something you're not showing us, there is no global variable.

    And again, building up all that HTML in a string is pretty awful. Why do you need to do it that way?


    Dear Bear,

    I need to display it in the colorbox, for instance when some button is clicked a popup with this html page will be displayed.Hence i am doing like that.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61413
        
      67

    You do not need to do it that way. With just a few minutes of investigation it's clear that the colorbox plugin can get its HTML from many sources. Hard-coding HTML in a string as you have done here is likely the worst possible choice. I'd investigate using existing inline hidden HTML.
    Ryan Tracy
    Ranch Hand

    Joined: Mar 21, 2001
    Posts: 33
    I agree with Bear. You are doing it the most difficult way. Just put it in the DOM with style="display:none". Then just show/hide using jQuery's show and hide. Another option would be to load them via ajax as they are needed.
    Vishal Hegde
    Ranch Hand

    Joined: Aug 01, 2009
    Posts: 1055

    Ryan Tracy wrote:I agree with Bear. You are doing it the most difficult way. Just put it in the DOM with style="display:none". Then just show/hide using jQuery's show and hide. Another option would be to load them via ajax as they are needed.


    Dear Ryan,

    Thanks for your response.So suppose i declare a simple dropdown textbox in the colorbox.How can I display the values from the database table in the colorbox.
    Bear Bibeault
    Author and ninkuma
    Marshal

    Joined: Jan 10, 2002
    Posts: 61413
        
      67

    If you want to dynamically generate the content, colorbox also appear to allow you to provide the source via Ajax. You could use a small JSP on the server to generate the markup with the database values.
    Ryan Tracy
    Ranch Hand

    Joined: Mar 21, 2001
    Posts: 33
    Sample of possible solution:

    Ryan Tracy
    Ranch Hand

    Joined: Mar 21, 2001
    Posts: 33
    Having never used colorbox. I do not know how to answer your question. But if I were to populate a select box in html I would have a servlet response return json, which then javascript can easily convert that json to option tags in a select tag. Inside the servlet would be the query for the data results which then would be converted the json format for sending as the response.

    If I wanted to return an html snippet to then be placed into the DOM. You just have the servlet return the html snippet and do the sample code I placed above.
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: in Jquery getting two value undefined