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?
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.