Page 1 of 1

Listboxes items --> textarea

Posted: Mon Jun 06, 2005 1:15 pm
by Decoian
Hi All,

I'm having problems coding what no doubt should be a very simple thing:

I have mobile XHTML form that contains a dropdown list and a textarea, the user selects an item from the list, click an Add button and the item from the list gets added to the textarea. I have the basic stuff down and working - but my grasp of PHP is limited (this is my first go with it...) and I need to know how to:

1) Add the selected item to the textbox (each item to it's own line)
2) Then redisplay the XHMTL page showing the item added to the textbox.


Thanks for any help!

Posted: Mon Jun 06, 2005 1:26 pm
by timvw
A little snippet to get the selected items in a listbox:

http://timvw.madoka.be/programming/php/ ... ltiple.txt

$text = $_POST['text']; // get what there is already in the textarea

Now all you have to do is iterate over the item, and append the values and a "<br/>" to $text to generate a linebreak effect in html.

Finally echo "<textarea name='text'>{$text}</textarea>";

Posted: Mon Jun 06, 2005 1:47 pm
by Decoian
Tim,

Thanks! I can follow most of that :-) , however, I need to get the updated $text back into the textarea it came out of, not display it as HTML text on new/ existing screen - which is what I think the echo command does - right?

See below -
http://www.ximetrix.ca/portal.html

The intent is to use the drop down to help speed up data entry from a mobile device... so the user picks a command from the dropdown - clicks the insert button- at which point the XHTML page is somehow updated/ reloaded via PHP (unless you know another way) to show the selected command inserted in to the textarea. The user might have to select several comamnds, and add additional text to eachline hence the use of the textarea. Follow?

Can I do this in PHP - of do I need to look at coding it up in something like JAVA...

Over,

Ian



8O 8O 8O 8O

Posted: Mon Jun 06, 2005 2:16 pm
by Decoian

Posted: Mon Jun 06, 2005 5:48 pm
by shiznatix
errr thats a little hard to understand but i think what you are saying is that you want to cick on the insert button and it will add "Option A" to the text area. then the user selects "Option B" and hits insert and the textarea then displays

Option A
Option B

and so on. that what you are looking for? if so do somtin like this

Code: Select all

<select name="somthing">
<option value="1">Option A</option>
<option value="2">Option B</option>
</select>

<input type="submit" name="submit" value="insert">
<?
if ($_POST['submit'])
{
    echo '<input type="hidden" name="already_selected[]" value="'.$_POST[somthing].'">';
}

echo '<textarea name="coolba">';

if (is_array($_POST['already_selected']))
{
    foreach ($_POST['already_selected'] as $key => $value)
    {
        echo $value;
    }
}
echo $_POST['somthing'];

echo '</textarea>';
?>
Jcart | fixed parse error

Posted: Tue Jun 14, 2005 12:21 pm
by Decoian
shiznatix

Sorry for the delay - what you came up with is dead on! However - I when I tested it (as PHP file on our server)I found that when I selected an item, then hit the insert button nothing is added to the box...

Over,

Ian