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 8734687
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:53:35+00:00 2026-06-13T09:53:35+00:00

I am using PHP to dynamically generate some fields in a form (here is

  • 0

I am using PHP to dynamically generate some fields in a form (here is jsFiddle with full code http://jsfiddle.net/KBYC5/1/).

<?php 
            $contacts= array('CONTRACT MANAGER', 'MEDICAL DIRECTOR', 'UTILIZATION MANAGER', 'QUALITY IMPROVMENT MANAGER ', 'CHIEF MEDICAL DIRECTOR', 'CMO', 'AUTHORIZATION MANAGER', 'CUSTOMER SERVICE MANAGER');
            foreach ($contacts as $contact) //TODO add something to check if contact already exists and don't show checkbox if it does
            {
                echo "<li>
                        <label>" . ucwords(strtolower($contact)) . "</label>" . inp_return('contact[]', 45) . " <input type='hidden' value='$contact' name='title' /> 
                        <ul>
                            <li><label> Rating: </label>" .  inp_return('rating[]',3) . "</li>
                            <li><label>Phone: </label>" . inp_return('contact_phone[]',13, 'phone'). "</li>
                            <li><label>Ext: </label>" . inp_return('ext[]', 8) . "</li>
                            <li><label>Create Referral Contact</label> " . cbox_return('create_contact[]') . "</li> 
                        </ul>
                        <div class='clear'></div>
                    </li>
                ";
            }
        ?>

As you can see, each will have a hidden input with the value from $contacts. What I am then trying to do is use jQuery to check for the value in the hidden input field, compare it to the “title” property of the JSON object, and then, if they are the same, fill in all of the form values. My script section is here:

<script type='text/javascript'>
var contacts = $.parseJSON('[{"id":1,"name":"TEST CONTACT","title":"CONTRACT MANAGER","rating":5,"phone":"(000)000-0000","ext":"1111","rfcode":"0000"},
{"id":2,"name":"TEST2 CONTACT","title":"MEDICAL DIRECTOR","rating":2,"phone":"(111)111-1111","ext":"2222","rfcode":"0000"}]');
$(document).ready(function () {$("#contracting_info ul li").each(function (){
    for (var i in contacts)
        {
            alert($(this).children("input[name='title']").val()); die;
            var title = contacts[i].title
            if (title == $(this).children("input[name='title']").val())
                alert('made it here');
        }
    });
});

How can I load the contact[] element in each list item with the value from the JSON array (where title matches hidden title element)? For example, I want the Contract Manager’s contact[] field to have TEST CONTACT in it.

  • 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-13T09:53:37+00:00Added an answer on June 13, 2026 at 9:53 am

    Here is the script section that worked for my problem.

    <script type='text/javascript'>
    var contacts = $.parseJSON('<?php echo json_encode(sql::results("SELECT * FROM crm.dbo.managed_care_contacts where rfcode =" . hexstr($referral->get_id())));?>');
    $(document).ready(function () {
    
        $("#contracting_info li").each(function (){
            for (var i in contacts)
            {
                alert(contacts[i].title + ' ' + $(this).children("input[name='title']").val());
                var title = contacts[i].title
                if (title == $(this).children("input[name='title']").val())
                    {
                            $(this).children("input[name='contact[]']").val(contacts[i].name);
                            $(this).find("input[name='contact_phone[]']").val(contacts[i].phone);
                            $(this).find("input[name='ext[]']").val(contacts[i].ext);
                            $(this).find("input[name='rating[]']").val(contacts[i].rating);
    
    
                    }
            }
        });//close .each (for autofilling form
    });
    
    </script>
    

    Unfortunately, it means I have to loop through each list item element, then loop through all of the contacts (so I end up looping through contacts for each li). It is working properly though.

    Hopefully this helps someone else that is trying to dynamically fill form fields with information from a json object (where the form fields post to an array).

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

Sidebar

Related Questions

i'm using this to generate a textbox dynamically:` <html> <head> <title>Dynamic Form</title> <script type=text/javascript
I am trying to pass dynamically created form fields to a php script, and
I generate some images using a PHP lib. Sometimes the browser does not load
How to find checkbox values from Dynamically generated Divs in php using javascript? Here
I am creating an image dynamically using php. The image is being created if
I am trying to dynamically create an XML file using php like this: header
I am using an JavaScript (and AJAX) to dynamically load a PHP page into
Using PHP I'm trying to download/save the following image: http://www.bobshop.nl/catalog/product_image.php?size=detail&id=42428 When you load this
Using php I am trying to get some data from a .csv file which
I have a form that has some fields and then some more generated by

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.