Announcement Announcement Module
Collapse
No announcement yet.
Session map & javascript Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Session map & javascript

    I have a select box which lists instructors full names (from a session
    variable: session.eligibleInstructor, created in the LoginController
    from a query of a view that returns fullname and email, so
    session.eligibleInstructors.FULLNAME returns the fullname and
    session.eligibleInstructors.EMAIL returns the email, session.eligible
    Instructors returns both:

    def eligibleInstructors = dbConnection.rows("select FULLNAME, EMAIL
    from zV_eligibleInstructors ORDER BY LASTNAME")
    println(eligibleInstructors)
    [[FULLNAME:Berg, Douglas, EMAIL:[email protected]], [FULLNAME:Askov,
    Michael, EMAIL:[email protected]], [FULLNAME:Abba, Jasmine,
    EMAIL:[email protected]], ...


    I want to update a textfield with the selected instructors email
    address when the instructor is selected in the selectbox. I know my
    javascript is capturing the selected instructor (because I did an
    "alert"):

    $('#inst2Select').change(function(event){
    $('#emailInst2').load('/edu.wit.nonac/nonAcadCourse/create/updateSelect',
    {
    selectedInst: $(event.target).val()
    },
    function() {alert($(event.target).val())
    }

    but my controller action (updateSelect) is not doing anything:

    def updateSelect = {

    println("UpdateSelect reached")

    println("Params: " + params.any())
    def selectedInstEmail = dbConnection.firstRow("select EMAIL
    from zV_eligibleInstructors where FIRSTNAME=?",
    [params.selectedInst])
    println(selectedInstEmail)
    render selectedInstEmail


    }

    I have tried multiple ajax-type callbacks , even a remoteFunction in
    the "onchange"event. I realize I should haven't to go back to the
    database to get the selected Instructors email because it's already
    avilable in the session variable eligibleInstructors, but how do I
    access the EMAIL value using the FULLNAME as the key? Do I even need
    to use Ajax for this? What is the "best practice? I have looked at
    hundreds of webpages for the answer but none seems to quite touch on
    this exact issue. Even if I could just get the controller action to
    fire, that would be a huge step forward. Do you have any suggestion on
    how to achieve this? Any suggestions will be greatly appreciated.
Working...
X