470,614 Members | 1,458 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

How to get DIV to work like LAYER?

Hi there,

How to get DIV to work like LAYER?
How can I get the following script to work?
I am trying to get text to appear in a div tag as a result of the selection
a dropdown list.
I have indicated the problem area with //???

Please help a newbie.
Thanks.

<html><head>
<Title>Targeting Text to Layer(Div)</Title>
<script language="JavaScript">
<!--
var selectedNumber;
var myText="Choose a number:";

function changeText(selectedNumber){
//??????
//document.mylayer.write ("You chose: " + selectedNumber);
// or maybe..
//myText="You chose: " + selectedNumber;
//??????
}
//-->
</script>
</head>

<body>
<p>Testing...</p>

<script language="JavaScript">
document.write('<DIV name="mylayer" ID="mylayer">' + myText + '</div>');
</script>

<select name="myselect" onChange="changeText(myselect.value)">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

</body>
</html>

Jul 20 '05 #1
1 1210
Lee
altergothen said:

Hi there,

How to get DIV to work like LAYER?
How can I get the following script to work?
I am trying to get text to appear in a div tag as a result of the selection
a dropdown list.
I have indicated the problem area with //???


Note that the way you were accessing the value of the Select
object wouldn't work in all browsers.

<html>
<head>
<Title>Targeting Text to Layer(Div)</Title>
<script type="text/javascript">
//var selectedNumber; You don't need to declare formal parameters.
var myText="Choose a number:";
function changeText(selectedNumber){
document.getElementById("mylayer").innerHTML="You chose: "
+selectedNumber;
}
</script>
</head>

<body>
<p>Testing...</p>

<script type="text/javascript">
document.write('<DIV name="mylayer" ID="mylayer">' + myText + '</div>');
</script>

<select name="myselect" onChange="changeText(options[selectedIndex].value)">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>

</body>
</html>

Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by digilab | last post: by
9 posts views Thread by kernelxu | last post: by
2 posts views Thread by shan chennai | last post: by
2 posts views Thread by dkode | last post: by
1 post views Thread by rbg | last post: by
16 posts views Thread by MS newsgroup | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.