Google Script Mapping

I was trying to use mapping on Google Script to enter a value on the City (id="city") field and show the Price (id="price") with the script below. The code below doesn’t work and didn’t provide any result on the price textbox. Moreover, would it be possible to do a multiple conditions? I mean the price will be displayed base on the City, Products, and Quantity. I have provided the image below. Thanks!

  <script>
 
    document.getElementById("btn").addEventListener("click",getPrice);

    function getPrice(){
      vCity = document.getElementById("city").value;
      google.script.run.withSuccessHander(updatePrice).getAmount(vCity);

    }

    function updatePrice(myprice) {
      document.getElementById("price").value = myprice;
    }

  </script>

Here’s my gs.

function doGet(e) {
  return HtmlService.createHtmlOutputFromFile("page");
}


function getAmount(city) {
  var ss = SpreadsheetApp.openByUrl("https://docs.google.com/spreadsheets/d/1FhWlaXixXPxq8EnHICfVR207aIkxtkzOgvdvt3hHuuI/edit#gid=0");
  var ws = ss.getSheetByName("Pricing");
  var data = ws.getRange(1, 1, ws.getLastRow(),2).getValues();

  var cityList = data.map(function(r){ return r[0]; });
  var priceList = data.map(function(r){ return r[1]; });
  var position = cityList.indexOf(city);

  if(position > -1){
    return priceList[position];
  } else {
    return "Unavailable";
  }

image

135 thoughts on “Google Script Mapping”

  1. Pingback: cloud bread keto
  2. I do agree with all of the ideas you have offered to your post.
    They’re very convincing and will certainly work.

    Still, the posts are too short for beginners. May just
    you please lengthen them a bit from subsequent time?

    Thanks for the post.

    Reply
  3. I blog often and I truly thank you for your content.

    This great article has really peaked my interest.

    I am going to take a note of your site and keep checking
    for new information about once a week. I opted in for your RSS feed as well.

    Reply
  4. Hello would you mind letting me know which web host you’re working with?
    I’ve loaded your blog in 3 different internet browsers and I must say
    this blog loads a lot faster then most. Can you suggest a
    good hosting provider at a honest price? Thank you, I appreciate it!

    Reply
  5. Howdy would you mind stating which blog platform you’re using?
    I’m planning to start my own blog soon but I’m having a hard time choosing between BlogEngine/Wordpress/B2evolution and
    Drupal. The reason I ask is because your layout seems different then most blogs and I’m looking for something completely
    unique. P.S Sorry for getting off-topic but I
    had to ask! ps4 games https://tinyurl.com/45xtc52b ps4 games

    Reply
  6. You really make it seem so easy with your presentation but I
    find this matter to be actually something that I think I would
    never understand. It seems too complex and very broad for
    me. I am looking forward for your next post, I will try to get the hang of it!

    Reply
  7. I like the helpful info you provide to your articles.
    I’ll bookmark your blog and check again here regularly.
    I’m rather certain I will be told a lot of
    new stuff right right here! Good luck for
    the following!

    Reply
  8. Wonderful article! This is the kind of info that are supposed to
    be shared across the net. Shame on the search engines for no longer positioning this put up
    higher! Come on over and visit my web site . Thanks =)

    Reply
  9. Very nice post. I simply stumbled upon your blog and wanted
    to mention that I have really enjoyed surfing around your weblog posts.
    In any case I’ll be subscribing in your feed and I
    hope you write once more very soon!

    Reply
  10. Hello! This post couldn’t be written any better!
    Reading this post reminds me of my previous room mate! He always kept chatting about this.
    I will forward this article to him. Fairly certain he will have a good read.
    Thanks for sharing!

    Reply
  11. I loved as much as you will receive carried out right here.

    The sketch is tasteful, your authored material stylish.
    nonetheless, you command get bought an impatience over that you wish be
    delivering the following. unwell unquestionably come more formerly again as
    exactly the same nearly a lot often inside case you shield this increase.

    Reply
  12. Awesome issues here. I am very satisfied to see your post.
    Thank you a lot and I’m taking a look forward
    to touch you. Will you kindly drop me a e-mail?

    Reply
  13. Hello there! I know this is kind of off topic but I was wondering
    which blog platform are you using for this site?
    I’m getting sick and tired of WordPress because I’ve had problems with hackers and I’m looking at alternatives for
    another platform. I would be great if you could point me in the direction of a good platform.

    Reply
  14. I do not even know how I ended up here, but I thought this post was great.
    I do not know who you are but definitely you
    are going to a famous blogger if you aren’t already 😉 Cheers!

    Reply