Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

222
Views
Need to access hidden field values across several pages

I need to share some Global Variables across several HTML and PHP pages. I created a small HTML file that contains a series of hidden fields that contains several lines like this:

<input type="hidden" name="pageColor" id="pageColor" value="#DCE6F1"> &nbsp; 
<input type="hidden" name="bgColor"   id="bgColor"   value="#004C00"> &nbsp; 
<input type="hidden" name="LamCost"   id="LamCost"   value="3"> &nbsp; 

The form has about 7 of these fields. For each page that needs this data, I have created an INCLUDE statement that adds the form with the hidden fields near the top of the page:

<!---------[ Script required for includes put in <head>]------------------->
<script language="JavaScript">
  function processUser()
  {
    var parameters = location.search.substring(1).split("&");

    var temp = parameters[0].split("=");
    l = unescape(temp[1]);
    temp = parameters[1].split("=");
    p = unescape(temp[1]);
    document.getElementById("log").innerHTML = l;
    document.getElementById("pass").innerHTML = p;
  }
</script>
<!----------[ End of INLUDE script ]--------------->

<!-------[Near the topy of the <BODY> add this INCLUDE ]--------------->
<!--[ Import common VBLS ]---------------->
<div id="cData-placeholder"></div>

<script>
    $(function(){
      $("#cData-placeholder").load("includes/commonData.html");
    });
</script>
<!--[ end of Common VBLS ]--------------------------->

The problem I am having is NO success at using those variables in other parts of the page. I have tried javascript & PHP:

var savLamCost = "<?php $_REQUEST['LamCost'] ?>";
var savLamCost = document.getElementById("LamCost").value;

...and in PHP:
$savLamCost = $_REQUEST["LamCost"];
$savLamCost = $_POST["LamCost"] ;

I would appreciate any suggestions of better ways to share global variables across several pages (the goal is to make future changes easy, by editing just one location to update all variables).

My thanks in advance!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Define/create a global.js:

var global_pageColor = "#DCE6F1";
var global_bgColor = "#004C00";
var global_bgColor = "3";

Call it in your other files, always being the first linked JS file in the html's head:

<html>
    <head>
        <!-- global.js -->
        <script src="<path>/global.js" type="text/javascript"></script>
    </head>
    <body>
    </body>
</html>
about 4 years ago · Juan Pablo Isaza Report

0

Because the "include" statements failed &/or worked inconsistently, instead of a .js file, I am storing all shared data in a mySQL DB. Each page that needs one or more of those variables gets them with a mySQL SELECT statement. THIS IS WORKING VERY WELL FOR ME... it may be over-kill, but it works consistently and reliably.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!