BZer0
BZer0

Reputation: 1

Input a jquery sentence in a grails gsp tag

I'm getting multiplecompilation error when I try to use a jQuery sentence in a grails <g:link> tag

var ul = $("#authorList > ul");
ul.append('<li><g:link action="show" controller="author" id="'+$('#authorID').val()+'">+'+$('#authorField').val()+'</g:link></li>')

I'm only getting error with the jquery inside the id="" attribute, with this

ul.append('<li><g:link action="show" controller="author" id="">+'+$('#authorField').val()+'</g:link></li>')

The page is working but I can't get the dynamic links, how it's the correct syntax?


URI: /ComplexTables/book/create Class
org.codehaus.groovy.control.MultipleCompilationErrorsException
Message: startup failed: 19: illegal string body character after dollar sign; solution: either escape a literal dollar sign "\$5" or bracket the value expression "${5}" @ line 19, column 210. l()\'"', 35, it) { return "'+$('#authorI ^ 1 error


Around line 35 of grails-app\views\book_form.gsp

function appendAuthor(ev) {
34:        var ul = $("#authorList > ul");
35:        ul.append('<li><g:link action="show" controller="author" id="'+$('#authorID').val()'">+'+$('#authorField').val()+'</g:link></li>')
36:    }
37:</script>

Upvotes: 0

Views: 266

Answers (1)

RaVns
RaVns

Reputation: 135

I don't know GSP but generally ID can not start with a number.

"Using characters except ASCII letters, digits, '_', '-' and '.' may cause compatibility problems, as they weren't allowed in HTML 4. Though this restriction has been lifted in HTML 5, an ID should start with a letter for compatibility."

And is not it better if you used just DOM getElementById () Method instead of jQuery

ul.append('<li><g:link action="show" controller="author" id="sth_'+document.getElementById('authorID').value+'">+'+document.getElementById('authorID').value+'</g:link></li>')

Upvotes: 1

Related Questions