PDA

View Full Version : Need help w/ pop up box in Netscape


Chicken
01-21-2004, 09:56 PM
I am developing a message board, and I have markup buttons (similar to the ones found on this board when you are posting) that users can press to pop up a box to accept input.

For example, check out this link:

One of my forums (http://www.tigerdroppings.com/rant/Message.asp?action=create&Post=New&BoardID=2&View=2)

These buttons work fine in Internet Explorer, but do not work for Netscape or the browser used by Macs.

This is the logic that I am now using for the "url" button:

<INPUT TYPE="button" VALUE="link" onClick="addSingleURL('Enter a valid URL:', 'Enter your link title:', 'http://'); frmPost.txtpost.focus(); return true;" id=button1 name=button1 title="Add Link">


And this is the logic for the javascript function:

function addSingleURL(prompt1, prompt2, defaultText)
{

// If something is selected then just encase it in the tags
var selection = document.selection.createRange().text;
if(selection != "")
{
document.frmPost.txtpost.focus();
var newSelection = document.selection.createRange();
var linktitle = self.prompt(prompt2, "LINK");
if((linktitle == "") || (linktitle == null))
linktitle = "LINK";
newSelection.text
= ''+linktitle+'';
return;
}

// Nothing's selected so prompt for something to put between the tags
var newTag = self.prompt(prompt1, defaultText);
if((newTag == null) || (newTag == defaultText))
return;
var linktitle2 = self.prompt(prompt2, 'LINK');
if((linktitle2 == "") || (linktitle2 == null))
linktitle2 = "LINK";
newTag=''+linktitle2+'';

document.forms.frmPost.txtpost.value += newTag;

}




frmPost is the name of the form that is defined on the page.

I need to know what I have wrong that is causing this not to work in Netscape and Safari(?). This has been driving me crazy, so I stumbled upon this forum seeking help.

Thanks in advance for your help.

Roy Sinclair
01-21-2004, 10:23 PM
Try "onclick" instead of "onClick".

Chicken
01-21-2004, 10:33 PM
That did not fix it.

Thanks, though.

glenngv
01-22-2004, 02:54 AM
createRange() is an IE thing only. And the form reference in the onclick handler is not complete.

onClick="addSingleURL(...);document.frmPost.txtpost.focus();..."

Check the Javascript console to see specific errors.

Chicken
01-22-2004, 10:29 PM
Do you know of some code that will handle both browser types?

Thanks in advance.

Chicken
01-27-2004, 10:17 PM
If I offered money for the solution, would I get a better response?

This is not a sarcastic question...I just really want to get this fixed...

Thanks in advance.

SlySecretSpy
01-27-2004, 10:31 PM
if (document.getSelection) {
selection = document.getSelection;
} else if (document.selection) {
selection = document.selection
}

BTW, this is from a google search for "netscape document.selection.createRange().text;"

Google is your friend.

liorean
01-27-2004, 10:43 PM
Hmm, I think this is one of the cases where there are very few resources on the web and very few that have used the mozilla equivalent. I'll throw in a few links that may help.

<http://www.mozilla.org/docs/dom/domref/dom_window_ref24.html#1000044>
<http://www.pbwizard.com/Articles/Moz_Range_Object_Article.htm>
<http://www.xulplanet.com/references/xpcomref/group_ClipboardandSelection.html>
<http://www.playsophy.com/edom/test/mozdom/imgbr.html>
<http://forums.devshed.com/t108661/s.html>