/    Sign up×
Community /Pin to ProfileBookmark

finding strings

sorry guys, i searched for this and couldn’t make it work. i wrote this code in PHP, and now i need to do the same thing in JavaScript. basically, it searches a string to see if another string exist, and sets a varaible according to the result.

in PHP:

if(!strstr($ins, ‘IEHP’) && !strstr($ins, ‘Private’) && !strstr($ins, ‘Workers’)){
if(strstr($ins, ‘Medicare’)){
$fname = “Add to MEDICARE.PRN”;
}elseif(strstr($ins, ‘PPO’)){
$fname = “Add to PPO.PRN”;
}elseif(strstr($ins, ‘HMO’) || strstr($ins, ‘SCAN’)){
$fname = “Add to HMO batch?”;
}
$text .= $fname.”&nbsp;<input type=’checkbox’ name=’addbatch’ value=’Y’>&nbsp;&nbsp;&nbsp;&nbsp;”;
}

and heres what ive started in javascript, but it doesn’t work:

if(ins.match(IEHP) == ‘null’ && ins.match(Private) == ‘null’ && ins.match(Workers) == ‘null’){
if(ins.match(Medicare) != ‘null’){
fname = ‘Add to MEDICARE.PRN’
}elseif(ins.match(PPO) != ‘null’){
fname = ‘Add to PPO.PRN’
}elseif(ins.match(HMO) != ‘null’ || ins.match(SCAN) != ‘null’){
fname = ‘Add to HMO batch?’
}
document.getElementById(‘filename’).innerHTML = fname+”<input type=’checkbox’ name=’addbatch’ value=’Y>”
}

to post a comment
JavaScript

13 Comments(s)

Copy linkTweet thisAlerts:
@CharlesApr 10.2005 — Please describe, in English, what [i]exactly[/i] it is that you are trying to do. And be aware that JavaScript supports regular expressions, an extremely powerful pattern matching syntrax and aware that Element.innerHTML is not a part of JavaScript, it's an MSIE corruption of the language.
Copy linkTweet thisAlerts:
@decibelauthorApr 10.2005 — whats the equivalent of strstr (php) in javascript? "english" enough for ya?can anybody give any helpful code or tips? (unlike charles) I dont understand regular expression. If i knew everything, i wouldn't be asking for help.

PS: I love IE.
Copy linkTweet thisAlerts:
@CharlesApr 10.2005 — I understand regular expressions but I do not understand what you are trying to do. If, and only if, you can help me then I will be able to help you. Please describe, in English, what [i]exactly[/i] it is that you are trying to do.
Copy linkTweet thisAlerts:
@CharlesApr 10.2005 — whats the equivalent of strstr (php) in javascript? "english" enough for ya?[/QUOTE]What does "strstr (php)" do?
Copy linkTweet thisAlerts:
@decibelauthorApr 10.2005 — it seaches the variable $ins, and if it finds HMO, it retuurns true. Then the condition sets variable $fname = "Add to HMO file";

of course in my php example, i use !strstr($ins, "HMO"); meaning that if it doesn't find string "HMO" in $ins
Copy linkTweet thisAlerts:
@CharlesApr 10.2005 — [font=monospace]if (/HMO/.test (ins)) fname = 'Add to HTML file'[/font]
Copy linkTweet thisAlerts:
@decibelauthorApr 10.2005 — well charles, i truly am grateful for the help, although you gave me a hard time at first. the code is workin now, here it is:

if (/HMO/.test(ins)) {

fname = 'Add to HMO.PRN'

}

if (/SCAN/.test(ins)) {

fname = 'Add to HMO.PRN'

}

if (/Medicare/.test(ins)) {

fname = 'Add to MEDICARE.PRN'

}

if (/PPO/.test(ins)) {

fname = 'Add to PPO.PRN'

}

document.getElementById('filename').innerHTML = fname+"&nbsp;<input type='checkbox' name='addbatch' value='Y'>"
Copy linkTweet thisAlerts:
@decibelauthorApr 10.2005 — what an alternative to innerHTML ?
Copy linkTweet thisAlerts:
@CharlesApr 10.2005 — &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"&gt;
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;meta name="Content-Script-Type" content="text/javascript"&gt;
&lt;meta name="Content-Style-Type" content="text/css"&gt;
&lt;title&gt;Example&lt;/title&gt;

&lt;script type="text/javascript"&gt;
&lt;!--
onload = function () {
var filename = document.getElementById ('filename');
var label = document.createTextNode ('fname ');
filename.appendChild (label);

<i> </i>var input = document.createElement ('INPUT');
<i> </i>input.setAttribute ('name', 'addbatch');
<i> </i>input.setAttribute ('type', 'checkbox');
<i> </i>input.setAttribute ('value', 'Y');
<i> </i>filename.appendChild (input);
}
// --&gt;
&lt;/script&gt;

&lt;/head&gt;
&lt;body&gt;
&lt;div&gt;
&lt;label id="filename"&gt;&lt;/label&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@decibelauthorApr 10.2005 — whoa, thats a little over my head. the code is working for now, and all i us e is IE for the program, so i'll bookmark this post and thanks again.
Copy linkTweet thisAlerts:
@CharlesApr 10.2005 — Don't bookmark this thread, bookmark the [url=http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/]Document Object Model (DOM) Level 1 Specification[/url].
Copy linkTweet thisAlerts:
@decibelauthorApr 10.2005 — alright, i will do that.
×

Success!

Help @decibel 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.18,
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,
)...