Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a list named "Assigning to Individual" which has a drop down 'Initial Training'

The values in the drop down are Immediate, Hire Date, Specific. There is another textbox Date

There is a listbox which contains employee name.

There is another list "Employees" which contains Employee name and Hire Date.

The scenario is when the user selects hire date in the drop down in "Assigning to Individual", and selects employee name from the listbox, then the text box should populate based on the Employees list.

I have got the code using drop down but I do not know how to get the listbox selected value. If somebody could show the changes required in my code

    $(document).ready(function () {
    var currentPage = decodeURIComponent(window.location.href.replace(/\+/g, " "));
    var result = null;
    if (currentPage.contains("Assigning to Individual")) {

        var dropdown = $("select[title = 'Initial Training']");
        var dropdownid = dropdown[0].id;
        if (dropdown.length != 0) {
            populateCourseAssignment(dropdown, dropdownid)

            $('#' + dropdownid).change(function () {
                onChangeValueDropDown(dropdownid);
            });
        }

    }

});



function populateCourseAssignment(dropdown, dropdownid) {
    //var dropdown = $("select[title = 'Course Name']");
    if (dropdown.length != 0) {
        var selectedtext = $('#' + dropdownid + ' option:selected').text();
        if (selectedtext == "Hire Date")
        result = getCourseAssignment("Initial Training", selectedtext);
        fillValuesInCourseAssignment();

    }
}

function fillValuesInCourseAssignment() {
    $("input[title = 'Date']").val(result[0].Hire_x0020_Date);
    //    $("input[title = 'Instructor Name']").val(result[0].Instructor);


}


function onChangeValueDropDown(dropdownid) {
    var currentvalue = $('#' + dropdownid + ' :selected').text();
    {
        if (currentvalue == "Hire Date")
        result = getCourse("Course_x0020_Title", currentvalue);
        fillValuesInTrainingStatus();

    }
}
function getCourseAssignment(whereColumnName, whereColumnValue) {

    var CAMLQuery = '<Query><Where><Eq><FieldRef Name="' + whereColumnName + '" /><Value Type="Text">' + whereColumnValue + '</Value></Eq></Where></Query>';

    // var CAMLQuery = '<Query><Where><Eq><FieldRef Name="' + whereColumnName + '" /><Value Type="Text">' + whereColumnValue + '</Value></Eq></Where></Query>';
    var course;
    $().SPServices({
        operation: "GetListItems",
        async: false,
        listName: "Course Details",
        CAMLQuery: CAMLQuery,
        CAMLViewFields: "",
        completefunc: function (xData, Status) {
            //            $(xData.responseXML).SPFilterNode("z:row").each(function () {
            //                wizardId = getData($(this).attr("ows_" + returnColumnName));
            //            });
            course = $(xData.responseXML).SPFilterNode("z:row").SPXmlToJson({
                includeAllAttrs: true,
                removeOws: true
            });
        }
    });

    return course;
}
share|improve this question

2 Answers 2

up vote 0 down vote accepted

In your onChangeValueDropDown function change this line

 var currentvalue = $('#' + dropdownid + ' :selected').text();

To what you have in populateCourseAssignment:

var currentvalue = $('#' + dropdownid + ' option:selected').text();

Also, remove the uneccessary curly braces in the onChangeValueDropDown function. So the final will be:

function onChangeValueDropDown(dropdownid) {
    var currentvalue = $('#' + dropdownid + ' option:selected').text();
    if (currentvalue == "Hire Date")
    result = getCourse("Course_x0020_Title", currentvalue);
    fillValuesInTrainingStatus();
}

Lastly, I notice you are using SPServices. Why not use their Cascading dropdowns function?

share|improve this answer
    
Also, the last to lines in the function above will require curly braces if the fillValuesInTrainingStatus() function shud only be called when currentvalue is "Hire Date" –  Realistic Feb 26 at 21:40
var selectedtext = $('#' + dropdownid).val();

...

var currentvalue = $('#' + dropdownid).val();
share|improve this answer
    
Hi thanks for responding. tMine is a listbox. –  user3008273 Feb 21 at 7:08
    
By list box I would suspect <select><option></option></select>, like jsfiddle.net/HZ3fB –  eirikb Feb 21 at 7:13
    
This listbox was added in sharepoint through javascript if (currentPage.contains("Lists/Assigning to Individual/NewForm.aspx")) { AddNewLinkOnLookupFields("Personnel", "/Lists/Employee/NewForm.aspx", "Add New Employee"); –  user3008273 Feb 21 at 7:16
    
I don't think comment is a good place to dump code, please use a pastebin such as gist.github.com . I can't derive anything from your dump either, only more proof that you have a select element, and as long as each option has value my code should work. You could extract the exact HTML and append it to the fiddle –  eirikb Feb 21 at 7:25
    
Could you help me out I am not getting an idea as I am clueless about javascript, i need drop down as well , the code which you gave where should I add it –  user3008273 Feb 21 at 10:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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