2
votes

I'm using Grails 1.3.7 and jQuery Mobile. I need to execute the following Javascript to initialize a select for a specific page but firebug confirms that this code is not being included when the page is rendered even though g:layoutHead in the layout is rendering the meta and title tags that are also in the head for this page.

<g:javascript>
    var zselect = document.getElementById('tee')
    var zopt = zselect.options[zselect.selectedIndex]
</g:javascript>

Any idea why the script is not being rendered?

The head of my layout has the jQuery and jQuery Mobile includes as well as the jQuery UI datepicker and fluid960. Here's the end of the layout head:

    <g:layoutHead/>
</head>

Here's the head of the view from which the meta and title tags are rendered but not the javascript.

<head>
  <g:javascript>
    var zselect = document.getElementById('tee')
    var zopt = zselect.options[zselect.selectedIndex]
  </g:javascript>
  <meta name="layout" content="main">
  <g:set var="entityName" value="${message(code: 'foursome.label', default: 'Foursome')}"/>
  <title><g:message code="default.create.label" args="[entityName]"/></title>
</head>
2

2 Answers

0
votes

Maybe its in your <head> section of the GSP, but your layout doesn't have a <g:layoutHead/> tag?

Checkout the Layout documentation for more info.

0
votes

If you look in the rendered html, is the Javascript there?

If it is, I think your problem is, that you try to reference objects on in you DOM from the header, before the DOM is rendered. You would have to move your initialization code to the bottom of your GSP, to make sure that the entire DOM is loaded. Or, you could use the onLoaded feature of jQuery.