473,390 Members | 1,159 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

open source javascript project - trouble with document.getElementById

This PHP function prints out a bunch of Javascript (as you can see).
This is all part of the open source weblog software of PDS
(www.publicdomainsoftware.org). We had this javascript stuff working,
but it only worked for IE. You can see a working version here:

http://www.publicpen.com/designer/mcControlPanel.php
username: designer
password: designer123

However, I've tried to rewrite this so it would work in all browsers,
and now it is broken and working in none. I don't know much about
Javascript, but if any of the gurus here would like to donate some
time to an open source project, we could use the help. Can you tell me
what here is generating an error?



function elementsAdminShowFormattingButtons($id=false) {
// 05-04-04 - we want to print out some Javascript and some buttons.
// 06-10-04 - I've modified the functions so, hopefully, they will
work with
// more than just the InternetExplorer browser. I'm new to
Javascript, so
// it's a gamble.

$controllerForAll = & getController();
$config = getConfig();
$path = $config["imagesFolder"];

echo "
<script language=\"javascript\">
function insertAtCursor(myField) {
var imageName;
var path;
var myValue;
var status;
var myField;

myField = document.getElementById['inputId3'];
imageName = document.getElementById['imagesToInsert'].value;

path = '$path';
myValue = path+imageName;

status = myValue + ' - ' + myField;
window.status= status;

//IE support
if (document.selection) {
myField.focus();
sel = document.selection.createRange();
sel.text = myValue;
} else if (myField.selectionStart || myField.selectionStart ==
'0') {
//MOZILLA/NETSCAPE support
var startPos = myField.selectionStart;
var endPos = myField.selectionEnd;
myField.value = myField.value.substring(0, startPos) + myValue +
myField.value.substring(endPos, myField.value.length);
} else {
myField.value += myValue;
}
}

function wrapSelectionBold (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<b>' + range.text + '<\/b>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<b>' + previousText +
'<\/b>';
alert('We did not find any selected text (only possible in some
browsers). We made all the text bold.');
}
}
function wrapSelectionItalic (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<i>' + range.text + '<\/i>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<i>' + previousText +
'<\/i>';
alert('We did not find any selected text (only possible in some
browsers). We made all the text italic');
}
}
function wrapSelectionBlockQuote (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<blockquote>' + range.text + '<\/blockquote>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<blockquote>' +
previousText + '<\/blockquote>';
alert('We did not find any selected text (only possible in some
browsers). We wrapped all the text in a block quote');
}
}
function wrapSelectionBigHeadline (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<h1>' + range.text + '<\/h1>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<h1>' + previousText +
'<\/h1>';
alert('We did not find any selected text (only possible in some
browsers). We wrapped all the text in a big headline');
}
}
function wrapSelectionSmallHeadline (element) {
var range = document.selection.createRange();
if (range.parentElement() == element) {
range.text = '<h4>' + range.text + '<\/h4>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = '<h4>' + previousText +
'<\/h4>';
alert('We did not find any selected text (only possible in some
browsers). We wrapped all the text in a small headline');
}
}
function wrapSelectionAllowFileLists (element) {
var range = document.selection.createRange();
var address;
// 06-10-04 - this next bit is to avoid tripping the PHP parser.
Potential PHP bug.
address = '<';
address += '?php showFileInfoLists(); ?';
address += '>';
if (range.parentElement() == element) {
range.text = range.text + address;
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = range.text + address;
alert('We did not find any selected text (only possible in some
browsers). We added the special code to the end of the text.');
}
}
function wrapSelectionAllowImageLists (element) {
var range = document.selection.createRange();
var address;
// 06-10-04 - this next bit is to avoid tripping the PHP parser.
Potential PHP bug.
address = '<';
address += '?php showImageInfoLists(); ?';
address += '>';
if (range.parentElement() == element) {
range.text = range.text + address;
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = range.text + address;
alert('We did not find any selected text (only possible in some
browsers). We added the special code to the end of the text.');
}
}
function wrapSelectionMakeALink (element) {
var range = document.selection.createRange();
address = prompt('What address?', '');
address = '<a href=\\\"' + address + '\\\">';
if (range.parentElement() == element) {
range.text = address + range.text + '<\/a>';
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = address + 'See the
page<\/a>' + previousText;
alert('We did not find any selected text (only possible in some
browsers). We added the link to the beginning of the text.');
}
}
function wrapSelectionInsertImage (element) {
var range = document.selection.createRange();
address = prompt('Add address for image. If the image is on your
site, look in Image Info.', '');
address = '<img src=\\\"' + address + '\\\">';
if (range.parentElement() == element) {
range.text = address + range.text;
} else {
var previousText;
previousText = document.getElementById[element].value;
document.getElementById[element].value = address + previousText;
alert('We did not find any selected text (only possible in some
browsers). We added the image to the beginning of the text');
}
}
</script>
";

echo "<input type=\"button\" value=\"bold\"
onclick=\"wrapSelectionBold(this.form.inputId".$id .")\" /> \n";
echo "<input type=\"button\" value=\"italic\"
onclick=\"wrapSelectionItalic(this.form.inputId".$ id.")\" /> \n";
echo "<input type=\"button\" value=\"block indent\"
onclick=\"wrapSelectionBlockQuote(this.form.inputI d".$id.")\" /> \n";
echo "<input type=\"button\" value=\"big headline\"
onclick=\"wrapSelectionBigHeadline(this.form.input Id".$id.")\" /> \n";
echo "<input type=\"button\" value=\"small headline\"
onclick=\"wrapSelectionSmallHeadline(this.form.inp utId".$id.")\" />
\n";
echo "<input type=\"button\" value=\"allow image lists\"
onclick=\"wrapSelectionAllowImageLists(this.form.i nputId".$id.")\" />
\n";
echo "<input type=\"button\" value=\"allow file lists\"
onclick=\"wrapSelectionAllowFileLists(this.form.in putId".$id.")\" />
\n";
echo "<input type=\"button\" value=\"make a link\"
onclick=\"wrapSelectionMakeALink(this.form.inputId ".$id.")\" /> \n";
flush();

$controllerForAll = & getController();
$forms = & $controllerForAll->getObject("McFormsGetImages", " in
elementsAdminEditImage01().");
$arrangementObject = & $controllerForAll->getObject("McArrangements",
" in elementsAdminEditImage01().");

$controlPanelCbId = $GLOBALS["controlPanelCbId"];
$cbId = $controlPanelCbId;
if (!$cbId) {
$cbId = $arrangementObject->getControlPanelCbId();
}

$forms->getChoicesForInput();
$forms->setChoicesIntoArray();
$field = $forms->returnCurrentValueForThisField($cbId,
"cbModifier01");
$visible = $field;
$value = $field;

$forms->setValueForCurrentField($visible, $value);
$forms->putIntoArrayForJavascriptInsert();
echo " <br>Insert an image: ";
$forms->printSelect();
}

?>
Jul 23 '05 #1
1 2678
> However, I've tried to rewrite this so it would work in all browsers,
and now it is broken and working in none. I don't know much about
Javascript, but if any of the gurus here would like to donate some
time to an open source project, we could use the help. Can you tell me
what here is generating an error?


I took a peek at it, and I did find one problem

location = document.body.scrollTop;
if (location == 0) location = document.documentElement.scrollTop;
if (location == 0) location = window.pageYOffset;
document.getElementById('scrollmenu').style.pixelT op = location;

'location' is a name of the location object. Modifiying it will
cause it to attempt to go to that location. Renaming location
to another name will cause Netscape 6 & 7 not to jump to
designer/0 all the time. The rest looks good to me, but I haven't
been able to test it much yet. What goes wrong in IE, cause thats
working for me too.

good luck,
Vincent

Jul 23 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

12
by: Christoph Bergmann | last post by:
Hi... We want to write an open source web based TEXT editor and would be happy about any help ;-) Please notice: We do NOT want to write a web based WEB editor, where you can edit a web...
1
by: Oliver Hoehle | last post by:
Hello! This ist the source-code for an editable combobox implemented with HTML,CSS and Javascript. I have tested it with IE and Mozilla. But I don't know, if it will work in other browsers...
3
by: unurban | last post by:
I have a javascript menu based off of unordered lists that only shows the subnav links when you click on the main nav links. is there a way to keep any subnav items open after you click on a link...
3
by: Aaron | last post by:
I am having a little difficulty with a relatively simple task. I have a parent webform. I have a javascript attribute added to a button to open a new window when clicked. The user fills in a...
1
by: Angelos | last post by:
Hello there, I am very new to Javascript and before I explain what I want I'll tell you in a few words that I am trying to make a button on a WYSIWYG text editor (RichArea) that previews on a...
18
by: len.hartley | last post by:
Hi, I am trying to pop-up a window when the user clicks on an image. The problem is that when the user clicks on the image and the window pops up OK, but the window underneath also proceeds to...
5
by: rocknbil | last post by:
Hello everyone! I'm new here but have been programming for the web in various languages for 15 years or so. I'm certainly no "expert" but can keep myself out of trouble (or in it?) most of the time....
6
by: =?Utf-8?B?U2FtZWVrc2hh?= | last post by:
Hi, I want to write a simple .net program to open a URL, fill in fields, and click on a button to submit it using .net 1.1 framework. Can someone help in suggesting the libraries I should use?...
3
omerbutt
by: omerbutt | last post by:
sir i am making an inventory application with the help of ajax,html,dhtml,javascript php and mysql i have been working with AJAX and ASP CLASSIC ,but now i have switched to php the problem i am...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.