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

  • SEARCH
  • Home
  • 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 9134291
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T08:38:02+00:00 2026-06-17T08:38:02+00:00

I have a php webform that uses an external js file that external files

  • 0

I have a php webform that uses an external js file

that external files runs events such as: onload, onchange, and onSubmit

In my php application, I have gathered data from db my using this:

<?php
$reqFlds  = array();
$results = mysql_query("select id, display_name from field where account_id = $acct_id2 and required_flag = 1");
    while($RequireResult = mysql_fetch_assoc($results))
        {
            $reqFlds[] = $RequireResult;
        }
    foreach($reqFlds as &$reqFld)
        {
            $reqFld = "'".$reqFld["id"] . "||" . $reqFld["display_name"]."'";
        }
?>

I then use json to gather the data and dump it into an variable
js script inside php application

<script language="javascript">
    var holdReqFlds = <?php echo json_encode($reqFlds); ?>;
</script>

The var/array result displays like this
View from page source

<script language="javascript">
    var holdReqFlds = ["'15||Project Requested By'","'18||Project Title'","'20||Banner Details'","'202||Flyer Details'","'2134||If Gl Code Not above'","'5862||Quantity'"];
</script>

Admittedly, I am just learning json, so here is what I can’t figure out: how do I feed this value to the function in my external js file?

Below is the javascript function for reference – this will run when the submit button is clicked within php app. In short – i’m passing all the fields flagged as required to the holdReqFlds variable. That var will then be passed to the chkReq() function below and determine if a field is within a fieldset that is currently being displayed

i need to pass the holdReqFlds var to the chkReq() function that is in the external javascript file: How?

 * ###################################
 *  PAGE ONSUBMIT FUNCTION
 * ###################################

function job_onsubmit(action)
{
function isVisible(field) {
    if (field.offsetWidth === 0 || field.offsetHeight === 0) return false;
}

function isBlank(field) {
    if ((field.type == "text" || field.type == "textarea") && field.value.length <= 0) return true;
    if (!(field.checked || field.selected || field.selectedIndex > -1)) return true;
    return false;
}

function chkReq(fieldList) {
    var field = null;
    var blankFields = [];
    for (var i = 0; i < fieldList.length; i++) {
        listItem = fieldList[i].split;
        fieldId = field[0];
        label = field[1];
        field = document.getElementById(fieldList[i].split("||")[0]);
        if (isVisible(field) && isBlank(field)) {
            blankFields[blankFields.length] = fieldList[i].split[1];
        }
    }
    if (blankFields.lentgh > 0) {
        displayError(blankFields);
        return false;
    } else {
        return true;
    }
}

function displayError(blankFields) {
    var msg = "Input required:\n\n";
    for (var i = 0; i < blankFields.length; i++) {
        msg += blankFields[i] + "\n";
    }
}
}
  • 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-17T08:38:03+00:00Added an answer on June 17, 2026 at 8:38 am

    Assuming that holdReqFlds is available in global scope you would just do:

    var result = chkReq(holdReqFlds);
    

    One other thing of note is that your JSON looks odd in that you have single quotes inside the double quotes for each value. It seems very strange the way you are concatenating these values together. You are probably better off just building actual objects and JSON encoding them so you don’t have to deal with any string manipulation in javascript to get at the values. Try something like this:

    while($RequireResult = mysql_fetch_object($results)) {
        $reqFlds[] = $row;
    }
    
    $json = json_encode($reqFlds);
    

    This will give you a nice of array of objects that are way easier to work with in javascript.

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

Sidebar

Related Questions

I have a process defined in a batch file that runs 3 php scripts,
Hi I have a web form that sends a string to one php file
I've got a problem with a webform that uses PHP. I'm sure it's very
I have a html form that sends POST data to php file. In php
I have this language based application that has language files for each part of
I have a php web application that asks the user for all fields' values
I have created a form to email that uses this script: <?php foreach ($_POST
I have php code that puts some values into an Array as follows: $hunter=addslashes($MessageArray[1]);
I have php mysql application and i want the phone numbers be saved in
I have php script that creates a temporary watermark image for users that are

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.