Skip to main content
deleted 12 characters in body
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1?

alert('1a = ' + id_'+id_('post_url').value.indexOf('http:') );//    ); // 0
alert('1b'   '1b += id_'+id_('post_url').value.indexOf('http:') > -1); // false
alert('2a = ' + id_'+id_('post_url').value.indexOf('www.') );//     ); // 7
alert('2b'   '2b += id_'+id_('post_url').value.indexOf('www.')  > -1); //  false

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1?

alert('1a = ' + id_('post_url').value.indexOf('http:')     ); // 0
alert('1b'    + id_('post_url').value.indexOf('http:') > -1); // false
alert('2a = ' + id_('post_url').value.indexOf('www.')      ); // 7
alert('2b'    + id_('post_url').value.indexOf('www.')  > -1); // false

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1?

alert('1a = '+id_('post_url').value.indexOf('http:'));//      0
alert('1b = '+id_('post_url').value.indexOf('http:') > -1);// false
alert('2a = '+id_('post_url').value.indexOf('www.'));//       7
alert('2b = '+id_('post_url').value.indexOf('www.') > -1);//  false
Notice removed Content dispute by CommunityBot
Post Unlocked by CommunityBot
Post Locked by animuson
Notice added Content dispute by animuson
Rollback to Revision 17
Source Link
animuson
  • 54.5k
  • 28
  • 141
  • 149

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1-1?

alert('1a = '+id_' + id_('post_url').value.indexOf('http:')     ); //returns 0
 
alert('1b'+id_'1b'    + id_('post_url').value.indexOf('http:') > -1); //returns false
 
alert('2a = '+id_('post_url').value.indexOf('www.'));//returns 7

alert('2b'+id_+ id_('post_url').value.indexOf('www.')>-1      ); //returns false7

In order to have both a string and a boolean alerted adding a second set of parenthesis as scragar suggested works...

alert('1b'2b' = '+(  + id_('post_url').value.indexOf('http:'www.')  > -1)); //returns 1b = truefalse

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1?

alert('1a = '+id_('post_url').value.indexOf('http:'));//returns 0
 
alert('1b'+id_('post_url').value.indexOf('http:')>-1);//returns false
 
alert('2a = '+id_('post_url').value.indexOf('www.'));//returns 7

alert('2b'+id_('post_url').value.indexOf('www.')>-1);//returns false

In order to have both a string and a boolean alerted adding a second set of parenthesis as scragar suggested works...

alert('1b = '+(id_('post_url').value.indexOf('http:')>-1));//returns 1b = true

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1?

alert('1a = ' + id_('post_url').value.indexOf('http:')     ); // 0
alert('1b'    + id_('post_url').value.indexOf('http:') > -1); // false
alert('2a = ' + id_('post_url').value.indexOf('www.')      ); // 7
alert('2b'    + id_('post_url').value.indexOf('www.')  > -1); // false
Rollback to Revision 16
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1-1?

alert('1a = ' + id_'+id_('post_url').value.indexOf('http:')     ); //returns 0 

alert('1b'    + id_'1b'+id_('post_url').value.indexOf('http:') > -1); //returns false 

alert('2a = ' + id_'+id_('post_url').value.indexOf('www.')      ); //returns 7 

alert('2b'    + id_'2b'+id_('post_url').value.indexOf('www.')>-1);//returns false

In order to have both a string and a boolean alerted adding a second set of parenthesis as scragar suggested works...

alert('1b >= '+(id_('post_url').value.indexOf('http:')>-1)); //returns false1b = true

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1?

alert('1a = ' + id_('post_url').value.indexOf('http:')     ); // 0
alert('1b'    + id_('post_url').value.indexOf('http:') > -1); // false
alert('2a = ' + id_('post_url').value.indexOf('www.')      ); // 7
alert('2b'    + id_('post_url').value.indexOf('www.')  > -1); // false

The value of the field with the id 'post_url' is http://www.example.com/. Shouldn't JavaScript return true for anything greater than -1?

alert('1a = '+id_('post_url').value.indexOf('http:'));//returns 0 

alert('1b'+id_('post_url').value.indexOf('http:')>-1);//returns false 

alert('2a = '+id_('post_url').value.indexOf('www.'));//returns 7 

alert('2b'+id_('post_url').value.indexOf('www.')>-1);//returns false

In order to have both a string and a boolean alerted adding a second set of parenthesis as scragar suggested works...

alert('1b = '+(id_('post_url').value.indexOf('http:')>-1));//returns 1b = true
Rollback to Revision 15
Source Link
Cerbrus
  • 72.1k
  • 19
  • 135
  • 149
Loading
Rollback to Revision 14
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188
Loading
Notice removed Content dispute by CommunityBot
Post Unlocked by CommunityBot
Post Locked by Andrew Barber
Notice added Content dispute by Andrew Barber
Rollback to Revision 13
Source Link
Cerbrus
  • 72.1k
  • 19
  • 135
  • 149
Loading
deleted 30 characters in body
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188
Loading
Rollback to Revision 8 - Stop messing with the formatting. The bold "Returns" statements are an eyesore, and the extra newlines are nor helping anyone determine what's actually returning the values. Instead of adding the answer to your question, just accept the right answer.
Source Link
Cerbrus
  • 72.1k
  • 19
  • 135
  • 149
Loading
Rollback to Revision 10
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188
Loading
Rollback to Revision 9
Source Link
Cerbrus
  • 72.1k
  • 19
  • 135
  • 149
Loading
Rollback to Revision 7
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188
Loading
[Edit removed during grace period]
Source Link
Cerbrus
  • 72.1k
  • 19
  • 135
  • 149
Loading
Rollback to Revision 6
Source Link
Cerbrus
  • 72.1k
  • 19
  • 135
  • 149
Loading
added 231 characters in body
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188
Loading
deleted 50 characters in body
Source Link
Cerbrus
  • 72.1k
  • 19
  • 135
  • 149
Loading
added 36 characters in body
Source Link
John
  • 13.5k
  • 13
  • 107
  • 188
Loading
Rollback to Revision 2
Source Link
user229044
  • 237.1k
  • 41
  • 341
  • 342
Loading