Listboxes items --> textarea

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Decoian
Forum Newbie
Posts: 4
Joined: Mon Jun 06, 2005 12:54 pm

Listboxes items --> textarea

Post 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!
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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>";
Decoian
Forum Newbie
Posts: 4
Joined: Mon Jun 06, 2005 12:54 pm

Post 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
Decoian
Forum Newbie
Posts: 4
Joined: Mon Jun 06, 2005 12:54 pm

Post by Decoian »

User avatar
shiznatix
DevNet Master
Posts: 2745
Joined: Tue Dec 28, 2004 5:57 pm
Location: Tallinn, Estonia
Contact:

Post 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
Decoian
Forum Newbie
Posts: 4
Joined: Mon Jun 06, 2005 12:54 pm

Post 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
Post Reply