<script type="text/javascript">
function CheckValue() {
var a = "d";
var str = "a|b|c|d";
for (var i = 0; i < str.split('|').length; i++) {
if (str.split('|')[i] == a) {
alert("Value already exist");
return;
}
}
str = str + "|" + a;
alert(str);
}
</script>
Please Mark as Answer if find helpful -- Nasser -- Skype: maleknasser1
Marked as answer by ssjGanesh on May 10, 2012 01:59 PM
ssjGanesh
Participant
1928 Points
1352 Posts
How to check wether a value is already added in a hiden or not?
May 10, 2012 12:43 PM|LINK
I have storing some values in a hidden variable in a javascript function.
like with | symbol seperated values,
a|b|c|d
I need to check wether the values is already added or not.
If i try to insert 'c' it shows alert(), else it should add.
How can i do that in javascript?
Mark as answer,if it helped U!
ravi_27may
Member
4 Points
3 Posts
Re: How to check wether a value is already added in a hiden or not?
May 10, 2012 12:58 PM|LINK
There is a function called search in Javascript which searches for a specific string and returns the starting of that string
Example
var str = "a|b|c|d"
var n = str.Search("c")
here if you execute the above steps in javascript the n will be returned as 4
so try with this condition such that search for the string if it returns some value then skip the insert else insert the string
Nasser Malik
Star
11574 Points
1778 Posts
Re: How to check wether a value is already added in a hiden or not?
May 10, 2012 01:03 PM|LINK
this fits for you
<script type="text/javascript"> function CheckValue() { var a = "d"; var str = "a|b|c|d"; for (var i = 0; i < str.split('|').length; i++) { if (str.split('|')[i] == a) { alert("Value already exist"); return; } } str = str + "|" + a; alert(str); } </script>Skype: maleknasser1