Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

in Jquery getting two value undefined

 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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.


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Vishal Hegde
Ranch Hand
Posts: 1077
Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 65218
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
    Posts: 46
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 1077
    Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    One more doubt, I need to add taglib within the htmldata ..I tried the below code, is this correct?

     
    Vishal Hegde
    Ranch Hand
    Posts: 1077
    Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 65218
    95
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 1077
    Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 65218
    95
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 46
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 1077
    Java Windows
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Pie
    Posts: 65218
    95
    IntelliJ IDE Java jQuery Mac Mac OS X
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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
    Posts: 46
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    Sample of possible solution:

     
    Ryan Tracy
    Ranch Hand
    Posts: 46
    • Mark post as helpful
    • send pies
    • Quote
    • Report post to moderator
    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.
     
    • Post Reply
    • Bookmark Topic Watch Topic
    • New Topic