1

the following code shows a "form" page (html) where people can select an option (read from option.txt file) sent to process_data.php option.txt file is like this:

 option1|this is the option 1
 option2|this is the option 2
 .....

Everything works fine: in process_data.php when i call $_post['mydecision'] the variable is correctly read ($item[0]). The issue is born when I want to use also $item[1] relating to the same option selected by the user. The code:

 <input type="hidden" name="mydecision2" id="mydecision2" value="<?php echo "$item[1]"; ?>">

gives always the same result: $_post['mydecision2'] = "this is the option 1" even though users select different options.

Any suggestions?

<body>
<form name="web_form" id="web_form" method="post" action="process_data.php">
<select name="mydecision">
<option selected="selected">SELECT DECISION</option>
<?php
// define file
$file = 'options.txt';
$handle = @fopen($file, 'r');
if ($handle) {
while (!feof($handle)) {
   $line = fgets($handle, 4096);
   $item = explode('|', $line);
   echo '<option value="' . $item[0] . '">' . $item[1] . '</option>' . "\n";
 }
 fclose($handle);
 }
 ?>
 </select>

 <input type="hidden" name="mydecision2" id="mydecision2" value="<?php echo "$item[1]"; ?>">
 ....

In a few words: how can i take both values chosen? I need also the $item[1] (correspondent to the chosen $item[0]) as variable $_post['mydecision2'] to be available in process_data.php

1 Answer 1

1

Your select should be like this:

<select name="mydecision[]" multiple>
Sign up to request clarification or add additional context in comments.

3 Comments

Also you need to add multiple inside select tab like this <select name="mydecision" multiple>. Read here about w3schools.com/tags/att_select_multiple.asp
you need some javascript for actualizing your hidden field)
Thanks, finally i fixed the issue! Your suggestion has been very useful.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.