0

I am trying to add controls dynamically using javascript add button. It is working fine with simple strings in javascript as follows:

 var input="";
 input2 = "<select name='parameterUniversity["+ updated_row_num +"]' id='ddl_university'>";
 for(i=0;i<10<i++)
    input += "<option  value='"+i+"'>" + i + "</option>";
 input+="</select>"; 

but when i try to use

 var input="";
 input = "<select name='parameterUniversity["+ updated_row_num +"]' id='ddl_university'>";
 <% @Universites.each_with_index do |u| %>
    input += "<option text='" +<%= u.University %>+ "' value='" + <%= u.id %> + "'>" + <%= u.University %> + "</option>";
 <% end %>  
 input+="</select>"; 

it submits the page when i click on Add button, please let me know what i have done wrong. it should work as we are replacing simple string with this server type string.

Edit Error in console is

SyntaxError: missing ; before statement

i am unable to locate this error

Regards.

4
  • change the input type from submit to button and click the add button and observe the JavaScript error in console and post the error too. Commented Oct 14, 2014 at 9:21
  • is there any error marked in your script-let? Commented Oct 14, 2014 at 9:43
  • Some tips that probably doesn't fix your main issue but you should also fix. You should use @Universites.each do |u|, also the first letter on a variable as capital is wrong, it should be @universites and lastly the plural for university is universities. Commented Oct 14, 2014 at 9:48
  • Thanks @NishadNichoos problem was with concatenation and trailing white spaces. i actually took gap of 2-3 months from RoR and this was the result. Thanks again guys :) Commented Oct 14, 2014 at 10:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.