Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change text on page when different select box options are selected

Status
Not open for further replies.

spastica

Programmer
Sep 27, 2002
72
GB
Hello,

i want to change the text (within html - not in a textbox) on part of a page depending on which options are selected in a select box. (it is contact information, and changes depending on the region selected)

right now, i can get it to work in a textbox, but i want it to show up on the actual page, not inside a textbox. when i try document.write, instead of writing out the line of text where i want it (within the html), it takes away all elements on the page, and writes the plain text on a white page.

any suggestions on how to do this? i am totally stumped.
 
Substitute this line for the document.write you were using:
document.getElementById('changing_div').innerText="";

and make sure that the div is named correctly:

<div id=&quot;changing_div&quot;></div>

Rick -----------------------------------------------------------
RISTMO Designs
Arab Church
 
If you read recent posts by xutopia you will see that &quot;innerText&quot; is an &quot;IE only&quot; solution where as &quot;innerHTML&quot; is DOM standard and is supported by several newer browsers inclusive of IE.

-pete
 
wow, thanks so much, i really appreciate it! :) :) it works like a charm in IE and Netscape - but doesn't work at all in Opera...am i doing something wrong? here's my code:


<script type=&quot;text/javascript&quot;>
function put()
{
option=document.forms[0].dropdown.options[document.forms[0].dropdown.selectedIndex].value
txt=option
document.getElementById('changing_div').innerHTML=txt;
}
</script>


Please select your region:<br />
<form>
<select name=&quot;dropdown&quot; onChange=&quot;put()&quot;>
<option value=&quot;choose region&quot;>Choose your region
<option value=&quot;contact1<br /><br />phone number&quot;>Central
<option value=&quot;contact 2<br /><br />test&quot;>West
<option value=&quot;contact 3<br /><br />test&quot;>SouthWest
</select>
The contact information for your region is:<br /><br />
<div id=&quot;changing_div&quot;></div>
</form>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top