/    Sign up×
Community /Pin to ProfileBookmark

Please look into to code why the second part is not working

[B]Current(working)[/B]
function doTest(txtFile, searchFor)
{
fetchText(txtFile);
setTimeout(“alert(-1 != text.indexOf(‘” + searchFor + “‘))”, 750);

}

[B]Required(not working)[/B]
function doTest(txtFile, searchFor)
{
fetchText(txtFile);
var a = alert(text.indexOf(+searchFor));
alert(‘a:::: ‘+a);

}

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangDec 29.2010 — Provided [I]text [/I]is a global variable, the 1st alert will work, but it does not return a value, so the 2nd alert will show undefined.
Copy linkTweet thisAlerts:
@ashadjawaidauthorDec 29.2010 — Hi

this is the whole program for finding the existence of a word in a file

it is giving an alert true or false with the function stated above

I need to store that value in a variable and then print the value through an alert i somehow succeeded to get pass it into the variable but it is giving me some random number instead of -1(in case word doesn't exist) or some +ve if word is there.

PLEASE ADVISE



<html>

<head>

<script language="JavaScript" type="text/javascript">

var text;

function fetchText(txtFile)

{

var d = document;

var txtFrame = d.getElementById( 'textReader');

txtFrame.src = txtFile;

setTimeout('text = getContent();', 500);

}

function getContent()

{

var d = document;

var txtFrame = d.getElementById( 'textReader');

var text = '';

if (txtFrame.contentDocument)

{

var d = txtFrame.contentDocument;

text = d.getElementsByTagName('BODY')[ 0].innerHTML;

}

else if (txtFrame.contentWindow)

{

var w = txtFrame.contentWindow;

text = w.document.body.innerHTML;

}
return text;

}

function doTest(txtFile, searchFor)

{

fetchText(txtFile);

var a = setTimeout("text.indexOf('" + searchFor + "')", 750);

alert('a:::'+a);

}
</script>

</head>

<body>

<iframe id="textReader" style="display: none;"></iframe>

<form>

<script>

window.onload= doTest('D:Desktopgrant.sql', 'SELECT');

</script>

</form>

</body>

</html>
Copy linkTweet thisAlerts:
@FangDec 29.2010 — [I]var a[/I] will be the id number of setTimeout. It's value is unpredictable and varies with each browser. It has nothing to do with indexOf.
×

Success!

Help @ashadjawaid spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.7,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...