Forum Moderators: open
I already know how to dynamicly populate a form, but I am attempting to take it a stage further.
I have a menu which passes text, pictures or both into a textarea.
Now, I thought that there may just be a way to do the exact same thing, but by using a css overflow substituted for a textarea. What I don't get is how to declare an overflow area in javascript. Any help?
If i was declaring via a form select option to show in a text area:
<form name="thisform">
<select name="selectwhat" size="1" onChange="showtext()">
<option value="select" readonly Selected>Select from the list></option>
<option value="A" readonly>first choice</option>
<option value="B">second choice</option>
<option value="C">third choice</option>
</select>
<TEXTAREA rows=6 cols=40 wrap="physical" name="show" readonly>Select from above</textarea>
<script language="javascript">
var description=new Array()
description[0]="Select"
description[1]="first display
description[2]="Next display."
description[3]="another display"
function showtext(){
document.thisform.selectwhat.show.value=description[document.thisform.selectwhat.select.selectedIndex];
}
</SCRIPT>
</FORM>
>>>>>>
(?)To do the same in an overflow is :
<DIV ID="menu">
<UL>
<LI><A HREF="javascript:void(0)" onclick="show()"
onfocus="this.blur()" Home</A></LI>
</UL></DIV>
<DIV class=overflowobject ID="showit">
</div>
<script language="javascript">
function show()
{document.getElementById("showit").style.overflow="description1";
}
</SCRIPT>
This, if I am getting you correctly passes the text "description1" into the overflow object declared in divid "showit"? Or have I completely misinterpreted this, as it does not do anything at all.
If you wish to write content into a document element other than a form element, you will probably be best served using the innerHTML method. Otherwise, if you want the value of the select to be appended to the text in a textarea, you can use the technique of making the textarea's value += the value of the select.
Make sense?
Thanks for your help.
Dumping your content into this DIV is easy. First code the DIV in your page:
<div id="preview">
<p>My default paragraph of text.</p>
</div>
Next, in your javascript, create a variable for each menu option containing the text and material you want dumped in the DIV:
var menuItemOne = "<p>This is the text that goes with menu option one. Ain't it grand?<\/p?"
Don't forget to add the html tags necessary for proper rendering of the elements.
Last, in your javascript, set the DIV's innerHTML property equal to the right variable:
document.getElementById('preview').innerHTML = menuItemOne.
Et voila! You can even use CSS position:absolute (or float for IE5+ or NN6+) to put that box anywhere on the page you want.
Peace.