Jump to content
Killersites Forums

Fill textarea from select box (nightmare!)


Recommended Posts

I have a form which displays users notes that they have saved. I want a textarea to display the main note text when they select the title from a select box.

 

I am trying to insert a value into a textarea depending on the option chosen from a select box. This i am obviously trying to do in Javascript.

 

This ISN'T trying to put the same text into the textarea that is in the select box (this i can do easily).

 

I have brought values from a MySQL database and stored the titles in a select box, and the main text (that i want in the text area) in hidden input variables.

 

I have tried to 'id' both the titles and the main text that corresponds to them in the same way, thinking that i can get to the main text id by saying 'if title id == main text id set textarea value to main text value', but i cant work out how to do it!

 

this may not be very clear. here is my html/php:

 

<?php

   session_set_cookie_params(30*60,"/");
   session_start();
   include 'database.php';

   $id = $_SESSION['id'];
   $queryNotes = "SELECT title,note FROM notes WHERE member_id = $id";
   $result = mysql_query($queryNotes);
   $result1 = mysql_query($queryNotes);
   $rows = mysql_num_rows($result);

?>


Note:



           <?php
               for($i=0;$i<$rows;$i++){
                   $array = mysql_fetch_array($result1);
                   $note = $array['note'];
                   echo '';
               }
           ?>




Choose a note:

               <?php
                   for($j=0;$j<$rows;$j++){
                       $array = mysql_fetch_array($result);
                       echo ''.$array['title'].'';
                   }
               ?>


 

if any one can offer a way of doing this it would end my headache! javascript is a pain in the arse but looks like im stuck with it as a means of client side scripting.

Link to post
Share on other sites
  • 2 weeks later...

Hi,

 

when you're writing out the using PHP try:

 


               <?php
                   for($j=0;$j<$rows;$j++){
                       $array = mysql_fetch_array($result);
                       echo ''.$array['title'].'';
                   }
               ?>

(Notice the extra "value='noteX'" parameter on the )

 

now you can put on the an onChange event to fire a function:

 


 

This will enable us to fire a function called fillTextArea() whenever the Select box's selected option changes. So therefore you might wanna add an initial blank option, before the PHP Loop.

 

You fillTextArea() function will look something like this:

 


 

Above code is not tested so if it doesn't work then Sorry :P

 

Good luck.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...