By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,605 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,605 IT Pros & Developers. It's quick & easy.

How to get DIV to work like LAYER?

P: n/a
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
Share this Question
Share on Google+
1 Reply


P: n/a
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.