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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T06:18:02+00:00 2026-05-13T06:18:02+00:00

I want to pass JavaScript variables to PHP using a hidden input in a

  • 0

I want to pass JavaScript variables to PHP using a hidden input in a form.

But I can’t get the value of $_POST['hidden1'] into $salarieid. Is there something wrong?

Here is the code:

<script type="text/javascript">
    // View what the user has chosen
    function func_load3(name) {
        var oForm = document.forms["myform"];
        var oSelectBox = oForm.select3;
        var iChoice = oSelectBox.selectedIndex;
        //alert("You have chosen: " + oSelectBox.options[iChoice].text);
        //document.write(oSelectBox.options[iChoice].text);
        var sa = oSelectBox.options[iChoice].text;
        document.getElementById("hidden1").value = sa;
    }
</script>

<form name="myform" action="<?php echo $_SERVER['$PHP_SELF']; ?>" method="POST">
    <input type="hidden" name="hidden1" id="hidden1" />
</form>

<?php
   $salarieid = $_POST['hidden1'];
   $query = "select * from salarie where salarieid = ".$salarieid;
   echo $query;
   $result = mysql_query($query);
?>

<table>
   Code for displaying the query result.
</table>
  • 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-05-13T06:18:02+00:00Added an answer on May 13, 2026 at 6:18 am

    You cannot pass variable values from the current page JavaScript code to the current page PHP code… PHP code runs at the server side, and it doesn’t know anything about what is going on on the client side.

    You need to pass variables to PHP code from the HTML form using another mechanism, such as submitting the form using the GET or POST methods.

    <DOCTYPE html>
    <html>
      <head>
        <title>My Test Form</title>
      </head>
    
      <body>
        <form method="POST">
          <p>Please, choose the salary id to proceed result:</p>
          <p>
            <label for="salarieids">SalarieID:</label>
            <?php
              $query = "SELECT * FROM salarie";
              $result = mysql_query($query);
              if ($result) :
            ?>
            <select id="salarieids" name="salarieid">
              <?php
                while ($row = mysql_fetch_assoc($result)) {
                  echo '<option value="', $row['salaried'], '">', $row['salaried'], '</option>'; //between <option></option> tags you can output something more human-friendly (like $row['name'], if table "salaried" have one)
                }
              ?>
            </select>
            <?php endif ?>
          </p>
          <p>
            <input type="submit" value="Sumbit my choice"/>
          </p>
        </form>
    
        <?php if isset($_POST['salaried']) : ?>
          <?php
            $query = "SELECT * FROM salarie WHERE salarieid = " . $_POST['salarieid'];
            $result = mysql_query($query);
            if ($result) :
          ?>
            <table>
              <?php
                while ($row = mysql_fetch_assoc($result)) {
                  echo '<tr>';
                  echo '<td>', $row['salaried'], '</td><td>', $row['bla-bla-bla'], '</td>' ...; // and others
                  echo '</tr>';
                }
              ?>
            </table>
          <?php endif?>
        <?php endif ?>
      </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 311k
  • Answers 311k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Here's what you are looking for: $('select > option')[0].selected =… May 13, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer dirname($path) And this is the documentation. May 13, 2026 at 10:22 pm
  • Editorial Team
    Editorial Team added an answer Don't convert your input string to ASCII if your input… May 13, 2026 at 10:22 pm

Related Questions

I'm using an MVC setup and I'm trying to inject javascript into my views
I got two projects running, both written in PHP. Now I want to merge
Can someone show me a simple way I can test if someone's cookies are
I have an multi-dimensional array that I want to send to a PHP script
I'm developing a facebook app right now all by my lonesome. I'm attempting to

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.