I'm getting pretty frustrated here.
I have a table of records. Next to each record will be a button. On clicking the button next to that record, a jquery AJAX call should be executed.
<script language="JavaScript" type="text/javascript">
<!--
function swapContent(cv) {
$("#myDiv").html('<div align="center"><img src="images/loader.gif"/></div>').show();
var url = "process.php";
$.post(url, {contentVar: cv} ,function(data) {
$("#myDiv").html(data).show();
});
}
//-->
</script>
The associated HTML:
<div id="myDiv" align="center"><a href="#" onClick="return false" onmousedown="javascript:swapContent('do_stuff');"><img src='images/icon.png' border='0'></a></div>
When I click on the HTML link, the contents of the div "myDiv" are changed out for the output of the ajax call to process.php. This is all well and good, but I will have dozens of these divs, and I need to be able to call the swapContent function with not only the parameter cv, but also pass in a parameter for which div should have its contents altered.
I believe my error is just based on an ignorance of JS syntax. For instance, I've done this:
<script language="JavaScript" type="text/javascript">
<!--
function swapContent(thediv,cv) {
$(thediv).html('<div align="center"><img src="images/loader.gif"/></div>').show();
var url = "process.php";
$.post(url, {contentVar: cv} ,function(data) {
$(thediv).html(data).show();
});
}
//-->
</script>
but I'm not sure if that is then treating the variable thediv as a string when it should be an object or what might be the problem.
I would appreciate any help you might give!
<div id="div1" align="center"><a href="#" onClick="return false" onmousedown="javascript:swapContent('div1','do_stuff');"><img src='images/icon.png' border='0'></a></div>
...
<div id="div2" align="center"><a href="#" onClick="return false" onmousedown="javascript:swapContent('div2','do_stuff');"><img src='images/icon.png' border='0'></a></div>