I have this code and i have made it work with a submit button so how will I change it to a onchange and discarding the submit button? Can you guide me on how to do this?
echo "<form type=\"post\" action=\"\" id=\"newAjaxAudio" . $id . "\">
<select name=\"name\" id=\"aaplaylist_selection\" style=\"border: 1px solid #999999;color: #555555;font-size: 11px;height: 17px;min-width: 216px\">
<option value='" . $thefile1 . "' >" . $thetitle1 . "</option>
<option value='" . $thefile2 . "' >" . $thetitle2 . "</option>
</select>
<input type=\"hidden\" name=\"action\" value=\"addAudioSelector1\"/>
<input type=\"submit\" value=\"Play\" style=\"font-size:11px\">
</form>
<div id=\"feedback" . $id . "\"></div>
<script type=\"text/javascript\">
jQuery('#newAjaxAudio" . $id . "').submit(ajaxSubmit);
function ajaxSubmit(){
var newAjaxAudio" . $id . " = jQuery(this).serialize();
jQuery.ajax({
type:\"POST\",
url: \"/wp-admin/admin-ajax.php\",
data: newAjaxAudio" . $id . ",
success:function(data){
jQuery(\"#feedback" . $id . "\").html(data);
}
});
return false;
}
</script>";
The Function :
function addAudioSelector1(){
$name = $_POST['name'];
echo "<div id='sm2-container'></div>
<ul class='playlist'>
<li><a href='" . WPAUDIO_URL . "/sounds/" . $name . ".mp3'>" . $name . "</a></li>
</ul>";
die();
} // end Function addnewAudio
add_action('wp_ajax_addAudioSelector1', addAudioSelector1);
add_action('wp_ajax_nopriv_addAudioSelector1', addAudioSelector1); // not really needed
//***************************************************************************//
Thanks for the Help :)
You can trigger jQuery('#newAjaxAudio" . $id . "').submit(ajaxSubmit);
on $("#aaplaylist_selection").change();
or directly trigger ajaxSubmit()
Ok I got it solved! .change() wasn't enough. Here is what I've done :
jQuery('#aaplaylist_selection" . $id . "').change(function() {
jQuery(this).parents('form').submit();
});