0

I would like to return objects from this function like,

function sampleCode(){
    new somewhere.api({
        var fullAddr = '';
        (adding some address using api)
        (it reutrns json data)
    })open();
}

<input type="text" id="x" placeholder="someone's address">
<input type="button" onclick="sampleCode()" value="popupFind">

<input type="text" id="x" placeholder="someone's address2">
<input type="button" onclick="sampleCode()" value="popupFind">

I'm using API for get address, to input values. might can use getelementbyid and make fucntion differ each times, but how if there are many inputs?

how do I returning objects and use seperately without duplicate?

Thx.

Dedenne_Cute
  • 65
  • 2
  • 6
  • 1
    Huh? Return objects to where? Your sample function is called from a click handler, so it doesn't make sense to return a value at all. Do you mean you want to parse the JSON (`JSON.parse(...)`) and use properties from the resulting object to populate the text input field nearest to the button that was clicked? – nnnnnn Mar 13 '17 at 04:54
  • Seconding @nnnnnn -- the code shown seems sort of pseudocode-esque, and I'm not completely clear on what your intent is nor what your problem is. However, if you clean up your code example and provide some more detail on your question I think someone will be able to help you. – Alexander Nied Mar 13 '17 at 05:03
  • oh, blimey. i forgot json.parse, firstly i made my function to give values with use getelementbyid(address) = fullAddr; - so when i reviewing my code, i thought it's not good-writing code, so tried refactorying it. but i can use JSON.parse()to give val to nearset input. I'm so sry for this stupid question. – Dedenne_Cute Mar 13 '17 at 05:35

1 Answers1

0

I believe what you are asking is how to make an http request. If you are using pure javascript then that information can be found here Javascript HTTP GET request. If you are using jQuery then the information can be found here jQuery HTTP GET request. I suggest using jQuery because its more compact and easier to understand.

As for it returning a json object, that is handled by server side code. You would need to write server code that can handle an http get request and then return a json object.

Community
  • 1
  • 1
Gary Holiday
  • 3,297
  • 3
  • 31
  • 72