0

I have a little bit trouble with this code:

var elem = $(this);
var bookID = elem.attr('data-bid');
var anzahl = $('#ctEdit'+bookID).val;
alert (anzahl);

HTML:

<input type="text" id="ctEdit<?php echo $row2c[0]; ?>" name="ctEdit<?php echo $row2c[0]; ?>"  >

The output is generated correctly. The IDs are named like this: #ctEdit1, #ctEdit2 etc.

A alert(bookID) shows the correct ID. The problem is with this line:

var anzahl = $('#ctEdit'+bookID).val;

A alert (anzahl) gives a huge message:

function (a){var b,c,d,e=this[0];{if(arguments.length)return d=n.isFunction(a),this.each(function(c){var e;1===this.nodeType&&(e=d?a.call(this,c,n(this).val()):a,null==e?e="":"number"==typeof e?e+="":n.isArray(e)&&(e=n.map(e,function(a){return null==a?"":a+""})),b=n.valHooks[this.type]||n.valHooks[this.nodeName.toLowerCase()],b&&"set"in b&&void 0!==b.set(this,e,"value")||(this.value=e))});if(e)return b=n.valHooks[e.type]||n.valHooks[e.nodeName.toLowerCase()],b&&"get"in b&&void 0!==(c=b.get(e,"value"))?c:(c=e.value,"string"==typeof c?c.replace(bb,""):null==c?"":c)}}

What can it be?

DragonStyle
  • 145
  • 11

1 Answers1

3

Nothing to do with your dynamic IDs; you just need val(), not .val.

One invokes the method, another merely references it.

See: What is the difference between a function call and function reference?

Community
  • 1
  • 1
Mitya
  • 33,629
  • 9
  • 60
  • 107