Jump to content

Including a textfile in a select drop-down menu?


extrovertive

Recommended Posts

I have a drop-down select menu.


Options are:
1
2

and then a textarea box.

If a user pull-down and select 2 from the drop-down select menu, then the textarea value will include a textfile.

Example:
[code]
<p>
<select name="messagetype">
<option value="1">1</option>
<option value="2">2</option>
</select>
</p>

<textarea name="message" rows="5" cols=30">

</textarea>
[/code]

Now if, I select 2 from the drop-down menu, the textarea will be like this:

<textarea name="message" rows="5" cols=30">
<?php include("mytext.txt");?>
</textarea>

I not a Javascript person, so can anyone help me with this?
Link to comment
Share on other sites

while begining assign the the includes of the mytext.txt files in a js var.

In your php code do something like
[code=php:0]

<?php

echo '<script language="javascript"> var mytxt1 = new String("' . include("mytext.txt") . '") ;var mytxt2 = new String("' . include("mytext2.txt") . '") ; </script>

?>
[/code]

then in your page do something like

[code]
<p>
<select name="messagetype" onChange=" message.value = ( this.value == 1 ? mytxt1 : mytxt2 ); ">
<option value="1">1</option>
<option value="2">2</option>
</select>
</p>

<textarea name="message" id="message" rows="5" cols=30">

</textarea>
[/code]

This should work but I'm certain that you have to change that include("mytext.txt") thing in the echoing. I'm not sure if it will work. But above that it should be ok
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.