2

Hi I am attempting to run a create.js.erb file when a user creates a record inside a RoR app.

Here is the jquery:

$('input[id=bizid]').val("<%= @branch.business_id %>");
$('input[id=braid]').val("<%= @branch.id %>");

Here is the view:

<input style="display:none;" id="bizid" name="bizid" value="" />
<input style="display:none;" id="braid" name="braid" value="" />

I have also tried this:

$('#bizid').val("<%= @branch.business_id %>");
$('#braid').val("<%= @branch.id %>");

<input type="hidden" id="bizid" name="bizid" value="">
<input type="hidden" id="braid" name="braid" value="">

I know that the machinery is working because I use @branch to update another text input field in the same form, without any issue. Also, I checked the DB and the above values for @branch do exist, and should be ready to pass.

Thanks!

EDIT:

alert("<%= @branch.business_id %>");
alert("<%= @branch.id %>");

The above (placed in create.js.erb) results in the correct id #s in two alert dialogs.

7
  • Have you tried hard coding it: $('#bizid').val('my id'); to see if that works? Commented Jun 5, 2012 at 20:39
  • 1
    are you wrapping your code in $(document).ready(function(){/*yourcode*/}); Commented Jun 5, 2012 at 20:39
  • @Diodeus his example has unique id's. Commented Jun 5, 2012 at 20:39
  • 1
    Is this a simplified version of your code? Because if not, why use JS at all? Commented Jun 5, 2012 at 20:40
  • Have you tried using text fields (for these fields) to see what happens? Commented Jun 5, 2012 at 20:41

2 Answers 2

1

Have you tried this?

$('#bizid').val("<%= @branch.business_id %>");
$('#bizid').val("<%= @branch.id %>");
Sign up to request clarification or add additional context in comments.

Comments

0

Make sure your code is in the document ready function:

$(function(){

   /** YOUR CODE **/

});

Also make sure that all of you id's are unique.

1 Comment

Thanks Neal. I tried this, but unfortunately still no luck. See my edit above. The data is there.

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.