×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Jobs

Placing a selected value inside input box and accessing it
3

Placing a selected value inside input box and accessing it

Placing a selected value inside input box and accessing it

(OP)
Hi everyone,
I'm trying to create a "from - to" selection area where the user selects his "from" number to "to" number.
The numbe choise is derived from a mysql table "hourshifts" and a column named "counter" .
This is my code:

CODE

<?php // select_list_from_query1.php
require_once 'myInitial.php';
require_once 'myLogin.php';
MYSQLI_SET_CHARSET($myConnection,'UTF8');
?>
<!DOCTYPE html>
<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <title>select_list_from_query1</title>
    <link rel="stylesheet" href="css/table2.css">
  </head>
<body>
  <table>
    <td>
      <form method = "post" action = "first_form.php">
        <input type="list" class = "extraction"
          required aria-required="true" placeholder="from"/>
          <?php
            $myQue = "select counter from hourshifts";
            $myResult = $myConnection->query($myQue);
            if (!$myResult) die ("Database access failed: " . $myConnection->error);
            $numOfRows = $myResult->num_rows;
          ?>
          <select name='counters'>
          <?php
            for ($j = 0 ; $j < $numOfRows ; $j++)
            {
              $myResult->data_seek($j);
              $row=$myResult->fetch_array(MYSQLI_ASSOC);
          ?>
            <option><?php echo $row['counter'] ?></option>
          <?php
            }
          ?>
          <input type="list" class = "extraction"
            required aria-required="true" placeholder="to"/>
            <?php
               $myQue = "select counter from hourshifts";
               $myResult = $myConnection->query($myQue);
               if (!$myResult) die ("Database access failed: " . $myConnection->error);
               $numOfRows = $myResult->num_rows;
            ?>
            <select name='counters'>
            <?php
              for ($j = 0 ; $j < $numOfRows ; $j++)
              {
                $myResult->data_seek($j);
                $row=$myResult->fetch_array(MYSQLI_ASSOC);
              ?>
              <option><?php echo $row['counter'] ?></option>";
              <?php
             }
          ?>
      </form>
    </td>
</table>
</body>
</html> 
This is what the display looks like after yhe user selected the "from" number.


The number selected, 19, is placed outside the input box.
Can anyone help me with placing the selected numbers inside their input boxes?
My second question is: How can I access the number selected with php? It is shown on the screen whereby en "echo" command
but is it stored inside a variable or an array such as $_post?
Thanks

RE: Placing a selected value inside input box and accessing it

Couple of things:
1. Close select tags - you are missing </select> to wrap your <option>...</option>
2. Why do you need <input ...> if you already have two <select ...> drop boxes?

It is best to ask your questions individually so that proper attention is given and you benefit from getting the help you seek. I do not think anyone here will suggest you ask fewer questions .... glasses

As far as your 2nd question, accessing the selected value off a <select ...> drop box is no different than the value entered in an <input ....> field. So, $_GET, $_REQUEST, and $_POST will be standard. Of course, this is dependent on how you process the form and if using AJAX calls GET/POST ...

Finally, look at what @feherke points out, make sure your type="" is valid so that you can get expected behavior. Some frameworks attempt to change these standards as if to say they are ahead of the game and if you are using a framework that suggests you set this property in such way, you may want to include this piece of information in future questions so that we learn alone side you.

--
SouthBeach
http://www.fp2php.com
The good thing about not knowing is the opportunity to learn - Yours truly, 2008.

RE: Placing a selected value inside input box and accessing it

Inputs and selects are 2 different types of elements. They do not relate to each other nor would they exist inside one another.

Since you have a select element, where you select the number, why do you need it to be placed inside another form element (the input box)?

Also as has been pointed out, "list" is not a valid type for an input. Valid types are: text, checkbox, radio and button. Any other value you place there will default to text. So essentially all you are creating is a textbox.


Beyond that, accessing a select item in PHP is the same as any other form element with a value. You access it from the $_POST or $_GET superglobals once the form has been submitted, using its name. In the case of your selects: $_POST['counters'].

Now an interesting thing will happen, since both of your selects are named the same, the second one will overwrite the value of the first when the form is submitted. So you will only ever get 1 value.

Name your selects differently to get both values.





----------------------------------
Phil AKA Vacunita
----------------------------------
OS-ception: Running Linux on a Virtual Machine in Windows which itself is running in a Virtual Machine on Mac OSx.

Web & Tech

RE: Placing a selected value inside input box and accessing it

(OP)
Thanks southbeach,
I'm very sorry about the disorder.
1. I didn't put closing tags to select because I didn't know how to handle it.
2. I mixed up input types such as "checkbox", "radio" etc.. I didn'y know select was different.
"list", I think I found through google search and I might have not fully understood it so I illused it.
Thanks for your assistence. I thing I better handle "select" now.

RE: Placing a selected value inside input box and accessing it

(OP)
Thanks a lot Vacunita.
Thing are much more clear now and I should thank you all for the assistence.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close