PHP: Need a double check on an error in this small code

Posted by Josh K on Stack Overflow See other posts from Stack Overflow or by Josh K
Published on 2010-05-13T14:18:10Z Indexed on 2010/05/13 14:24 UTC
Read the original article Hit count: 150

Filed under:

I have this simple Select box that is suppose to store the selected value in a hidden input, which can then be used for POST (I am doing it this way to use data from disabled drop down menus)

<body>
    <?php 
    $Z = $_POST[hdn];
    ?>
    <form id="form1" name="form1" method="post" action="test.php">
    <select name="whatever" id="whatever" onchange="document.getElementById('hdn').value = this.value">
      <option value="1">1Value</option>
      <option value="2">2Value</option>
      <option value="3">3Value</option>
      <option value="4">4Value</option>
    </select>

<input type="hidden" name ='hdn' id="hdn" />
<input type="submit" id='submit' />
<?php
echo "<p>".$Z."</p>";
?>
</form>
</body>

The echo call works for the last 3 options (2,3,4) but if I select the first one it doesnt output anything, and even if i change first one it still doesnt output anything. Can someone explain to me whats going on, I think it might be a syntax issue.

© Stack Overflow or respective owner

Related posts about php