1

I am making a simple jQuery mobile app, where one of the pages is about a restaurant. On that page, I want to have a button that, when clicked, saves the information of the restaurant to a database.

I already have a php code that can save data to my database, and i have this javascript code that works together with it. Though this is used for saving data from a google maps infowindow when closed. I just need a on click button.

var url = "phpsqlinfo_addrow.php?name=" + name + "&address=" + address + "&description=" + description + "&lat=" + latlng.lat() + "&lng=" + latlng.lng();
downloadUrl(url, function (data, responseCode) {
    if (responseCode == 200 && data.length <= 1) {
        infowindow.close();
        document.getElementById("message").innerHTML = "Location added.";
    }
}

What is the easiest approach to this?

Thanks.

EDIT:

Is it possible to do like this, if i create a button with id #btn_save :

$(document).ready(function() { $(document).on("click","#btn_save",function() { "phpsqlinfo_addrow.php?name=" + john + "&address=" + lolstreet 12 + "&description=" + this is restaurant john + "&lat=" + xx.xx() + "&lng=" + yy.yy();

}); });

Sorry, i know i should be learning the basics first.. :/

1 Answer 1

4

If I understood correctly, you need to add button onClick event handler? If so, here you go (using jquery 1.9+):

$(document).ready(function() {
  //onClick event handler for button with id "btn_save"
  $(document).on("click","#btn_save",function() {
    //Your code here
  });
});
Sign up to request clarification or add additional context in comments.

3 Comments

"i'm making a simple jquery mobile app" he is using jQuery.
@Shawn31313 I don't see how it was my fault, but sure I will add it.
@Shawn31313 yep, he did :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.