Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda