Forum Moderators: open
job
Job name
notes
some notes
some more notes
yet more notes
Now each job has a unique ID in a database and I would like to display an edit button right by the notes for each job. Then, when the user clicks the edit button it goes to the corresponding job edit page. I have the php echoing hello world right on a button click so I am that far. My problem is that I don't know how I can distinguish between the different jobs i.e. if they click edit button for job1 or the edit button for job2 etc. Can I pass some data into a php file w/ JS somehow? So it would be something like
pseudo
onButtonClick(execute(somefile.php(passing in an id)));
If not, does anyone have any ideas how I would be able from the client side to tell which job it is? Thanks,
Read this on using jquery for ajax:
[ibm.com...]
Yes, it's totally possible to pass a query string via JavaScript to the PHP script, have the PHP script take those values and return some dynamic content (i.e. that specific record's data based on the `ID` value).
And while that article is a nice introduction to using jQuery's Ajax methods, it's not very clear on how to do what you want. If you look at "Listing 4", you can see how the POST method Ajax call sends some data to the script, but it doesn't express how you would use a GET string to retrieve some content. If you are interested in using jQuery (which I recommend), you can view the jQuery.get method examples [docs.jquery.com] in the jQuery API.
Otherwise, it's as simple as sending the query string to the URL, e.g.
// instantiate the xhr object
var xhr= ( window.XMLHttpRequest ) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP");
// the URL to send (note the value attached to it)
var URL= 'yourscript.php?id=' + theIDvalue;
// open the connection
xhr.open("GET", URL, true);
// callback function
xhr.onreadystatechange= function() {
// handle your request here
};
// send method (send null with GET method)
xhr.send(null);
If this confuses you, there are plenty of resources out there on the XMLHttpRequest object [lmgtfy.com] and how to implement it. This is just a glib example of how to pass data in the query string.