Click here to Skip to main content
15,867,453 members
Home / Discussions / JavaScript
   

JavaScript

 
Questionapi connection culendar Pin
jagadeesh omkaram14-Feb-23 19:00
jagadeesh omkaram14-Feb-23 19:00 
AnswerRe: api connection culendar Pin
Richard MacCutchan14-Feb-23 22:05
mveRichard MacCutchan14-Feb-23 22:05 
AnswerRe: api connection culendar Pin
Dave Kreskowiak15-Feb-23 1:32
mveDave Kreskowiak15-Feb-23 1:32 
QuestionCopying from billing address to mailing address if they are the same not working correctly Pin
samflex11-Feb-23 12:15
samflex11-Feb-23 12:15 
AnswerRe: Copying from billing address to mailing address if they are the same not working correctly Pin
Richard Deeming12-Feb-23 22:02
mveRichard Deeming12-Feb-23 22:02 
GeneralRe: Copying from billing address to mailing address if they are the same not working correctly Pin
samflex13-Feb-23 5:14
samflex13-Feb-23 5:14 
QuestionAjax didn't work for cloning rows, But works for first row only Pin
amr aly3-Feb-23 8:35
amr aly3-Feb-23 8:35 
AnswerRe: Ajax didn't work for cloning rows, But works for first row only Pin
amr aly9-Feb-23 5:35
amr aly9-Feb-23 5:35 
Finally I fix my issue as usual. I want to share my solution of this issue.

JavaScript
$(document).on('change', '.product', function(e){
            var product_id = $(this).val();
            let $el = $(this).closest('.purchase-row');
            console.log('SUCCESS-CHANGE-PRODUCT: ', product_id,);
            $.ajax({
                type: 'POST',
                url: '{% url "purchases:get_product_unit" %}',
                data: {
                    'pro-product': product_id,
                },
                success: function (data) { 
                    if (purchaseCount == 0) {
                        console.log('purchase count equal to ZERO: ');
                        console.log(
                            'FROM SUCCESS: ', data['unit'],
                        );
                        var values_3 = data['unit'];               
                        if (values_3.length > 0) {
                        
                            for (var i = 0; i < values_3.length; i++) {
                                $el.find('.unit').append('<option>' + values_3[i] + '</option>');
                            }
                        }
                    } else {
                        let unit = $el.find('.newUnit'); // here I can access the "unit input" of the same row of the "product input"
                        var values_3 = data['unit'];
                        unit.text('');
                        console.log('COUNT IS NOT EQUAL TO ZERO:', values_3);
                        if (values_3.length > 0) {
                            for (var i = 0; i < values_3.length; i++) {
                                unit.append('<option>' + values_3[i] + '</option>');
                            }
                        }
                    }
        
                },
                error: function (){
                    console.log('ERROR with ajax request in Adding Purchase !!!');
                },
            });
            e.preventDefault();
        });


Or in an enhanced code snippet as follow

JavaScript
$(document).on("change", ".product", function (e) {
    var product_id = $(this).val();
    let $el = $(this).closest(".purchase-row");
    console.log("SUCCESS-CHANGE-PRODUCT: ", product_id);
    $.ajax({
      type: "POST",
      url: '{% url "purchases:get_product_unit" %}',
      data: {
        "pro-product": product_id
      },
      success: function (data) {
        const values_3 = data.unit;
        const unitClass = purchaseCount == 0 ? ".unit" : ".newUnit";
        const unit = $el.find(unitClass);
        unit.text(''); 
        if (values_3.length) {
          for (const value of values_3) {
            unit.append(`<option>${value}</option>`);
          }
        }
      },
      error: function () {
        console.log("ERROR with ajax request in Adding Purchase !!!");
      }
    });
    e.preventDefault();
  });

QuestionI am using javascript to convert a large table to a pdf Pin
Zahira CHOUIBA26-Jan-23 3:22
Zahira CHOUIBA26-Jan-23 3:22 
QuestionRe: I am using javascript to convert a large table to a pdf Pin
Jeremy Falcon26-Jan-23 8:02
professionalJeremy Falcon26-Jan-23 8:02 
AnswerRe: I am using javascript to convert a large table to a pdf Pin
RickyJudith8-Feb-23 0:24
RickyJudith8-Feb-23 0:24 
QuestionI have problem importing images of Json File on HTML Table Pin
Member 1590151922-Jan-23 2:14
Member 1590151922-Jan-23 2:14 
AnswerRe: I have problem importing images of Json File on HTML Table Pin
Jeremy Falcon24-Jan-23 4:30
professionalJeremy Falcon24-Jan-23 4:30 
Questionsoftware access control Pin
Member 1589900419-Jan-23 0:51
Member 1589900419-Jan-23 0:51 
AnswerRe: software access control Pin
Richard Deeming19-Jan-23 1:25
mveRichard Deeming19-Jan-23 1:25 
QuestionUse async function to retrieve data while looping through from another function to insert objects Pin
Member 1589206711-Jan-23 23:35
Member 1589206711-Jan-23 23:35 
AnswerRe: Use async function to retrieve data while looping through from another function to insert objects Pin
Richard Deeming12-Jan-23 0:02
mveRichard Deeming12-Jan-23 0:02 
QuestionRe: Use async function to retrieve data while looping through from another function to insert objects Pin
Member 1589206712-Jan-23 1:38
Member 1589206712-Jan-23 1:38 
AnswerRe: Use async function to retrieve data while looping through from another function to insert objects Pin
Richard Deeming12-Jan-23 2:31
mveRichard Deeming12-Jan-23 2:31 
PraiseRe: Use async function to retrieve data while looping through from another function to insert objects Pin
Member 1589206712-Jan-23 3:17
Member 1589206712-Jan-23 3:17 
GeneralRe: Use async function to retrieve data while looping through from another function to insert objects Pin
Richard Deeming12-Jan-23 3:39
mveRichard Deeming12-Jan-23 3:39 
AnswerRe: Use async function to retrieve data while looping through from another function to insert objects Pin
Jeremy Falcon12-Jan-23 8:44
professionalJeremy Falcon12-Jan-23 8:44 
AnswerRe: Use async function to retrieve data while looping through from another function to insert objects Pin
Leon Scott Kennedy13-Jan-23 5:25
Leon Scott Kennedy13-Jan-23 5:25 
QuestionJava Script Pin
Prerna Kharbanda3-Jan-23 20:56
professionalPrerna Kharbanda3-Jan-23 20:56 
AnswerRe: Java Script Pin
Richard MacCutchan3-Jan-23 21:33
mveRichard MacCutchan3-Jan-23 21:33 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.