• Resolved fibbu

    (@fibbu)


    Hello;
    A question stuck in my head, actually I am logical, but I will succeed with this logic.

    Now I am trying to calculate distance measurement between 3 places.

    I created 2 dropdown fields. There are the same 3 places in both dropdowns.
    1) 1st Place
    2) 2nd Place
    3) 3nd Place
    shaped;

    I found a method to write the distances between these 3 places in the result, but I think I’m making a small mistake..

    (function() {
    	var mesafe;
         var s1 = fieldname29;
         var s2 = fieldname30;
         var mesafe = aMesafe[s1][s2];
    
    var aMesafe = [
    [0,150,170],
    [160,0,150],
    [170,160,0],
    ];
    
    
        jQuery('#calculation-mesafe').html(mesafe);
        jQuery('.criter3-one').html('Mesafe: ');
        jQuery('.criter3-two').html(mesafe);
    
        return mesafe;
      })();

    The code is exactly what it should do;
    If s1 is selected;

    If the 2nd value in the 1st dropdown field is selected
    [160,0,150], this part will take into account..

    If the 1st value in the 2nd dropdown field is selected
    [0,150,170], this part will be considered

    This is actually a calculation method between cities.. I couldn’t get it to work..

    I’m leaving a codepen link for you, it’s a working Java version.

    Where am I making a mistake in the coding part in this plugin..

    Thanks a lot..

    Codepen Link


Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @fibbu

    In the coding process, it is important the order of the lines of code.

    In the following piece of code:

    
    var mesafe = aMesafe[s1][s2];
    
    var aMesafe = [
    [0,150,170],
    [160,0,150],
    [170,160,0],
    ];

    The variable mesafe is trying to access information that has not been defined aMesafe[s1][s2]

    So, the correct would be:

    
    var aMesafe = [
    [0,150,170],
    [160,0,150],
    [170,160,0],
    ];
    
    var mesafe = aMesafe[s1][s2];

    Best regards.

    Thread Starter fibbu

    (@fibbu)

    (function() {
    	var mesafe;
         var s1 = fieldname29;
         var s2 = fieldname30;
    
    var aMesafe = [
    [0,337,578],
    [337,0,915],
    [578,915,0],
    ];
    
    var mesafe = aMesafe[s1][s2];
    
        jQuery('#calculation-mesafe').html(mesafe);
        jQuery('.kriter3-aciklama').html('Mesafe: ');
        jQuery('.kriter3-sonuc').html(mesafe);
    
        return mesafe;
      })();

    yes, the result is written. Thank you very much..

    But there is one last little problem, I am amazed by the plugin, it does everything.
    Now I am exemplifying;

    When fieldname29 dropdown 01 value is selected;
    When fieldname30 dropdown 02 value is selected;

    According to these rules;
    var aDistance = [
    [0,337,578],
    [337,0,915],
    [578,915.0],
    ];

    In other words, it takes the number 915, while it should take 1 row 2nd cell.
    Do you have an idea?

    I defined cell values as 01 02 03.

    Thanks.

    Thread Starter fibbu

    (@fibbu)

    I solved the problem thanks.

    var mesafe = aMesafe[s1 – 1][s2 – 1];

    Plugin Author codepeople

    (@codepeople)

    Excellent !!!!!

    Best regards.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘distance between 2 places’ is closed to new replies.