Soldato
- Joined
- 24 Nov 2002
- Posts
- 16,378
- Location
- 38.744281°N 104.846806°W
Is there any obvious reason I've overlooked as to why this won't work in mozilla/opera but fine in IE:
I know it's to do with "document.getElementById('field_' + field).value"
Similarly, the following doesn't work in mozilla/opera - and I think it's to do with .value:
Code:
function updateMe(field){
if(document.getElementById('field_' + field).value == ''){
document.getElementById(field).innerHTML = field
document.getElementById('field_' + field).value = field
}else{
document.getElementById(field).innerHTML = document.getElementById('field_' + field).value
}
}
I know it's to do with "document.getElementById('field_' + field).value"
Similarly, the following doesn't work in mozilla/opera - and I think it's to do with .value:
Code:
function textSelect(field, type){
var textarea = document.getElementById(field);
// code for IE
if (navigator.appName=="Microsoft Internet Explorer"){
textarea.focus();
var sel = document.selection.createRange();
if(type == 'bold'){
sel.text = '<b>' + sel.text + '</b>';
}else if(type == 'italic'){
sel.text = '<em>' + sel.text + '</em>';
}else if(type == 'underline'){
sel.text = '<u>' + sel.text + '</u>';
}else if(type == 'link'){
var title = prompt("Link title",sel.text);
var url = prompt("Link URL","http://");
sel.text = '<a href="' + url + '">' + title + '</a>';
}
}else{
// code for Mozilla
var len = textarea.value.length;
var start = textarea.selectionStart;
var end = textarea.selectionEnd;
var sel = textarea.value.substring(start, end);
if(type == 'bold'){
var replace = '<b>' + sel + '</b>';
}else if(type == 'italic'){
var replace = '<em>' + sel + '</em>';
}else if(type == 'underline'){
var replace = '<u>' + sel + '</u>';
}else if(type == 'link'){
var title = prompt("Link title",sel);
var url = prompt("Link URL","http://");
var replace = '<a href="' + url + '">' + title + '</a>';
}
textarea.value = textarea.value.substring(0,start) + replace + textarea.value.substring(end,len);
}
}
Last edited: