I thought I was doing really well teaching myself JQuery, but then came upon a problem which I needed JSON for, and now I feel like I'm back as a neanderthal, staring in wonder at the incomprehensible shapes on the screen...
Basically, I am creating a form as follows:
<h2>Heroes and Heroines Site Management System - Edit a Site</h2>
<p><label for="eventLocation">Event Location:</label><select name="eventLocation" id="eventLocation">
<option value="5">Buckstone</option>
<option value="18">Sandiways: Begg</option>
<option value="16">Wing Drumble Wood</option>
<option value="17" selected></option>
<option value="19" selected></option>
<option value="20">Pwll Du</option>
<option value="21" selected></option>
<option value="22">Kinver Edge</option>
<option value="23">Sandiways: Lakeview</option>
<option value="24">Gladstone</option>
<option value="25">Cannock Chase</option>
<option value="26" selected></option>
<option value="27">Consall Scout camp</option>
<option value="28">Broadwater</option>
<option value="29">Horley</option>
<option value="30">Blackwell Court</option>
<option value="31">Roddlesworth, Lancs</option>
<option value="32">Root 'n' Branch </option>
</select></p>
<form method="post" action="/heroes-and-heroines-larp-and-lrp-events.php?task=commitLocationEdit">
<p><label for="name">Location Name:</label><input type="text" name="name" id="name" class="wideText"></p>
<p><label for="address">Location Address:</label><textarea name="address" id="address" rows="6" cols="50"></textarea></p>
<p><label for="postcode">Location postcode:</label><input type="text" name="postcode"></p>
<p><label for="directions">Directions to Location:</label><textarea name="directions" rows="10" cols="50"></textarea></p>
<p><label for="locationType">Location Type:</label><select name="locationType"><option value="YHA">YHA</option>
<option value="Hostel">Hostel</option><option value="Campsite">Campsite</option>
<option value="Scout Camp (Building)">Scout Camp (Building)</option><option value="Scout Camp (Camping)">Scout Camp (Camping)</option>
<option value="8 Hour">8 Hour</option><option value="Other">Other</option>
</select></p>
<p><label for="googleMapLink">Google Map Link:</label><textarea name="googleMapLink" rows="6" cols="50" title="To get a Google Maps Link, go to www.maps.google.co.uk, find the location, and then click on the tiny gear icon in the bottom right of the screen. Click 'Share and Embed Map', choose the 'Embed Map' tab, select 'Small Map' and then copy and paste the code into this box"></textarea></p>
<p><label for="notes">Notes:</label><textarea name="notes" rows="10" cols="50"></textarea></p>
<button type="submit" class="eventBookButton">Edit Location</button>
<a href="/heroes-and-heroines-larp-and-lrp-events.php"><input type="button" class="eventBookButton" value="Cancel" /></a>
</form>
which will allow site moderators to edit the locations which we use to run events at in our club. I want them to be able to select a site from the first select field, and for JQuery to then populate all the subsequent fields with the data from our SQL database. I have been using the following JQuery script, which I took from this previous question:Dynamically fill in form values with jQuery
<script>
$("#eventLocation").bind("change", function(e){
$.getJSON("/common/ajaxCalls.php?task=locationEdit&&eventLocation" + $("#eventLocation").val(),
function(data){
$.each(data, function(i,item){
if (item.field == "name") {
$("#name").val(item.value);
} else if (item.field == "address") {
$("#address").val(item.value);
}
});
});
});
</script>
The JQuery script SHOULD send location to the following PHP script when a selection is made, and then populate the form with the information (which is just dummy data at the moment...)
$json = array(array('field' => 'name',
'value' => "test Name"),
array('field' => 'address',
'value' => "Test Address"));
echo json_encode($json);
I've been mashing my head against this all afternoon, and haven't managed to get anywhere... I've watched the queries through Firefox developer, and the script isn't putting any calls out to the PHP script or anything.
Any suggestions?
Thanks!
Seb
=leaving not file=valuechangefunction to be within$(function(){ ... });. You currently have it after that.