JavaScript check field value based on variable value
Posted
by Nikita Sumeiko
on Stack Overflow
See other posts from Stack Overflow
or by Nikita Sumeiko
Published on 2010-04-21T07:56:50Z
Indexed on
2010/04/21
8:03 UTC
Read the original article
Hit count: 328
I have an anchor like this:
<a href="#" rel="1 4 7 18 ">Anchor</a>
Where 'rel' attribute values are ids of some items.
Than I have a form with an input, where user should type an id and click submit button.
On submit button click I need to check the value of input like this:
var value = $('a').attr('rel');
if ( value == '1' || value == '4' || value == '7' || value == '18') {
// however I need the line above are created dynamically based on 'value' var
alert('The id exists');
return false;
} else {
return true;
}
So, the question is how to create a line below dynamically based on anchor 'rel' attribute values?!
This is the line:
if ( value == '1' || value == '4' || value == '7' || value == '18') {
© Stack Overflow or respective owner