I have a content type "Students" which has an entity reference field "Course".

Course field shows a list of course nodes titles from a view.

When adding a new student node, I need the course field to be automatically selected as per the URL value.

I will pass the course ID in the URL like this.


Any idea how to get this done ? thanks


3 Answers 3


You could use Entity Reference Prepopulate module

Allow prepopulating any Entity reference field via URL



In order to pre-populate an entity reference field you have to supply the parameter in the URL.

The structure is node/add/article?[field_ref]=[id]

Where [field_ref] is the name of the entity reference field and [id] is the id of the entity being referenced.




  • 1
    this is something what I was looking for. But i already ended up doing it with jquery.
    – brainHax
    Sep 1, 2016 at 14:46

I think the easiest way would be to use hook_form_alter() and set a default value for the field. You can use arg() to get the course ID


Another jQuery quick and dirty way.

jQuery( document ).ready(function($) {

    var the_url  = window.location.href;  
    var nid_from_url = the_url.substr(the_url.lastIndexOf('/') + 1);
    //change the selected value of the select list of courses.
    $('.page-node-add-offline-course-pictures #edit-field-offline-course-reference2-und').val(nid_from_url);

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.