javascript - Fetch a user defined name using jQuery -


need fetch element name using jquery , fetching name value, concatenated samp (variable). cant able form name element. there problem concatenation please help.

$("input[name^='resource_" + samp + "_']") 

full code:

var samp = $(thisval).attr('name');  //user defined name   $("input[name^='resource_" + samp + "_']").each(function(key,val){     alert("calcwk entered");     if ($(this).val() === '') {         theval  = 0;     }     else {         theval = parseint($(this).val());     }     tot = tot + theval;     alert("calcwk exit"); }); 

since cannot sure of format value "samp" contain need make sure value covered right quotes.

$('[property=value]'); 

works have no spaces or anyway selector doesn't instantly know end of property value is, whereas

$('[property=my value]'); 

confuses parser system , such need correctly "escape" or "wrap" value quotes eg:

$('[property="my value"]'); 

here's version of code help

var samp = $(thisval).attr('name'),   //user defined name      tot = 0                           //define total ;  $('input[name^="resource_' + samp + '_"]').each(function(key,val){     var theval = $(this).val(); // jquery call once per item     if (theval === '') {         theval  = 0; // if text change 0     }      tot += parseint(theval); // no need else, parseint     alert("calcwk exit"); }); 

as example, i've created jsfiddle: http://jsfiddle.net/fua9rtjd/


Comments

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -