Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8107999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T00:57:20+00:00 2026-06-06T00:57:20+00:00

I am trying to using the JS to take user input and modify certain

  • 0

I am trying to using the JS to take user input and modify certain object attributes based on the user’s input. I am storing the object’s index in the select’s alt attribute in order to use that to update the correct object. I’m getting an error: element[Payment_Format_name] is undefined

The WF.php file takes data from a CSV and formats it into a mulch-dimensional object.

$(document).ready(function() { 
$.getJSON('WF.php', function(data) {

    var newDiv, NewDiv2, NewDiv3,InvoiceInfo, count, DeliveryMethod, PaymentFormat, Payment_Format_id, Payment_Format_name;

    count = 0;

    $.each(data, function(index, element) {
        count = count + 1; 
        //document.write (count);   

        newDiv = $('<div/>').addClass('row').appendTo('#showdata');

        newDiv3 = $('<div/>').addClass('hd').appendTo(newDiv);
        $('<div class="hd_field">' + element['PmtRec']['RcvrParty']['Name']['Name1'] + '</div>').appendTo(newDiv3);

        if (element['PmtRec']['PmtMethod'] === 'CHK'){

                $('<div class="hd_field">Delivery Method: <select alt="Delivery_Method" " id="Delivery' + count  +'" class="Delivery_Method"><option value="100" selected="selected">US Mail</option><option value="300">Foreign Mail</option><option value="J00">Certified Mail with Return Receipt</option></select><div id="Selected_Method' + count +'"></div></div>').appendTo(newDiv3);
        }
         else if (element['PmtRec']['PmtMethod'] === 'DAC') {
                $('<div class="hd_field">Payment Format: <select alt="'+index +'" id="Payment_' + count  +'" class="Payment_Format"><option value="CTX" selected="selected">Company to Company</option><option value="PPD">Company to Person</option></select><div id="Selected_Format'+count+'"></div></div>').appendTo(newDiv3);

         }
        $('<div class="hd_field">' + 'Total: ' + element['PmtRec']['CurAmt'] + '</div>').appendTo(newDiv3);

        InvoiceInfo = element['PmtRec']['PmtDetail']['InvoiceInfo'];

        $.each(InvoiceInfo, function(index, element) {
        newDiv2 = $('<div/>').addClass('sub_row').appendTo(newDiv);
                $('<div class="field">' + element['InvoiceNum'] + '</div>').appendTo(newDiv2);
                $('<div class="field">' + element['NetCurAmt'] + '</div>').appendTo(newDiv2);
            });

        $('select.Payment_Format').change(function(){ 
            Payment_Format_id = ($(this).attr('id').match(/[\d]+$/));
            Payment_Format_name = ($(this).attr('alt')); 
            //alert(Payment_Format_name);
            PaymentFormat = ($(this).val()); 
            element[Payment_Format_name] = Payment_Format_name;
            element[Payment_Format_name]['PmtRec']['PmtFormat'] = PaymentFormat;
            $('#Selected_Format' + Payment_Format_id).text('Selected Format: ' + element[Payment_Format] );

            });

        });
            console.log(data);
     });

});

PHP (this is a snippet, I’m actually creating a lot more elements here)

     if (($handle = fopen('upload/BEN-new.csv', "r")) === FALSE) {
            die('Error opening file'); 
         }

         $headers = fgetcsv($handle, 1024, ',');
         $cardCodes = array();
         $payments = array();
         $details = array ();

        while ($row = fgetcsv($handle, 1024, ",")) {
               $cardCodes[] = array_combine($headers, $row);

        }

            $prevCode = '';

            foreach ($cardCodes as $key => $value) {

                $payments[$value['CardCode']]['PmtRec']['PmtCrDr'] = 'C';
                $payments[$value['CardCode']]['PmtRec']['PmtFormat'] = 'CTX';
                                    fclose($handle);
                                    echo json_encode($payments)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T00:57:22+00:00Added an answer on June 6, 2026 at 12:57 am

    Ok, so for starters,

    $('select.Payment_Format').change(function(){ 
            Payment_Format_id = ($(this).attr('id').match(/[\d]+$/));
            Payment_Format_name = ($(this).attr('alt')); 
            PaymentFormat = ($(this).val()); 
            element[Payment_Format_name] = Payment_Format_name;
            element[Payment_Format_name]['PmtRec']['PmtFormat'] = PaymentFormat;
            $('#Selected_Format' + Payment_Format_id).text('Selected Format: ' + element[Payment_Format] );
        });
    });
    

    is not what you want – this function is reassigned to the change event of the 'select.Payment_Fomat' element for each iteration of $.each(data, function(index, element). The event listener should be added outside the $.each function, inside the $.getJson call and it needs to loop over the elements object, and try to find the correct data to update.

    Apologies for the uselessness earlier, it was 5am and apparently I was slightly delusional.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to take an input from a user using Scanner(System.in) but when
In JavaScript, I'm trying using the user's input to search my database. For example,
I’m trying to make something that will take lines of input from the user,
I'm trying to take an integer from the user. I'm using cin.ignore to make
I'm trying to take the results of a view - using the function views_get_view_result()
I am trying to take an AES HMAC of a file using the openssl
I am trying to take advantage of hardware encryption of LTO5 devices using ioctl
I am using the jquery plugin datatables and am trying to take advantage of
I'm trying using NHibernate.Search to get Lucene.NET Score through projections. My domain object implements
I'm currently trying to make a button which will take the user back to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.