Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

224
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda