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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

changing text in div 2

Status
Not open for further replies.

TheConeHead

Programmer
Aug 14, 2002
2,106
US
How do I change the text in a div?

[conehead]
 
hmmm does not seem to work - here's what i have
Code:
<head>
function showDetail(trigger) {
	document.getElementById('sevDetail').innerHtml = 'something or other';
}
</head>

<body>
<select name="severity" onchange="showDetail(this.value);">
<option value="">None Selected
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<div id="sevDetail"></div>
</body>

[conehead]
 
sorry cone, I'm a moron.

two things: cAsE (my fault) and try not to use .value directly with a select box.

Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<script type="text/javascript"><!--

function showDetail(trigger) {
    document.getElementById('sevDetail').innerHTML = trigger;
}

function getSelVal(sel) {
    return sel.options[sel.selectedIndex].value;
}

//--></script>
</head>

<body>
<select name="severity" onchange="showDetail(getSelVal(this));">
<option value="">None Selected
<option value="1">1
<option value="2">2
<option value="3">3
</select>
<div id="sevDetail"></div>
</body>
</html>

*cLFlaVA
----------------------------
[tt]your mom goes to college[/tt]
[URL unfurl="true"]http://www.coryarthus.com/[/url]
[banghead]
 
...try not to use .value directly with a select box
I don't understand why... I've never experienced any problems doing this (and you are passing 'this' which is a superset of 'this.value'). Just curious, that's all.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
I was at the local windows test suite and decided to run some tests to see what browsers wouldn't function with passing this.value in the onchange for a select...

These all passed with Windows 2000 Pro:
Firefox1.07, Mozilla 1.7, Netscape 7.0, 7.2, 8.03, Opera 6.06, 7.54, 8.5, Internet Explorer 5.01, 5.5 and 6.0

I know these would pass with MacOSX:
Safari 1.x, 2.x, Internet Explorer 5.23, Netscape 7.2X, Firefox 1.07

I can't imagine any browsers in current use that would cause a problem with passing 'this' vs 'this.value' in an onchange.

Maybe it's one of those urban myths that someone started way back when.

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Just to wind up the thread for anyone reading in the future, Netscape 4.73 on MacOS9 fails when attempting to pass this.value in the onchange of a select element.

It works on IE4+, Netscape 6+, Opera 6+ and all mainstream browsers released since on both MacOS and Windows... so shouldn't be a problem for modern-day developers but could be important for someone developing a very specific browser solution (in which case you have my deepest sympathies).

The jury is still out on whether cLFlaVA is insane however [smile]

Cheers,
Jeff

[tt]Jeff's Page [/tt][tt]@[/tt][tt] Code Couch
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top