Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31511 > unrolled thread
| Started by | vinodtiwari10@gmail.com |
|---|---|
| First post | 2016-10-04 11:23 -0700 |
| Last post | 2016-10-04 20:58 +0200 |
| Articles | 2 — 2 participants |
Back to article view | Back to comp.lang.javascript
How to check existance of the element value in Javascript vinodtiwari10@gmail.com - 2016-10-04 11:23 -0700
Re: How to check existance of the element value in Javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-10-04 20:58 +0200
| From | vinodtiwari10@gmail.com |
|---|---|
| Date | 2016-10-04 11:23 -0700 |
| Subject | How to check existance of the element value in Javascript |
| Message-ID | <63599b54-703c-4db4-ac68-2eb4275357ba@googlegroups.com> |
I have XML stored in the variable 'ad' and 'addd':
Variable ad:
<?xml version="1.0" encoding="UTF-8"?>
<name>
<data>
<Id>003</Id>
</data>
<data>
<Id>006</Id>
</data>
....
</name>
And Variable addd:
<?xml version="1.0" encoding="UTF-8"?>
<name>
<data>
<Id>009</Id>
</data>
<data>
<Id>005</Id>
</data>
...
</name>
I have written a `ttt` function:
function ttt(ad,addd) {
var match = ad.match(/<Id\/>/);
var matcht = addd.match(/<Id\/>/);
if ((! match || match.length == 0) && (! matcht || match.length == 0)){
return "Below is the details of the Id of ad:\n\n" + ad.split("<Id>")[1].split("</Id>")[0]; + "\n\n And, Below is the details of the Id of addd:\n\n" +addd.split("<Id>")[1].split("</Id>")[0];
}
}
I need `If` `Id` is not blank from ad variable then return alert as `error` with `Id` as below:
<?xml version="1.0" encoding="UTF-8"?>
<name>
<data>
<Id>003</Id>
</data>
<data>
<Id>006</Id>
</data>
</name>
And, I need `If` `Id` is not blank from addd variable then return alert as `error` with `Id` as below:
<?xml version="1.0" encoding="UTF-8"?>
<name>
<data>
<Id>009</Id>
</data>
<data>
<Id>005</Id>
</data>
</name>
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2016-10-04 20:58 +0200 |
| Message-ID | <XnsA697D54B2C51Ceejj99@194.109.6.166> |
| In reply to | #31511 |
vinodtiwari10@gmail.com wrote on 04 Oct 2016 in comp.lang.javascript:
> I have XML stored in the variable 'ad' and 'addd':
You can only store a STRING containing text with xml-source in a variable
[...]
>
> I have written a `ttt` function:
> function ttt(ad,addd) {
> var match = ad.match(/<Id\/>/);
> var matcht = addd.match(/<Id\/>/);
If you want to test something in a string, use test() not match(),
and preferable don't use function words as variable names.
var adTest = /<Id\/>/.test(ad);
var adddTest = /<Id\/>/.test(addd);
> if ((! match || match.length == 0) &&
> (! matcht || match.length == 0 )
>
if (!adTest && !adddTest)
alert('both tests are false');
Is that what you expected?
[..]
> I need `If` `Id` is not blank from ad variable then return alert as
> `error` with `Id` as below:
"is not blank from ad variable"
I do not understand that senstense, could you refrase?
=================
Please give your name as signature.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web