Note that there are some explanatory texts on larger screens.

plurals
  1. POPassing params from within <g:each> to action specified in createLink within a javascript function, called on clicking <a:> link
    primarykey
    data
    text
    <p>I have a template containing a g:each that renders a set of search results in tabular format as follows:</p> <pre><code>&lt;g:if test="${company}"&gt; &lt;table cellpadding="0" cellspacing="0"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class="small"&gt;&lt;g:message code="Company Name"/&gt;&lt;/th&gt; &lt;th class="medium"&gt;&lt;g:message code="TDCID"/&gt;&lt;/th&gt; &lt;th class="tiny"&gt;&lt;g:message code="STREET"/&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;g:each in="${company}" status="idx" var="PNo"&gt; &lt;tr&gt; &lt;td&gt; &lt;a: href="javascript:void(0)" onClick="javascript:asd();" params="[tdc:PNo.tdcId,companyid:PNo.companyId,companytype:PNo.companyType]"&gt;//params: passing not working now.Have to pass the tdcId,companyId,companyType of clicked result ${PNo.officialName} &lt;/a:&gt; &lt;/td&gt; &lt;td&gt; ${PNo.tdcId} &lt;/td&gt; &lt;td&gt; ${PNo.street} &lt;/td&gt; &lt;/tr&gt; &lt;/g:each&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/g:if&gt; </code></pre> <p>I need to pass tdcId,companyId,companyType contained in company object that is clicked by user to the following JavaScript function:</p> <pre><code>function asd(){ window.open("${g.createLink(controller: 'Customer', action: 'showcontacts',params:'[tdc:company.tdcId,companyid:company.companyId,companytype:company.companyType]')}",'', 'width=200,height=100'); } </code></pre> <p>Here from asd() I need to pass the params to action:'showcontacts' through createLink tag. What is the right way to do this?</p> <p>This is the calling gsp: _customers.gsp:</p> <pre><code>&lt;script type="text/javascript"&gt; function asd(tdcId, companyId, companyType) { alert(tdcId); var link = "${g.createLink(controller: 'Customer', action: 'showcontacts')}?tdc=" + tdcId + "&amp;companyid=" + companyId + "&amp;companytype=" + companyType; window.open(link, '', 'width=200,height=100'); } &lt;/script&gt; &lt;div class="form-edit"&gt; &lt;div class="heading"&gt; &lt;strong&gt; &lt;g:message code="Firm Profile"/&gt; &lt;/strong&gt; &lt;/div&gt; &lt;div id="hai" class="form-hold"&gt; &lt;g:form name="company-edit-form" action="save"&gt; &lt;fieldset&gt; &lt;div class="form-columns"&gt; &lt;div class="column"&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Company Name"/&lt;/content&gt; &lt;content tag="label.for"&gt;Company&lt;/content&gt; &lt;g:textField class="field" name="Company" id="Company" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/checkbox"&gt; &lt;content tag="label"&gt;&lt;g:message code="Starts with"/&lt;/content&gt; &lt;content tag="label.for"&gt;Starts with&lt;/content&gt; &lt;g:checkBox class="cb checkbox" name="StartsWith" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Street"/&gt;&lt;/content&gt; &lt;content tag="label.for"&gt;Street&lt;/content&gt; &lt;g:textField class="field" name="Street" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/checkbox"&gt; &lt;content tag="label"&gt;&lt;g:message code="Starts with"/&lt;/content&gt; &lt;content tag="label.for"&gt;Starts With&lt;/content&gt; &lt;g:checkBox class="cb checkbox" name="StreetStartsWith"/&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Zip code"/&gt;&lt;/content&gt; &lt;content tag="label.for"&gt;Zip&lt;/content&gt; &lt;g:textField class="field" name="ZipCode"/&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Fagrubrik"/&lt;/content&gt; &lt;content tag="label.for"&gt;Fagrubrik&lt;/content&gt; &lt;g:textField class="field" name="Fagrubrik" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="House no."/&lt;/content&gt; &lt;content tag="label.for"&gt;HouseNo&lt;/content&gt; &lt;g:textField class="field" name="HouseNo" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Tel./Fax."/&lt;/content&gt; &lt;content tag="label.for"&gt;Telephone&lt;/content&gt; &lt;g:textField class="field" name="Telephone" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Company No."/&lt;/content&gt; &lt;content tag="label.for"&gt;CompanyNo&lt;/content&gt; &lt;g:textField class="field" name="CompanyNo" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="City"/&gt;&lt;/content&gt; &lt;content tag="label.for"&gt;City&lt;/content&gt; &lt;g:textField class="field" name="City" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="TDC ID"/&gt;&lt;/content&gt; &lt;content tag="label.for"&gt;TdcId&lt;/content&gt; &lt;g:textField class="field" name="TdcId" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Industry Designation"/&gt;&lt;/content&gt; &lt;content tag="label.for"&gt;Industry Designation&lt;/content&gt; &lt;g:textField class="field" name="IndustryDesignation" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Decision Maker"/&lt;/content&gt; &lt;content tag="label.for"&gt;DecisionMaker&lt;/content&gt; &lt;g:textField class="field" name="DecisionMaker" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="Email"/&gt;&lt;/content&gt; &lt;content tag="label.for"&gt;Email&lt;/content&gt; &lt;g:textField class="field" name="Email" /&gt; &lt;/g:applyLayout&gt; &lt;g:applyLayout name="form/input"&gt; &lt;content tag="label"&gt;&lt;g:message code="WWW"/&gt;&lt;/content&gt; &lt;content tag="label.for"&gt;WWW&lt;/content&gt; &lt;g:textField class="field" name="WWW"/&gt; &lt;/g:applyLayout&gt; &lt;/div&gt; &lt;/div&gt; &lt;div&gt; &lt;br/&gt;&amp;nbsp; &lt;/div&gt; &lt;div id="button" class="buttons"&gt; &lt;ul&gt; &lt;li&gt; &lt;g:submitButton class="buttons" id="button" name="Search" value="Search" action="search"/&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt; &lt;/fieldset&gt; &lt;/g:form&gt; &lt;div class="table-box"&gt; &lt;g:if test="${company}"&gt;&lt;table cellpadding="0" cellspacing="0"&gt; &lt;thead&gt; &lt;tr&gt; &lt;th class="small"&gt;&lt;g:message code="Company Name"/&gt;&lt;/th&gt; &lt;th class="medium"&gt;&lt;g:message code="TDCID"/&gt;&lt;/th&gt; &lt;th class="tiny"&gt;&lt;g:message code="STREET"/&gt;&lt;/th&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;tbody&gt; &lt;g:each in="${company}" status="idx" var="PNo"&gt; &lt;tr&gt; &lt;td&gt; &lt;a href="javascript:void(0)" onClick="javascript:asd('${PNo.tdcId}','${PNo.companyId}', '${PNo.companyType}');"&gt;${PNo.officialName}&lt;/a&gt; &lt;/td&gt; &lt;td&gt; &lt;g:remoteLink action="show" id="${PNo}" before="register(this);" onSuccess="render(data, next);" params="[template:'show']"&gt; ${PNo.tdcId} &lt;/g:remoteLink&gt; &lt;/td&gt; &lt;td&gt; ${PNo.street} &lt;/td&gt; &lt;/tr&gt; &lt;/g:each&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;/g:if&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This is the called one for test purposes.named _showcontacts.gsp:</p> <pre><code> &lt;body&gt; &lt;div id="dialog" title="Contacts"&gt; hai &lt;/div&gt; &lt;/body&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload