Note that there are some explanatory texts on larger screens.

plurals
  1. PORails 3: error while passing params to javascript function
    primarykey
    data
    text
    <p>I am trying to pass value to the JavaScript function but it gives me the below error on Firebug when I click the anchor tag (plus icon). </p> <p>What I am trying to do is, on click of a 'plus' sign, I add fields from partial to the table. What am I doing wrong here?</p> <p>Currently there is a table with '+' inside <code>&lt;th&gt;</code>. I want to append data(from the partial) to the table.</p> <p><strong>Error</strong></p> <pre><code>SyntaxError: syntax error [Break On This Error] add_fields(this, contact, &amp;quot;&amp;lt;tr class=\&amp;#x27;fields\&amp;#x27;&amp;gt;\n&amp;lt;td&amp;gt... </code></pre> <p><strong>Helper file</strong></p> <pre><code>module TestHelper def add_fields(name, obj) if (obj == 'contact') fields = render :partial =&gt; '/test/add_fields', :locals =&gt; {:map_values =&gt; ["Name", "URL", "Address"]} link_to_function(name, h("add_fields(this, #{obj}, \"#{escape_javascript(fields)}\")")) elsif (obj=='company') fields = render :partial =&gt; '/test/add_fields', :locals =&gt; {:map_values =&gt; ["CName", "CURL", "CAddress"]} link_to_function(name, h("add_fields(this, #{obj}, \"#{escape_javascript(fields)}\")")) elsif (obj=='lead') fields = render :partial =&gt; '/test/add_fields', :locals =&gt; {:map_values =&gt; ["LName", "LURL", "LAddress"]} link_to_function(name, h("add_fields(this, \"#{obj}\", \"#{escape_javascript(fields)}\")")) end end end </code></pre> <p><strong>View file</strong></p> <pre><code>=add_fields 'Add', 'contact' </code></pre> <p><strong>partial _add_fields.html.haml</strong></p> <pre><code>%tr.fields %td %select{:class =&gt; 'select-two'} - map_values.each do |e| %option #{e} </code></pre> <p><strong>js file</strong></p> <pre><code>add_fields = function(obj, maptype, content){ //console.log(obj.closest('.table')); var parent = $(obj).closest('.table'); var msg_obj = $('.alert.alert-info',parent); if(msg_obj.length &gt; 0) { msg_obj.closest('tr').addClass('hidden'); } $('tbody',parent).append(content); $("select.select-two").select2({allowClear: true}); }; </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.
    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