I'm using jquery for adding fields to a form, "repeatable" fields with "add more" button
The code is
$(".add-attacker-scores").click(function() {
count = count + 1;
$('#atacker_score_items').append('<li><span class="sort hndle"><label>team :<input type="text" name="attacker_scores[' + count + '][team]" size="30" value=""/></label><label>flags :<input type="text" name="attacker_scores[' + count + '][flags]" size="10" value=""/></label><label>phone homes :<input type="text" name="attacker_scores[' + count + '][phone]" size="10" value=""/></label><label>Injects :<input type="text" name="attacker_scores[' + count + '][injects]" size="10" value=""/></label><span class="remove">Remove</span></li>');
var temp = <? echo implode('',explode("\n",Print_attacker_scores('count') )); ?>;
temp = temp.replace(/count/g, count);
$('#atacker_score_items').append(temp);
return false;
});
The code for Print_attacker_scores is
function Print_attacker_scores($cnt, $p = null) {
if ($p === null){
$a = $b = $c = $d = '';
}else{
$a = $p['team'];
$b = $p['flags'];
$c = $p['phone'];
$d = $p['injects'];
}
return <<<HTML
<li><span class="sort hndle"></span>
<label>team :
<input type="text" name="attacker_scores[$cnt][team]" size="30" value="$a"/>
</label>
<label>flags :
<input type="text" name="attacker_scores[$cnt][flags]" size="10" value="$b"/></label>
<label>phone homes :
<input type="text" name="attacker_scores[$cnt][phone]" size="10" value="$c"/></label>
<label>injects :
<input type="text" name="attacker_scores[$cnt][injects]" size="10" value="$d"/></label>
<span class="remove">Remove</span>
</li>
HTML
;
}
In firefox its working but in chrome it doesn't work.
Then i realized that it throws an error: NS_ERROR_XPC_BAD_CONVERT_JS: Could not convert JavaScript argument arg 0 [nsIDOMDocumentFragment.appendChild]
Why is happening this? I've copied the code from around the web but i can fix it because i don't understand this lines:
var temp = <? echo implode('',explode("\n",Print_attacker_scores('count') )); ?>;
temp = temp.replace(/count/g, count);
so this is reading the html generated by the Print_scores_function and creating an array with each line.Then generates a string with all the items in the array. Then replaces the count number¿? i don't understand why it is doing this. Maybe there's a another way of doing it more simple?
(/count/g, count) is a regular expression?
What am i doing wrong?
` or `
`?
– andyb Nov 26 '12 at 16:31– Oterox Nov 26 '12 at 16:36