Hello group.
This is my first message in this group, and my first stab at
Javascript.
I am trying to tweak the code for the "FOLDOC button"
(http://foldoc.org/foldoc/tools.html) to be able to execute a DB query
over my firm's intra-net.
The source code for the IE button is as follows:
javascript:f=document.frames.length;q=(f?'':docume nt.selection.createRange().text);for(i=0;i<documen t.frames.length;i++){q=document.frames[i].document.selection.createRange().text;if(q!='')br eak;}if(q=='')void(q=prompt('search
foldoc:',''));if(q!=null){q='http://www.foldoc.org/?'+escape(q);void(f?open(q):window.location=q)}
which when reasonably indented looks like this:
javascript:
f=document.frames.length;
q=(f?'':document.selection.createRange().text);
for(i=0; i<document.frames.length; i++)
{
q=document.frames[i].document.selection.createRange().text;
if(q!='')
break;
}
if(q=='')
void(q=prompt('search foldoc:',''));
if(q!=null)
{
q='http://www.foldoc.org/?'+escape(q);
void(f?open(q):window.location=q)
}
For reasons I don't understand, IE *requires* that the entire code be
in one single line. Notwithstanding that, the FOLDOC button works
quite well.
My tweak to the FOLDOC code attempts to do this:
* In either the selected text, or the text entered in the 'Prompt'
box,
* Strip off all text EXCEPT,
* numbers of 5 or more digits.
For example, when a text such as
In v6.1.25.4 release, defects 12345, 23456, 78901 and 24211 were fixed
on 4/5/6. Docs are available at ftp://12.34.56.78/TR34251.txt
is selected (or copy-pasted), the string should be reduced to
12345,23456,78901,24211,34251
before appending it to my query URL.
My attempt is as follows (I have laid it out indented and spread out
although the IE button code has it all in one single line):
f=document.frames.length;
q=(f?'':document.selection.createRange().text);
for(i=0; i<f; i++)
{
q=document.frames[i].document.selection.createRange().text;
if(q!='')
break;
}
if(q=='')
void(q=prompt('Search for Defect ID:',''));
if(q!='' && q!=null)
{
q=q.replace(/\D+/g,'#');
q=q.replace(/\b\d{1,4}#/g,'#');
q=q.replace(/#+/g,',');
q=q.replace(/(^\,|\,$)/gm,'');
q='http://intranet.myfirm.com/query.asp?JTSNo='+escape(q);
}
else
q='http://intranet.myfirm.com';
void(f?open(q):window.location=q);
The problem is, when I click the button (for this code), NOTHING
happens.
Some observations:
* I use IE 6.0.2900 on XP SP2 (includes all current patches/security
fixes).
* I have UNCHECKED the "Disable script debugging" option as well as
CHECKED the "Display notification on every script error".
* I've tried installing Microsoft script debugger.
* The above code reduced to a single line is well within the 2083
character limit.
None of them have any effect, i.e., IE does not seem to think there is
any error. It simply just does not do anything.
The help I seek:
* Is there anything wrong with the code above? Is there any better way
to do what I have sought to do?
* Can anyone explain why nothing happens, yet another button with near
identical code works flawlessly?
* In general, how do I debug such code?
All advice/insights appreciated,
- Anand Hariharan