Hey Guys i am trying to populate dynamic fields in groovy GSP by using javascript and Groovy markup
*Here's the Effort 1 ->Works fine using plain html *
<r:script>
function createField()
{
var variable=0;
var d="<input type='text' name='item["+variable+"]' id='item["+variable+"]'/>";
reutrn d;
}
</r:script>
*Here's the Effort 2 ->JavaScript Error while using Groovy tags *
<r:script>
function createField()
{
var variable = 0;
var d = "<g:textField name='item["+variable+"]' id='item["+variable+"]' />";
return d;
}
</r:script>
By Using above function browser ends up with the error :javascript uncaught syntaxerror unexpected token illegal
So i decided to encode the tag using Grails InLine codec encodeAs="JavaScript".
*Here's the Effort 3 ->Error using Groovy tags *
y<r:script>
function createField()
{
var variable=0;
var d="<g:textField name='item["+variable+"]' id='item["+variable+"]' encodeAs="JavaScript"/>";
return d;
}
</r:script>
Problem with the third effort while encoding the tags, quotes besides the variable are also encoded so the output is something like u003b+variable+\u0026#39, this makes the nonidentical form fields which are unable to process further.
Any help will be appreciated.
Effort 1. i don't think you gain much by usingg:textField- aldrin