Problem to get value into javascript variable ?

  • 27 November 2015
  • 1 reply
  • 8 views

Badge +6

Hello everyone,

 

 

Like the post title said, I want to get just the text from my list lookup drop down.

1.JPG

If I have this, I want to get in a JS variable : "Please select a value..."

 

 

I set up the list lookup like this :

2.JPG

 

I want to store the choice into JS variable with the following code :

 

NWF$("#" + Idselect_sitescodes).change(function ()

{

        var siteCodeSelectedItem = NWF$(this).find("#" + Idselect_sitescodes + " option:selected").html();

        alert("siteCodeSelectedItem : " + siteCodeSelectedItem);

});

 

How can I fix the fact that, when I want to check the value of my variable siteCodeSelectedItem, I have a message like 'Undefined' ?

3.JPG

 

Thanks

Theo


1 reply

Badge +6

Thx ! I 've already found but I don't have time to post my solution and it seems the same :

I used  code in a JS file upload in style librarie (with Sharepoint Designer) and include in my form like "Form setting" > "Advanced">"Custom Javascript Includes" :

../../Style Library/MyCustomJSFile.js

My JS file looks like this :

//********************************************************/

//****                  MAIN FUNCTIONS                ****/ 

//********************************************************/

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

    // Définition des variables passées en paramètre

    var varSelectedSiteCode = NWF$(".select_sitescodes option:selected").html();

    //Appel de la fonction

    getSiteCode(varSelectedSiteCode);

});

//**********************************************************/

//****        Get data from NMF (SitesCodes)            ****/

//**********************************************************/

function getSiteCode(in_siteref)

{

    var siteUrl = "http://blablabla/";

    var restQuery = siteUrl + "_vti_bin/listdata.svc/ListFromAnotherSite?$select=SiteRef,SiteCode&$filter=SiteRef eq '" + in_siteref + "'";

    $.ajax({

        url: restQuery,

        dataType: "json",

        success: function (data) {

            /*if (NWF$(data.d.results).length == 0) {

             alert("Erreur");

             }*/

            NWF$(data.d.results).each(function () {

                NWF$('.MySiteCode').val(this.SiteCode).focus();

                //alert("siteCode : "+SiteCode);

            });

        },

        error: function (data) {

            alert("Error");

        }

    });

    NWF$(".select_sitescodes").change(function () {

        var siteCodeSelectedItem = NWF$(this).find(":selected").html();

        getSiteCode(siteCodeSelectedItem);

    });

}

I have change class : Idselect_sitescodes => .select_sitescodes

I hope this post can help someone !

Thx Ragnesh

BR

Théo

Reply