Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums JavaScript Update price onchange via jQuery

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #176728
    Presto
    Participant

    Hello everyone,

    I’m trying to update a price column in my HTML table via a select option with onchange using jQuery, but i’m not having much luck, the function name I’m using is called “updatePrice”, you can view my code here: http://codepen.io/Presto/pen/uvkmc

    I was trying .parent, then I gave .closest a try without much luck, if you could point me in the right direction that would be great, thanks :)

    #176737
    Chromawoods
    Participant

    updatePrice does not know what $(this) is. If you log it to the console, you will see that it in the context of that function, this refers to the window object. You have named the param e, which is misleading because it’s not an event, it’s the actual select element. So to make it work, you could do:

    function updatePrice(select) {
        $(select).parent().siblings('.price').html(select.value);
    }
    

    So you are turning a list into a table using JS. I assume you can’t just have the table being served in the markup to begin with? If you really really need to create it like that, I think I would build the table using jQuery objects from the start and then register event handlers on them using jQuery, not the onchange attribute, that’s weird IMO. replaceWith can take jQuery as a parameter, so it should be fine.

    #176739
    Presto
    Participant

    Awesome, thank you so much!

    Yes the ideal solution would of been to do it in ether HTML or in jQuery, the idea that I’m working on is converting un/organized lists in to a functioning pricing table, i.e. making it really simple for a user to add a list and not having to worry about knowing any HTML, CSS, or Javascript.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘JavaScript’ is closed to new topics and replies.