Forum Moderators: open

Message Too Old, No Replies

onChange() not working on MAC computer

onChange, Mac

         

frencam2005

8:47 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



Can somebody please help me, I'm trying to create an application that will dynamic change the page using div tags when the user selects a specific option from a drop down list box but it will not work on a MAC. It works perfectly on a PC. Here is the basic coding I'm trying to get to work:

<SCRIPT type="text/javascript">
function newTest(myValue){
alert("Check");
document.getElementById("testDiv").innerHTML = myValue;
}
</SCRIPT>

<BODY>
<div id="testDiv">
&nbsp;
</div>

<select name="test1" onChange="newTest(this.value)">
<option value="value1" >value1</option>
<option value="value2" >value2</option>
<option value="value3" >value3</option>
<option value="value4" >value4</option>
</select>
</BODY>

I would like to have the user select a value from the list box, then call the function and update the div tag. This works perfectly on windows, and it will work on a mac if I use the onBlur() or onFocus() events but the onChange() even will not call the function for some reason. It just does nothing.

Can anybody help tell me how to get this to work on a MAC? Thanks,

Aaron French
Web Developer

SpaceFrog

8:31 am on Mar 23, 2005 (gmt 0)

10+ Year Member



on what?
MAC? is that a computer? ;-))

BlobFisk

10:49 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this :

<select name="test1" onChange="newTest(this.options[this.selectedIndex].value)">

HTH

frencam2005

4:17 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



I tried that and it didn't seem to work either. I've gone bare bones with my code and found that the problem seems to be in the form tag. If I have my select statement in the form tags it does NOT work, but if I pull it out of the form tags it does. Here is the code I'm testing with now:

<body>
<form>
<SELECT name="sport" onChange="alert(this.value)">
<OPTION SELECTED>--Choose a Sport-- </OPTION>
<OPTION value="FBall 1">Football - 1</OPTION>
<OPTION value="BBall 1">Basketball - 1</OPTION>
<OPTION value="Hockey 1">Hockey - 1</OPTION>
</SELECT>
</form>

<SELECT name="sport" onChange="alert(this.value)">
<OPTION SELECTED>--Choose a Sport-- </OPTION>
<OPTION value="FBall 2">Football - 2</OPTION>
<OPTION value="BBall 2">Basketball - 2</OPTION>
<OPTION value="Hockey 2">Hockey - 2</OPTION>
</SELECT>
</body>

Does anybody know why the onClick() event will not work when the select is embedded within the form tags? Any help would be greatly appriated, this works on PC, just not on a MAC computer.

What I am wanting to do with this is have the user select an option from the box, this the next select box will appear using div tags and populated from a database. This will happen through four selections and then the enter button will appear to submit the form and selections. It works on PC, just not on MAC.

Thanks

Aaron

SpaceFrog

4:20 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



may be mac is a bit tingy on syntax and if select is in form use the form syntax:

document.forms[0].Elements["test1").value

frencam2005

5:34 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



Thanks for the tip but that didn't seem to work either. I took the "this.value" out and just put text in the alert to display and again, it works on PC but not on MAC when I have it in a form. The OnBlur() and OnFocus() commands will show the alert on MAC but the onChange() command will not when the select is within a form tag.

This is the most rediculous thing ever. Any other ideas? Does anybody have a MAC to copy that code into a blank HTML document and see if it is working for you? I'm open to ideas. Thanks

Aaron

rocknbil

6:04 pm on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Works fine on OS X, v 5.1 MSIE. Which is going to go away soon.

Something not covered, I used this, note the doctype:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Home Page Sample</title>
<meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
</head>
<body>
<form>
<SELECT name="sport" onChange="alert(this.value)">
<OPTION value="" SELECTED>--Choose a Sport-- </OPTION>
<OPTION value="FBall 1">Football - 1</OPTION>
<OPTION value="BBall 1">Basketball - 1</OPTION>
<OPTION value="Hockey 1">Hockey - 1</OPTION>
</SELECT>
</form>
</body>
</html>

And while it's **probably** irrelevant, you might try using the value attribute for your selected:
<OPTION value="" SELECTED>--Choose a Sport-- </OPTION>

Probably means nothing, but doesn't hurt to have all your duckies in a row.

I always encounter huge problems with Mac browsers. I find myself developing a site, then sometimes having th tear the whole thing down and build it again to get it all to work on a Mac. So what you're experiencing is no surprise at all.