JAaron Anderson
asked on
HowTo use JavaScript to read in external file and assign datastream to variable for use with other functions
The jQuery.get works as expected and well documented to push the stream to target divElement.
GOAL :: Does anyone know a way to populate the open 'data-read' stream
NOT into an divElement but INTO a <$variable> for other functions to use the passed-in data ?
in other words : How can I use JavaScript to read in external file and assign the data-stream to a local session variable for use with other funtions during the Client side experience...
thanks so much
note: I cannot default to using a scripting language like PHP or ASP I need another workaround...
...
<script language="JavaScript">
//GOAL :: I want to load the contents into a variable as a sting
//jQuery.get( url, [ data ], [ success(data, textStatus, jqXHR) ], [ dataType ] )
// ref. http://api.jquery.com/jQuery.get
jQuery.get('myTextFile.log', function(data) {
//Alert the results from requesting file
alert(data);
//the following line will insert the var data (raw log) in the divElement
$('#readMyFile').html(data)
});
</script>
...
<div id="readMyFile"></script>
...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Proculopsis I copied the script as you have it and its Not working :(
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q__26822624.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var theText;
jQuery(document).ready( function () {
$.get( "test.log", getContent ); // the only thing I change is the file name making sure it reside aside this .htm document
});
function getContent( data, sstatus, response ) {
theText = response.responseText;
}
</script>
<style>
#dynamic-content { width: 640px; height: 400px; border: 1px dotted #f00; margin-left: auto; margin-right: auto; overflow: auto; background-color: beige; }
</style>
</head>
<body>
<input id="click-me" onclick="getElementById('dynamic-content').innerText=theText;" value="Click Me!" type="button" />
<div id="dynamic-content"></div>
</body>
</html>
ASKER
ok I pullled everything out of my code working JUST with this... I renamed my log file to myTextFile.log and I still get nothing in FireFox works in IE ONLY !!! agggh!
@leakim97 not working... (course I did correct closing </div> at end of sample code)
validator says theres a syntax error with ::
myString = $.ajax({"url":"myTextFile. log","asyn c":false}) .responseT ext;
@leakim97 not working... (course I did correct closing </div> at end of sample code)
validator says theres a syntax error with ::
myString = $.ajax({"url":"myTextFile.
Work for me :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script language="javascript" type="text/javascript">
var myString; // a global var to share it with all your function
$(document).ready(function () {
$("input").click(function() {
myString = $.ajax({"url":"myTextFile.log","async":false}).responseText;
showIt();
});
});
function showIt() {
$("#readMyFile").html(myString.replace(/\n/g,"<br />"));
}
</script>
</head>
<body>
<input type="button" value="click" /><br />
<div id="readMyFile"></div>
</body>
</html>
leakim971-409887.flv
ASKER
ok works now .. not sure why no matter...
... moving forward...
my log file is formatted like so '...','...','...'
it comes into the stream fine for the click event but how can I populate an array with each line break result from line 16 (above)
now I need my stream to be slit into cells of an array...
myString.split(/','/);
... moving forward...
my log file is formatted like so '...','...','...'
it comes into the stream fine for the click event but how can I populate an array with each line break result from line 16 (above)
now I need my stream to be slit into cells of an array...
myString.split(/','/);
myArray = myString.split(","); // if you don't worry about simple quote
ASKER
I need to take the "onclick event" out of the equation on your examples
I need to streamline it to populate the Array scraping the external file and return the results of the Array .. you can check the streamed value is neccessary as you step thru it...
but most importantly I cannot seem to populate the array
I can verify the stream is read by the onclick event but
I cannot verify the passing of that value into the array for use with
body onload function... thx
I need to streamline it to populate the Array scraping the external file and return the results of the Array .. you can check the streamed value is neccessary as you step thru it...
but most importantly I cannot seem to populate the array
I can verify the stream is read by the onclick event but
I cannot verify the passing of that value into the array for use with
body onload function... thx
live link please :)
ASKER
psuedo code is this :
1. onload
at client request of page read in the external value2. return and populate
populate the external string into an array(split by /,/)3. read variable
make the array available to be read by other function/methods
1 :
3:
$(document).ready(function () {
myString = $.ajax({"url":"myTextFile.log","async":false}).responseText;
2 :
var myString, myArray; // a global var to share it with all your function
3:
myArray = myString.split(",");
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script language="javascript" type="text/javascript">
var myString, myArray; // a global var to share it with all your function
$(document).ready(function () {
myString = $.ajax({"url":"myTextFile.log","async":false}).responseText;
showIt();
});
function showIt() {
myArray = myString.split(",");
alert("myArray have : " + myArray.length + " elements");
}
</script>
</head>
<body>
</body>
</html>
ASKER
postid_34898869 Proof of concept cant get to work right :
http://www.widener.edu/webdev/expertexchange/Q_26822624/postid_34898869.htm
.. but this doesnt matter to figure out...
.......................... .......... .......... .......... .......... .......... .......... .......... .......... .......... .......... ....
... this works in IE at least here in form Im working on ...
http://www.widener.edu/webdev/expertexchange/Q_26822624/index.htm
now I just need the external file values to be populated into the array WUindex[]
cannot get the logic/syntax to work for line 22
in order to function for line 3358
thanks leakim971...this makes sense right ?...
http://www.widener.edu/webdev/expertexchange/Q_26822624/postid_34898869.htm
.. but this doesnt matter to figure out...
..........................
... this works in IE at least here in form Im working on ...
http://www.widener.edu/webdev/expertexchange/Q_26822624/index.htm
now I just need the external file values to be populated into the array WUindex[]
cannot get the logic/syntax to work for line 22
in order to function for line 3358
thanks leakim971...this makes sense right ?...
ASKER
I learned my server does NOT allow .log files for some reason so I changed to reading .txt
ASKER
could it be a (this.value) prinicple of the WUindex variable ?
ASKER
could it be a (this.value) principle of the WUArray variable ? I mean ...
ASKER
maybe I need to incorporate an addeventListener() ?
ASKER
guess I cannot introduce an addEventListener because I learned its not IE supported... the read-in file script already doesnt work with firefox so I can't worry about cross compatibility must stay with IE supported DOM methods
ASKER
when I try to output to the screen
document.writeln(WUArray[1 ]); // Will output: the second record it gives me undefined...
document.writeln(WUArray[1
I tried to download your file directly with the browser : http://www.widener.edu/webdev/expertexchange/Q_26822624/myTextFile.txt
I get a 404 error (file not found)
I get a 404 error (file not found)
Here's a slightly modified version of my original post, is this the sort of thing you are looking for:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>http://www.experts-exchange.com/Programming/Languages/Scripting/AJAX/Q_26822624.html</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
var theData;
jQuery(document).ready( function () {
$.get( "http://www.widener.edu/webdev/expertexchange/Q_26822624/university.txt", getContent );
$("#click-me").click( display );
});
function getContent( data, status, response ) {
theData = response.responseText.split( /,/ );
}
function display() {
$("#dynamic-content")
.empty()
.append( "var theData = " )
.append( JSON.stringify( theData ) );
}
</script>
<style>
#dynamic-content { width: 640px; height: 400px; border: 1px dotted #f00; margin-left: auto; margin-right: auto; overflow: auto; background-color: beige; }
</style>
</head>
<body>
<input id="click-me" value="Click Me!" type="button" />
<div id="dynamic-content"></div>
</body>
</html>
ASKER
@Proculopsis thanks man but that only does a part. what I also need is Im struggling to get the value read in from the stream to also be populated in an array ... split isnt seeming to work ...
>>I tried to download your file directly with the browser :
@leakim971 surprised not getting that halted studying the code...
you could reference that file from any where http://absolute path ...
what it was is that I learned myTextFile.log cannot be used via IIS default I had to just now make it a .txt file changing the extension
thanks guys for looking into this more...
Im just struggling trying to get that array 'WUArray' 's cells populated I just have it returning 'undefined' :(
thanks again
>>I tried to download your file directly with the browser :
@leakim971 surprised not getting that halted studying the code...
you could reference that file from any where http://absolute path ...
what it was is that I learned myTextFile.log cannot be used via IIS default I had to just now make it a .txt file changing the extension
thanks guys for looking into this more...
Im just struggling trying to get that array 'WUArray' 's cells populated I just have it returning 'undefined' :(
thanks again
ASKER
@Proculopsis I know
http://www.widener.edu/webdev/expertexchange/Q_26822624/postid_34904200.htm
"shows" the results as ["cells"] but when I implement in my solution to read from the array it is again undefined...
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
(clicking the University lookup button doesnt work) not just a "display test"
can you help me figure out why I cant harness the values in the Array
I am trying to do that on line2842
like I can do if I just hardcode in cell values like in lines 87-90
var EXindex=new Array('#Exton','#test','#i nline','#h ardcoded') ;// type E to test
var DEindex=new Array('#Delaware','#test', '#inline', '#hardcode d');// type D to test
var CHindex=new Array('#Chester','#test',' #inline',' #hardcoded '); // type C to test
var HBindex=new Array('#Harrisburg','#test ','#inline ','#hardco ded');// type H to test
thanks for all your guys' help were close...
http://www.widener.edu/webdev/expertexchange/Q_26822624/postid_34904200.htm
"shows" the results as ["cells"] but when I implement in my solution to read from the array it is again undefined...
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
(clicking the University lookup button doesnt work) not just a "display test"
can you help me figure out why I cant harness the values in the Array
I am trying to do that on line2842
like I can do if I just hardcode in cell values like in lines 87-90
var EXindex=new Array('#Exton','#test','#i
var DEindex=new Array('#Delaware','#test',
var CHindex=new Array('#Chester','#test','
var HBindex=new Array('#Harrisburg','#test
thanks for all your guys' help were close...
ASKER
maybe another way to word what Im trying to do is look at line 2885 of
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
Since:
line 2895 : works CHSearchbase(document.getE lementById ("qCH"),CH index);
for line 89: var CHindex=new Array('#Chester','#test',' #inline',' #hardcoded '); // type C to test
why cant I get
line 2885 : WUSearchbase(document.getE lementById ("qWU"),WU Array);
to read for our programming we are scraping the array from the external file ?
should it be something more akin to :
WUSearchbase(document.getE lementById ("qWU"), JSON.stringify( WUArray ) );
?
thanks
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
Since:
line 2895 : works CHSearchbase(document.getE
for line 89: var CHindex=new Array('#Chester','#test','
why cant I get
line 2885 : WUSearchbase(document.getE
to read for our programming we are scraping the array from the external file ?
should it be something more akin to :
WUSearchbase(document.getE
?
thanks
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@leakim971
on http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
with this command line 2885 : WUSearchbase(document.getE lementById ("qWU"),WU Array);
I am trying to perform lines 250 thru line 755 against a populated WUArray[] just the same as...
I am w/command line 2895 : CHSearchbase(document.getE lementById ("qCH"),CH index);
I am using the same working code to 'drive' the hard-coded array CHindex[] lines 760 thru 1266
as I am also w/command line 2904 : HBSearchbase(document.getE lementById ("HB"),HBi ndex);
I am using the same working code to 'drive' the hard-coded array HBindex[] lines 1271 thru 1775
as I am also w/command line 2912 : EXSearchbase(document.getE lementById ("qEX"),EX index);
I am using the same working code to 'drive' the hard-coded array EXindex[] lines 1780 thru 2284
as I am also w/command line 2921 : DESearchbase(document.getE lementById ("qDE"),DE index);
I am using the same working code to 'drive' the hard-coded array DEindex[] lines 2289 thru 2793
see lines 87 thru 90 for population of these hard-coded arrays...
on http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
with this command line 2885 : WUSearchbase(document.getE
I am trying to perform lines 250 thru line 755 against a populated WUArray[] just the same as...
I am w/command line 2895 : CHSearchbase(document.getE
I am using the same working code to 'drive' the hard-coded array CHindex[] lines 760 thru 1266
as I am also w/command line 2904 : HBSearchbase(document.getE
I am using the same working code to 'drive' the hard-coded array HBindex[] lines 1271 thru 1775
as I am also w/command line 2912 : EXSearchbase(document.getE
I am using the same working code to 'drive' the hard-coded array EXindex[] lines 1780 thru 2284
as I am also w/command line 2921 : DESearchbase(document.getE
I am using the same working code to 'drive' the hard-coded array DEindex[] lines 2289 thru 2793
see lines 87 thru 90 for population of these hard-coded arrays...
ASKER
WUArray is an array or a table ? It is suppose to be an array
what a 'table' is more like a hashmap ?
I want to mimic and populate hardcoded cells w/ values like in lines 87-90
var EXindex=new Array('#Exton','#test','#i nline','#h ardcoded') ;// type E to test
var DEindex=new Array('#Delaware','#test', '#inline', '#hardcode d');// type D to test
var CHindex=new Array('#Chester','#test',' #inline',' #hardcoded '); // type C to test
var HBindex=new Array('#Harrisburg','#test ','#inline ','#hardco ded');// type H to test
I am trying to get to populate the WUArray from the external file university.txt
...split same format, able to be handled by other functions the same way EXindex, DEindex, CHindex, & HBindex can be just no matter what I do it comes back to me undefined... :(
does that make sense ?
what a 'table' is more like a hashmap ?
I want to mimic and populate hardcoded cells w/ values like in lines 87-90
var EXindex=new Array('#Exton','#test','#i
var DEindex=new Array('#Delaware','#test',
var CHindex=new Array('#Chester','#test','
var HBindex=new Array('#Harrisburg','#test
I am trying to get to populate the WUArray from the external file university.txt
...split same format, able to be handled by other functions the same way EXindex, DEindex, CHindex, & HBindex can be just no matter what I do it comes back to me undefined... :(
does that make sense ?
Ok, please put the "debugger" keyword before the line 2885 so like this :
debugger;
WUSearchbase(document.getElementById("qWU"),WUArray);
ASKER
ok I put 'debugger;' in line 2884 ...
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
whats debugger do ?
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
whats debugger do ?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@leakim971
ok clipboard 04 is me trying to printout the Array but its still undefined.
thanks for showing me this but its all null Im needing to figure out how to NOT have WUArray undefined.
you mentioned earlier post ID:34909352
>>If WUArray is a json object you should modify WUSearchbase (or create WUSearchbaseJSON) to handle it
should I make it one ? all thats new to me... thoughts on that ?
Im looking to fix how to make the Array NOT undefined how do we remedy ?
thx
ok clipboard 04 is me trying to printout the Array but its still undefined.
thanks for showing me this but its all null Im needing to figure out how to NOT have WUArray undefined.
you mentioned earlier post ID:34909352
>>If WUArray is a json object you should modify WUSearchbase (or create WUSearchbaseJSON) to handle it
should I make it one ? all thats new to me... thoughts on that ?
Im looking to fix how to make the Array NOT undefined how do we remedy ?
thx
ASKER
took
<script language="javascript">
//document.writeln(WUArray [1]); // Will output: one
document.writeln('Array info here:');
var printArray = function (x, idx) { document.writeln('['+idx+' ] = '+x);}
WUArray.forEach(printArray ); // outputs: [0] = 1 [1] = two [2] = 3 [3] = four [4] = 5
</script>
out...
<script language="javascript">
//document.writeln(WUArray
document.writeln('Array info here:');
var printArray = function (x, idx) { document.writeln('['+idx+'
WUArray.forEach(printArray
</script>
out...
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
>>function in the same file
it is
>>or inside the same tag
not sure what tag is... does it mean
<script type="text/javascript"> ???
>>Please show me where you populate it.
isnt it http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm :: line 49?
function getContent( data, status, response ) {
WUArray = response.responseText.spli t( /,/ );
}
?? doesnt that perform the same as line 87 :: var EXindex=new Array('#Exton','#test','#i nline','#h ardcoded') ; ??
>>Confirm it's a global variable.
Im going to try to learn how to be sure it is any suggestion how to confirm this ?
it is
>>or inside the same tag
not sure what tag is... does it mean
<script type="text/javascript"> ???
>>Please show me where you populate it.
isnt it http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm :: line 49?
function getContent( data, status, response ) {
WUArray = response.responseText.spli
}
?? doesnt that perform the same as line 87 :: var EXindex=new Array('#Exton','#test','#i
>>Confirm it's a global variable.
Im going to try to learn how to be sure it is any suggestion how to confirm this ?
>it is
>:o(
>not sure what tag is... does it mean <script type="text/javascript"> ???
Yes
>>Please show me where you populate it.
OK. What about my code in my first post ?
jQuery(document).ready( function () {
WUArray = $.ajax({"url":"http://www.widener.edu/webdev/expertexchange/Q_26822624/university.txt","async":f alse}).res ponseText;
alert(WUArray); // please post what you get with this
WUArray = WUArray.split(",")
$("#click-me").click( display );
});
>>Confirm it's a global variable.
It is declared as global line 40, don't worry :) !!!
>:o(
>not sure what tag is... does it mean <script type="text/javascript"> ???
Yes
>>Please show me where you populate it.
OK. What about my code in my first post ?
jQuery(document).ready( function () {
WUArray = $.ajax({"url":"http://www.widener.edu/webdev/expertexchange/Q_26822624/university.txt","async":f
alert(WUArray); // please post what you get with this
WUArray = WUArray.split(",")
$("#click-me").click( display );
});
>>Confirm it's a global variable.
It is declared as global line 40, don't worry :) !!!
var WUArray;
jQuery(document).ready( function () {
ASKER
ok Im putting all methods/ functions in same tag...
//// @ Author:leakim971 Ive been toggling testing between this and @Proculopsis suggestions
////////////////////////// ////////// ////////// ////////// ////////// ////////// ////////// /////
jQuery(document).ready( function () {
WUArray = $.ajax({"url":"http://www.widener.edu/webdev/expertexchange/Q_26822624/university.txt","async":f alse}).res ponseText;
alert(WUArray); // please post what you get with this
WUArray = WUArray.split(",")
$("#click-me").click( display );
////////////////////////// ////////// ////////// ////////// ////////// ////////// ////////// //////
});/// NOTE THIS jQuery DOES NOT seem to work in IE but in FFX it does...
/// see http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
////////////////////////// ////////// ////////// ////////// ////////// ////////// ////////// /////
//// @ Author:leakim971 Ive been toggling testing between this and @Proculopsis suggestions
//////////////////////////
jQuery(document).ready( function () {
WUArray = $.ajax({"url":"http://www.widener.edu/webdev/expertexchange/Q_26822624/university.txt","async":f
alert(WUArray); // please post what you get with this
WUArray = WUArray.split(",")
$("#click-me").click( display );
//////////////////////////
});/// NOTE THIS jQuery DOES NOT seem to work in IE but in FFX it does...
/// see http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
//////////////////////////
ASKER
//should I read it in as a string first as earlier suggested then populate a Array?
var theUniversityIndex = ""; // a new String
var WUArray; // global Array variable
theUniversityIndex = $.ajax({"url":"university. txt","asyn c":false}) .responseT ext;
//THEN split to an array ...
WUArray = theUniversityPhoneIndex.sp lit(",")
// or straight to an array as last post suggests WUArray = WUArray.split(",") ??????????
var theUniversityIndex = ""; // a new String
var WUArray; // global Array variable
theUniversityIndex = $.ajax({"url":"university.
//THEN split to an array ...
WUArray = theUniversityPhoneIndex.sp
// or straight to an array as last post suggests WUArray = WUArray.split(",") ??????????
I still see the previous one
ASKER
I see I cannot nest all code in the same tag - to boil things down the quintessential question here is...
// for javascript programming in
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
// why
this.WUSearchbase_keywords = ca; //line 239
// for the method
function WUSearchbase(obj,ca){ //line 199
// is NOT populating with the values in array cells :
WUArray = response.responseText.spli t( /,/ ); //line 19
thanks
// for javascript programming in
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3.htm
// why
this.WUSearchbase_keywords
// for the method
function WUSearchbase(obj,ca){ //line 199
// is NOT populating with the values in array cells :
WUArray = response.responseText.spli
thanks
Please put a debugger keyword line 19, like this :
function getContent( data, status, response ) {
debugger;
WUArray = response.responseText.split( /,/ );
}
ASKER
I put in 'debugger' but that doesnt seem to do anything ?...
your statement having me nest all javascript in same tag got me thinking...
Im wondering if I should pursue more of a JSON object so I may be able to pass the array between functions sort of like
http://www.widener.edu/webdev/expertexchange/Q_26822624/index5.htm is doing in code where Id nest all functions in one BIG this.load function ....
what do you guys think ?
your statement having me nest all javascript in same tag got me thinking...
Im wondering if I should pursue more of a JSON object so I may be able to pass the array between functions sort of like
http://www.widener.edu/webdev/expertexchange/Q_26822624/index5.htm is doing in code where Id nest all functions in one BIG this.load function ....
what do you guys think ?
>I put in 'debugger' but that doesnt seem to do anything ?...
What's url of the page ?
What's url of the page ?
ASKER
oh yeah I could'a posted...
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3debugger.htm
http://www.widener.edu/webdev/expertexchange/Q_26822624/index3debugger.htm
ASKER
ok I think weve gone round and round with no solution so far looking at external webpages so I figured Id send the working code with hardcoded arrays inline for the ticket ...
this code is found online at
http://www.widener.edu/webdev/expertexchange/Q_26822624/test.htm
this line ::.
MYSearchbase(document.getE lementById ("qLookup" ),MYArray) ; // is the key to array population
works hardcoded.... doesnt work dynamicly read in...
thoughts on Array DOM scope ?
thanks
this code is found online at
http://www.widener.edu/webdev/expertexchange/Q_26822624/test.htm
this line ::.
MYSearchbase(document.getE
works hardcoded.... doesnt work dynamicly read in...
thoughts on Array DOM scope ?
thanks
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Hardcoded Phone Directory Lookup</title>
<script language="javascript" type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////
//////////// Index Array Handling Methods
//////////////////////////////////////////////////////////////////
// Hard coded Arrays all work below
////////////////////////////////////////////////////////
var MYArray=new Array('#MYArray','#hardcoded test','#inline','#hardcoded');
// type 'E' in textfield 'qLookup' to test
//////////////////////////////////////////////////////////////////
//////////// Index Intelitext Drop Down
//////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////
// common searchbase functions
////////////////////////////////////////////////////////
function addEvent(obj,event_name,func_name){
if (obj.attachEvent){
obj.attachEvent("on"+event_name, func_name);
}else if(obj.addEventListener){
obj.addEventListener(event_name,func_name,true);
}else{
obj["on"+event_name] = func_name;
}
}
function removeEvent(obj,event_name,func_name){
if (obj.detachEvent){
obj.detachEvent("on"+event_name,func_name);
}else if(obj.removeEventListener){
obj.removeEventListener(event_name,func_name,true);
}else{
obj["on"+event_name] = null;
}
}
function stopEvent(evt){
evt || window.event;
if (evt.stopPropagation){
evt.stopPropagation();
evt.preventDefault();
}else if(typeof evt.cancelBubble != "undefined"){
evt.cancelBubble = true;
evt.returnValue = false;
}
return false;
}
function getElement(evt){
if (window.event){
return window.event.srcElement;
}else{
return evt.currentTarget;
}
}
function getTargetElement(evt){
if (window.event){
return window.event.srcElement;
}else{
return evt.target;
}
}
function stopSelect(obj){
if (typeof obj.onselectstart != 'undefined'){
addEvent(obj,"selectstart",function(){ return false;});
}
}
function getCaretEnd(obj){
if(typeof obj.selectionEnd != "undefined"){
return obj.selectionEnd;
}else if(document.selection&&document.selection.createRange){
var M=document.selection.createRange();
try{
var Lp = M.duplicate();
Lp.moveToElementText(obj);
}catch(e){
var Lp=obj.createTextRange();
}
Lp.setEndPoint("EndToEnd",M);
var rb=Lp.text.length;
if(rb>obj.value.length){
return -1;
}
return rb;
}
}
function getCaretStart(obj){
if(typeof obj.selectionStart != "undefined"){
return obj.selectionStart;
}else if(document.selection&&document.selection.createRange){
var M=document.selection.createRange();
try{
var Lp = M.duplicate();
Lp.moveToElementText(obj);
}catch(e){
var Lp=obj.createTextRange();
}
Lp.setEndPoint("EndToStart",M);
var rb=Lp.text.length;
if(rb>obj.value.length){
return -1;
}
return rb;
}
}
function setCaret(obj,l){
obj.focus();
if (obj.setSelectionRange){
obj.setSelectionRange(l,l);
}else if(obj.createTextRange){
m = obj.createTextRange();
m.moveStart('character',l);
m.collapse();
m.select();
}
}
function setSelection(obj,s,e){
obj.focus();
if (obj.setSelectionRange){
obj.setSelectionRange(s,e);
}else if(obj.createTextRange){
m = obj.createTextRange();
m.moveStart('character',s);
m.moveEnd('character',e);
m.select();
}
}
String.prototype.addslashes = function(){
return this.replace(/(["\\\.\|\[\]\^\*\+\?\$\(\)])/g, '\\$1');
}
String.prototype.trim = function () {
return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
function curTop(obj){
toreturn = 0;
while(obj){
toreturn += obj.offsetTop;
obj = obj.offsetParent;
}
return toreturn;
}
function curLeft(obj){
toreturn = 0;
while(obj){
toreturn += obj.offsetLeft;
obj = obj.offsetParent;
}
return toreturn;
}
function isNumber(a) {
return typeof a == 'number' && isFinite(a);
}
function replaceHTML(obj,text){
while(el = obj.childNodes[0]){
obj.removeChild(el);
};
obj.appendChild(document.createTextNode(text));
}
////////////////////////////////////////////////////////
// this successfully populates inline arrays of text ',' delineated for each directory
////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////
/////////// MYSearchbase(document.getElementById("q"),WUArray);
/////////////////////////////////////////////////////////////////////////
function MYSearchbase(obj,ca){ // obj, ca
/* ---- Public Variables ---- */
this.MYSearchbase_timeOut = -1; // Autocomplete Timeout in ms (-1: autocomplete never time out)
this.MYSearchbase_lim = 4; // Number of elements autocomplete can show (-1: no limit)
this.MYSearchbase_firstText = false; // should the auto complete be limited to the beginning of
keyword?
this.MYSearchbase_mouse = true; // Enable Mouse Support
this.MYSearchbase_delimiter = new Array(';',','); // Delimiter for multiple autocomplete. Set it to
empty array for single autocomplete
this.MYSearchbase_startcheck = 1; // Show widget only after this number of characters is typed in.
/* ---- Public Variables ---- */
/* --- Styles --- */
this.MYSearchbase_bgColor = '#7bafde';
this.MYSearchbase_textColor = '#FFFFFF';
this.MYSearchbase_hColor = '#000000';
this.MYSearchbase_fFamily = 'Verdana';
this.MYSearchbase_fSize = '11px';
this.MYSearchbase_hStyle = 'text-decoration:underline;font-weight="bold"';
/* --- Styles --- */
/* ---- Private Variables ---- */
var MYSearchbase_delimwords = new Array();
var MYSearchbase_cdelimword = 0;
var MYSearchbase_delimchar = new Array();
var MYSearchbase_display = false;
var MYSearchbase_pos = 0;
var MYSearchbase_total = 0;
var MYSearchbase_curr = null;
var MYSearchbase_rangeu = 0;
var MYSearchbase_ranged = 0;
var MYSearchbase_bool = new Array();
var MYSearchbase_pre = 0;
var MYSearchbase_toid;
var MYSearchbase_tomake = false;
var MYSearchbase_getpre = "";
var MYSearchbase_mouse_on_list = 1;
var MYSearchbase_kwcount = 0;
var MYSearchbase_caretmove = false;
this.MYSearchbase_keywords = new Array();
/* ---- Private Variables---- */
this.MYSearchbase_keywords = ca;
//MAYBE TRY to FORCE the this.WUArray value HERE
var MYSearchbase_self = this;
MYSearchbase_curr = obj;
addEvent(MYSearchbase_curr,"focus",MYSearchbase_setup);
function MYSearchbase_setup(){
addEvent(document,"keydown",MYSearchbase_checkkey);
addEvent(MYSearchbase_curr,"blur",MYSearchbase_clear);
addEvent(document,"keypress",MYSearchbase_keypress);
}
function MYSearchbase_clear(evt){
if (!evt) evt = event;
removeEvent(document,"keydown",MYSearchbase_checkkey);
removeEvent(MYSearchbase_curr,"blur",MYSearchbase_clear);
removeEvent(document,"keypress",MYSearchbase_keypress);
MYSearchbase_removedisp();
}
function MYSearchbase_parse(n){
if (MYSearchbase_self.MYSearchbase_delimiter.length > 0){
var t = MYSearchbase_delimwords[MYSearchbase_cdelimword].trim().addslashes();
var plen = MYSearchbase_delimwords[MYSearchbase_cdelimword].trim().length;
}else{
var t = MYSearchbase_curr.value.addslashes();
var plen = MYSearchbase_curr.value.length;
}
var tobuild = '';
var i;
if (MYSearchbase_self.MYSearchbase_firstText){
var re = new RegExp("^" + t, "i");
}else{
var re = new RegExp(t, "i");
}
var p = n.search(re);
for (i=0;i<p;i++){
tobuild += n.substr(i,1);
}
tobuild += "<font style='"+(MYSearchbase_self.MYSearchbase_hStyle)+"'>"
for (i=p;i<plen+p;i++){
tobuild += n.substr(i,1);
}
tobuild += "</font>";
for (i=plen+p;i<n.length;i++){
tobuild += n.substr(i,1);
}
return tobuild;
}
function MYSearchbase_generate(){
if (document.getElementById('tat_table')){ MYSearchbase_display =
false;document.body.removeChild(document.getElementById('tat_table')); }
if (MYSearchbase_kwcount == 0){
MYSearchbase_display = false;
return;
}
a = document.createElement('table');
a.cellSpacing='1px';
a.cellPadding='2px';
a.style.position='absolute';
a.style.top = eval(curTop(MYSearchbase_curr) + MYSearchbase_curr.offsetHeight) + "px";
a.style.left = curLeft(MYSearchbase_curr) + "px";
a.style.backgroundColor=MYSearchbase_self.MYSearchbase_bgColor;
a.id = 'tat_table';
document.body.appendChild(a);
var i;
var first = true;
var j = 1;
if (MYSearchbase_self.MYSearchbase_mouse){
a.onmouseout = MYSearchbase_table_unfocus;
a.onmouseover = MYSearchbase_table_focus;
}
var counter = 0;
for (i=0;i<MYSearchbase_self.MYSearchbase_keywords.length;i++){
if (MYSearchbase_bool[i]){
counter++;
r = a.insertRow(-1);
if (first && !MYSearchbase_tomake){
r.style.backgroundColor = MYSearchbase_self.MYSearchbase_hColor;
first = false;
MYSearchbase_pos = counter;
}else if(MYSearchbase_pre == i){
r.style.backgroundColor = MYSearchbase_self.MYSearchbase_hColor;
first = false;
MYSearchbase_pos = counter;
}else{
r.style.backgroundColor = MYSearchbase_self.MYSearchbase_bgColor;
}
r.id = 'tat_tr'+(j);
c = r.insertCell(-1);
c.style.color = MYSearchbase_self.MYSearchbase_textColor;
c.style.fontFamily = MYSearchbase_self.MYSearchbase_fFamily;
c.style.fontSize = MYSearchbase_self.MYSearchbase_fSize;
c.innerHTML = MYSearchbase_parse(MYSearchbase_self.MYSearchbase_keywords[i]);
c.id = 'tat_td'+(j);
c.setAttribute('pos',j);
if (MYSearchbase_self.MYSearchbase_mouse){
c.style.cursor = 'pointer';
c.onclick=MYSearchbase_mouseclick;
c.onmouseover = MYSearchbase_table_highlight;
}
j++;
}
if (j - 1 == MYSearchbase_self.MYSearchbase_lim && j < MYSearchbase_total){
r = a.insertRow(-1);
r.style.backgroundColor = MYSearchbase_self.MYSearchbase_bgColor;
c = r.insertCell(-1);
c.style.color = MYSearchbase_self.MYSearchbase_textColor;
c.style.fontFamily = 'arial narrow';
c.style.fontSize = MYSearchbase_self.MYSearchbase_fSize;
c.align='center';
replaceHTML(c,'\\/');
if (MYSearchbase_self.MYSearchbase_mouse){
c.style.cursor = 'pointer';
c.onclick = MYSearchbase_mouse_down;
}
break;
}
}
MYSearchbase_rangeu = 1;
MYSearchbase_ranged = j-1;
MYSearchbase_display = true;
if (MYSearchbase_pos <= 0) MYSearchbase_pos = 1;
}
function MYSearchbase_remake(){
document.body.removeChild(document.getElementById('tat_table'));
a = document.createElement('table');
a.cellSpacing='1px';
a.cellPadding='2px';
a.style.position='absolute';
a.style.top = eval(curTop(MYSearchbase_curr) + MYSearchbase_curr.offsetHeight) + "px";
a.style.left = curLeft(MYSearchbase_curr) + "px";
a.style.backgroundColor=MYSearchbase_self.MYSearchbase_bgColor;
a.id = 'tat_table';
if (MYSearchbase_self.MYSearchbase_mouse){
a.onmouseout= MYSearchbase_table_unfocus;
a.onmouseover=MYSearchbase_table_focus;
}
document.body.appendChild(a);
var i;
var first = true;
var j = 1;
if (MYSearchbase_rangeu > 1){
r = a.insertRow(-1);
r.style.backgroundColor = MYSearchbase_self.MYSearchbase_bgColor;
c = r.insertCell(-1);
c.style.color = MYSearchbase_self.MYSearchbase_textColor;
c.style.fontFamily = 'arial narrow';
c.style.fontSize = MYSearchbase_self.MYSearchbase_fSize;
c.align='center';
replaceHTML(c,'/\\');
if (MYSearchbase_self.MYSearchbase_mouse){
c.style.cursor = 'pointer';
c.onclick = MYSearchbase_mouse_up;
}
}
for (i=0;i<MYSearchbase_self.MYSearchbase_keywords.length;i++){
if (MYSearchbase_bool[i]){
if (j >= MYSearchbase_rangeu && j <= MYSearchbase_ranged){
r = a.insertRow(-1);
r.style.backgroundColor = MYSearchbase_self.MYSearchbase_bgColor;
r.id = 'tat_tr'+(j);
c = r.insertCell(-1);
c.style.color = MYSearchbase_self.MYSearchbase_textColor;
c.style.fontFamily = MYSearchbase_self.MYSearchbase_fFamily;
c.style.fontSize = MYSearchbase_self.MYSearchbase_fSize;
c.innerHTML =
MYSearchbase_parse(MYSearchbase_self.MYSearchbase_keywords[i]);
c.id = 'tat_td'+(j);
c.setAttribute('pos',j);
if (MYSearchbase_self.MYSearchbase_mouse){
c.style.cursor = 'pointer';
c.onclick=MYSearchbase_mouseclick;
c.onmouseover = MYSearchbase_table_highlight;
}
j++;
}else{
j++;
}
}
if (j > MYSearchbase_ranged) break;
}
if (j-1 < MYSearchbase_total){
r = a.insertRow(-1);
r.style.backgroundColor = MYSearchbase_self.MYSearchbase_bgColor;
c = r.insertCell(-1);
c.style.color = MYSearchbase_self.MYSearchbase_textColor;
c.style.fontFamily = 'arial narrow';
c.style.fontSize = MYSearchbase_self.MYSearchbase_fSize;
c.align='center';
replaceHTML(c,'\\/');
if (MYSearchbase_self.MYSearchbase_mouse){
c.style.cursor = 'pointer';
c.onclick = MYSearchbase_mouse_down;
}
}
}
function MYSearchbase_goup(){
if (!MYSearchbase_display) return;
if (MYSearchbase_pos == 1) return;
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_bgColor;
MYSearchbase_pos--;
if (MYSearchbase_pos < MYSearchbase_rangeu) MYSearchbase_moveup();
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_hColor;
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
if (MYSearchbase_self.MYSearchbase_timeOut > 0) MYSearchbase_toid =
setTimeout(function(){MYSearchbase_mouse_on_list=0;MYSearchbase_removedisp();},MYSearchbase_self.MYSearchbase_t
imeOut);
}
function MYSearchbase_godown(){
if (!MYSearchbase_display) return;
if (MYSearchbase_pos == MYSearchbase_total) return;
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_bgColor;
MYSearchbase_pos++;
if (MYSearchbase_pos > MYSearchbase_ranged) MYSearchbase_movedown();
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_hColor;
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
if (MYSearchbase_self.MYSearchbase_timeOut > 0) MYSearchbase_toid =
setTimeout(function(){MYSearchbase_mouse_on_list=0;MYSearchbase_removedisp();},MYSearchbase_self.MYSearchbase_t
imeOut);
}
function MYSearchbase_movedown(){
MYSearchbase_rangeu++;
MYSearchbase_ranged++;
MYSearchbase_remake();
}
function MYSearchbase_moveup(){
MYSearchbase_rangeu--;
MYSearchbase_ranged--;
MYSearchbase_remake();
}
/* Mouse */
function MYSearchbase_mouse_down(){
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_bgColor;
MYSearchbase_pos++;
MYSearchbase_movedown();
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_hColor;
MYSearchbase_curr.focus();
MYSearchbase_mouse_on_list = 0;
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
if (MYSearchbase_self.MYSearchbase_timeOut > 0) MYSearchbase_toid =
setTimeout(function(){MYSearchbase_mouse_on_list=0;MYSearchbase_removedisp();},MYSearchbase_self.MYSearchbase_t
imeOut);
}
function MYSearchbase_mouse_up(evt){
if (!evt) evt = event;
if (evt.stopPropagation){
evt.stopPropagation();
}else{
evt.cancelBubble = true;
}
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_bgColor;
MYSearchbase_pos--;
MYSearchbase_moveup();
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_hColor;
MYSearchbase_curr.focus();
MYSearchbase_mouse_on_list = 0;
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
if (MYSearchbase_self.MYSearchbase_timeOut > 0) MYSearchbase_toid =
setTimeout(function(){MYSearchbase_mouse_on_list=0;MYSearchbase_removedisp();},MYSearchbase_self.MYSearchbase_t
imeOut);
}
function MYSearchbase_mouseclick(evt){
if (!evt) evt = event;
if (!MYSearchbase_display) return;
MYSearchbase_mouse_on_list = 0;
MYSearchbase_pos = this.getAttribute('pos');
MYSearchbase_penter();
}
function MYSearchbase_table_focus(){
MYSearchbase_mouse_on_list = 1;
}
function MYSearchbase_table_unfocus(){
MYSearchbase_mouse_on_list = 0;
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
if (MYSearchbase_self.MYSearchbase_timeOut > 0) MYSearchbase_toid =
setTimeout(function(){MYSearchbase_mouse_on_list =
0;MYSearchbase_removedisp();},MYSearchbase_self.MYSearchbase_timeOut);
}
function MYSearchbase_table_highlight(){
MYSearchbase_mouse_on_list = 1;
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_bgColor;
MYSearchbase_pos = this.getAttribute('pos');
while (MYSearchbase_pos < MYSearchbase_rangeu) MYSearchbase_moveup();
while (MYSearchbase_pos > MYSearchbase_ranged) MYSearchbase_movedown();
document.getElementById('tat_tr'+MYSearchbase_pos).style.backgroundColor =
MYSearchbase_self.MYSearchbase_hColor;
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
if (MYSearchbase_self.MYSearchbase_timeOut > 0) MYSearchbase_toid =
setTimeout(function(){MYSearchbase_mouse_on_list =
0;MYSearchbase_removedisp();},MYSearchbase_self.MYSearchbase_timeOut);
}
/* ---- */
function MYSearchbase_insertword(a){
if (MYSearchbase_self.MYSearchbase_delimiter.length > 0){
str = '';
l=0;
for (i=0;i<MYSearchbase_delimwords.length;i++){
if (MYSearchbase_cdelimword == i){
prespace = postspace = '';
gotbreak = false;
for (j=0;j<MYSearchbase_delimwords[i].length;++j){
if (MYSearchbase_delimwords[i].charAt(j) != ' '){
gotbreak = true;
break;
}
prespace += ' ';
}
for (j=MYSearchbase_delimwords[i].length-1;j>=0;--j){
if (MYSearchbase_delimwords[i].charAt(j) != ' ') break;
postspace += ' ';
}
str += prespace;
str += a;
l = str.length;
if (gotbreak) str += postspace;
}else{
str += MYSearchbase_delimwords[i];
}
if (i != MYSearchbase_delimwords.length - 1){
str += MYSearchbase_delimchar[i];
}
}
MYSearchbase_curr.value = str;
setCaret(MYSearchbase_curr,l);
}else{
MYSearchbase_curr.value = a;
}
MYSearchbase_mouse_on_list = 0;
MYSearchbase_removedisp();
}
function MYSearchbase_penter(){
if (!MYSearchbase_display) return;
MYSearchbase_display = false;
var word = '';
var c = 0;
for (var i=0;i<=MYSearchbase_self.MYSearchbase_keywords.length;i++){
if (MYSearchbase_bool[i]) c++;
if (c == MYSearchbase_pos){
word = MYSearchbase_self.MYSearchbase_keywords[i];
break;
}
}
MYSearchbase_insertword(word);
l = getCaretStart(MYSearchbase_curr);
}
function MYSearchbase_removedisp(){
if (MYSearchbase_mouse_on_list==0){
MYSearchbase_display = 0;
if (document.getElementById('tat_table')){
document.body.removeChild(document.getElementById('tat_table')); }
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
}
}
function MYSearchbase_keypress(e){
if (MYSearchbase_caretmove) stopEvent(e);
return !MYSearchbase_caretmove;
}
function MYSearchbase_checkkey(evt){
if (!evt) evt = event;
a = evt.keyCode;
caret_pos_start = getCaretStart(MYSearchbase_curr);
MYSearchbase_caretmove = 0;
switch (a){
case 38:
MYSearchbase_goup();
MYSearchbase_caretmove = 1;
return false;
break;
case 40:
MYSearchbase_godown();
MYSearchbase_caretmove = 1;
return false;
break;
case 13: case 9:
if (MYSearchbase_display){
MYSearchbase_caretmove = 1;
MYSearchbase_penter();
return false;
}else{
return true;
}
break;
default:
setTimeout(function(){MYSearchbase_tocomplete(a)},50);
break;
}
}
function MYSearchbase_tocomplete(kc){
if (kc == 38 || kc == 40 || kc == 13) return;
var i;
if (MYSearchbase_display){
var word = 0;
var c = 0;
for (var i=0;i<=MYSearchbase_self.MYSearchbase_keywords.length;i++){
if (MYSearchbase_bool[i]) c++;
if (c == MYSearchbase_pos){
word = i;
break;
}
}
MYSearchbase_pre = word;
}else{ MYSearchbase_pre = -1};
if (MYSearchbase_curr.value == ''){
MYSearchbase_mouse_on_list = 0;
MYSearchbase_removedisp();
return;
}
if (MYSearchbase_self.MYSearchbase_delimiter.length > 0){
caret_pos_start = getCaretStart(MYSearchbase_curr);
caret_pos_end = getCaretEnd(MYSearchbase_curr);
delim_split = '';
for (i=0;i<MYSearchbase_self.MYSearchbase_delimiter.length;i++){
delim_split += MYSearchbase_self.MYSearchbase_delimiter[i];
}
delim_split = delim_split.addslashes();
delim_split_rx = new RegExp("(["+delim_split+"])");
c = 0;
MYSearchbase_delimwords = new Array();
MYSearchbase_delimwords[0] = '';
for (i=0,j=MYSearchbase_curr.value.length;i<MYSearchbase_curr.value.length;i++,j--){
if (MYSearchbase_curr.value.substr(i,j).search(delim_split_rx) == 0){
ma = MYSearchbase_curr.value.substr(i,j).match(delim_split_rx);
MYSearchbase_delimchar[c] = ma[1];
c++;
MYSearchbase_delimwords[c] = '';
}else{
MYSearchbase_delimwords[c] += MYSearchbase_curr.value.charAt(i);
}
}
var l = 0;
MYSearchbase_cdelimword = -1;
for (i=0;i<MYSearchbase_delimwords.length;i++){
if (caret_pos_end >= l && caret_pos_end <= l +
MYSearchbase_delimwords[i].length){
MYSearchbase_cdelimword = i;
}
l+=MYSearchbase_delimwords[i].length + 1;
}
var ot = MYSearchbase_delimwords[MYSearchbase_cdelimword].trim();
var t = MYSearchbase_delimwords[MYSearchbase_cdelimword].addslashes().trim();
}else{
var ot = MYSearchbase_curr.value;
var t = MYSearchbase_curr.value.addslashes();
}
if (ot.length == 0){
MYSearchbase_mouse_on_list = 0;
MYSearchbase_removedisp();
}
if (ot.length < MYSearchbase_self.MYSearchbase_startcheck) return this;
if (MYSearchbase_self.MYSearchbase_firstText){
var re = new RegExp("^" + t, "i");
}else{
var re = new RegExp(t, "i");
}
MYSearchbase_total = 0;
MYSearchbase_tomake = false;
MYSearchbase_kwcount = 0;
for (i=0;i<MYSearchbase_self.MYSearchbase_keywords.length;i++){
MYSearchbase_bool[i] = false;
if (re.test(MYSearchbase_self.MYSearchbase_keywords[i])){
MYSearchbase_total++;
MYSearchbase_bool[i] = true;
MYSearchbase_kwcount++;
if (MYSearchbase_pre == i) MYSearchbase_tomake = true;
}
}
if (MYSearchbase_toid) clearTimeout(MYSearchbase_toid);
if (MYSearchbase_self.MYSearchbase_timeOut > 0) MYSearchbase_toid =
setTimeout(function(){MYSearchbase_mouse_on_list =
0;MYSearchbase_removedisp();},MYSearchbase_self.MYSearchbase_timeOut);
MYSearchbase_generate();
}
return this;
}
/////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////
// Google targeted Website with text field value
//////////////////////////////////////////////////////////////////
function pushtoGoogle(){
var str;
str = document.getElementById('qLookup').value;
//got it here alert(str);
splitListing = str.split("#") // zero based array
//alert(splitListing);
//telling the function to look for a single space
//When it finds a single space, use that to add an item to the array
returnjustnumber = splitListing[1];
document.getElementById("q").value = returnjustnumber;
}// end Google Search script
</script>
<!--
// These next 2 scripts handle Hide/Show of DIV 'panels'
/////////////////////////////////////////////////////////////////////
-->
<SCRIPT language="JavaScript1.2" src="reveal.js"type="text/javascript"></SCRIPT>
<SCRIPT language="JavaScript1.2" src="jumpto.js"type="text/javascript"></SCRIPT>
<style type="text/css">
<!--
body {
background-color: #fff;
}
#dynamic-content { width: 320px; height: 400px; border: 1px dotted #f00; margin-left: 18px; margin-right: auto;
overflow: auto; background-color: beige; z-index:9; margin-top:120px; }
-->
@charset "utf-8";
/* CSS Document */
#pnlMYSearch {
position:absolute;/* position:absolute; */
width: 381px;
height:25px;
top: 80px;
left: 450px;
z-index:5;
background-color:#FFF
}
#MYReadFile {
position:absolute;/* position:absolute; */
width: 700px;
height:600px;
top: 120px;
left: 18px;
z-index:10;
background-color:gold;
font-size:12px;
color:#000;
}
#pnlSearchBTN {
position:absolute;/* position:absolute; */
width: 166px;
height:30px;
top: 49px;
left: 456px;
z-index:3;
}
#button_bg {
position:absolute;/* position:absolute; */
width: 160px;
height:63px;
top: 110px;
left: 581px;
z-index:1;
background-image:url(test_button_background.gif);
}
#testPanel {
position:absolute;/* position:absolute; */
width: 360px;
height:400px;
top: 0px;
left: 18px;
z-index:1;
background-color:#FC6;
}
</style>
</head>
<body>
<FORM id="searchForm" method="GET" action="http://www.google.com/search">
<input type="hidden" name="ie" value="ISO-8859-1">
<input type="hidden" name="oe" value="ISO-8859-1">
<script type="text/javascript" charset="utf-8">
document.write("The string is this long "+ MYArray +" (should be 23753)");
//processArrayValues.display()
</script>
<div id="button_bg">
<table width="160" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="33" colspan="2" align="center" style="background-color:#FFF;">Search Array</td>
</tr>
<tr>
<td width="90" height="30"><a href="#" onclick="showhide('pnlSearch');"><img src="trans_spacer.gif" alt=""
width="90" height="30" hspace="0" vspace="0" border="0" /></a></td>
<td width="70" height="30"><input type="image" src="trans_spacer.gif" height="31" width="70" border="0"
value="Search MyWebsite.tld" id="submit" name="submit" alt="search" onclick="pushtoGoogle()" /></td>
</tr></table></div>
<!-- Search Chester -->
<div id="pnlSearch" style="display: none;">
<label><a href="#" onclick="showhide('pnlSearch');"><img src="close_btn.gif" border="0" hspace="0" vspace="0"
/></a> Search Array <font size="-2" color="#999999">: type E to test inline hardcoded array</font><INPUT
type="text" id="qLookup" name="qLookup" size="60" value="" style="margin-left:10px;"
autocomplete="off"></label>
<script language="javascript">
MYSearchbase(document.getElementById("qLookup"),MYArray);
</script>
</div>
<input type="hidden" name="client" value="google-csbe">
<input type="hidden" name="domains" value="widener.edu">
<input type="radio" name="sitesearch" value="http://widener.edu" checked style="display:none;">
<input type="hidden" name="q" id="q" >
</FORM>
</body>
</html>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
hey @leakim971 man that works !
Im gonna try to implement later this week for a complete solution and will post so others can obtain source
can you explain how you came to this data.replace conclusion ?
and how in your mind/design is it operating to handle the scope need ?
thx
Im gonna try to implement later this week for a complete solution and will post so others can obtain source
can you explain how you came to this data.replace conclusion ?
and how in your mind/design is it operating to handle the scope need ?
thx
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thats great man... so perhaps the double quote was conflicting with passing to a paramater of the other sub-function... thanks !
final work is here http://www.widener.edu/webdev/phone_index.htm
final work is here http://www.widener.edu/webdev/phone_index.htm
ASKER
thx to Proculopsis for blazing a trail of understand but MAJOR props to leakim971 for patience and follow though! cheers !
Open in new window