Richard Cornford wrote:
...... tips elided
</script>
</head>
<body>
<form action="formecho.cgi" method="POST">
<a href="javascript:;" onmouseup="dw0()">dw0</a>
<a href="javascript:;" onmouseup="dw1()">dw1</a>
<snip>
Using "javascript:" in a HREF is a known causer of problems on various
browsers (and particularly little-tested browsers on unusual OSs, which
Mac IE is). And that particular formulation - javascirpt:; - is
demonstrated to produce a (usually internally suppressed) syntax error
on Windows IE (at least it can be demonstrated on IE <= 5.0).
Basically, in cross-browser scripting terms, once a javascript HREF has
been acted upon all bets on what the browser will subsequently
support/do are off.
It might be that Mac IE 5 just will not recognise dynamically added
checkboxes, but nothing is proven one way or another until the
javascirpt: HREFs are gone. Try triggering the action form <input
type="button"> elements instead (or, at minimum, adding onclick="return
false;" event handlers to the links to cancel the navigation and prevent
the HREFs being acted upon).
Richard.
I tried this instead
<div style="color: blue" onmouseup="dw0()">dw0</div>
once again this creates the checkbox in the browser window at
the right place, but the form doesn't contain any extra elements.
I can only assume that I need to do something extra. I added an id
on the checkbox and can tell that an object is being created.
the overall script is now
<html>
<head>
<script type="text/javascript">
var getElementWithId=
document.getElementById
?function(id){return document.getElementById(id);}
:document.all
?function(id){return document.all[id];}
:function(id){return null;};
function DynWrite(id, S){
var testH, newH, inH, testID;
var funcBody = "return false;"
var el = getElementWithId(id);
if((el)&&(typeof el.innerHTML == 'string')){
testID = "tSt";
while(getElementWithId(testID)){
testID += testID;
}
inH = el.innerHTML;
newH = inH+"<sTrOnG Id='"+testID+"' >test<\/StRoNg >";
el.innerHTML = newH;
testH = el.innerHTML;
if((testH != newH)&&
(testH != inH)&&
(getElementWithId(testID))){
funcBody = "getElementWithId(id).innerHTML=S;return true";
}
}
DynWrite = new Function("id", "S", funcBody);
return DynWrite(id, S);
}
</script>
<script type="text/javascript">
function dw0(){
return DynWrite('placeHolder','<input type="checkbox" name="bingo"
id="bingo">');
}
function dw1(){
return DynWrite('anID','new<code>HTML</code>');
}
function testMyForm(t){
var f=t.form, i, s='';
for(i=0;i<f.elements.length;i++){
s += 'element['+i+'].name='+f.elements[i].name+'\n';
}
s += 'Elements\nbingo='+getElementWithId('bingo')+'\n';
alert('Form\n'+s);
}
</script>
</head>
<body>
<form action="formecho.cgi" method="POST">
<div style="color: blue" onmouseup="dw0()">dw0</div>
<div style="color: blue" onmouseup="dw1()">dw1</div>
<div id="placeHolder">old</div>
<div ID="anID">old <code>HTML</code></div>
<input type=button name="test" value="testMyForm" onclick="testMyForm(this)">
<input type=submit name="submit" value="Submit">
</form>
</body>
</html>
--
Robin Becker