0

Hi Everyone, I am new to JQuery, Java Script & Ajax.

Hope you dont mind the daft questions I may post.
Here is my first Jquery, JS & Ajax question.

I have the follow script inside my head section of a website I am testing with.

<script type="text/javascript" src="jquery-1.9.1.js"></script>
<script language="JavaScript" type="text/javascript">
function swapContent(cv) {
    $("#inPlayCards").html('<img src="blueloading.gif"/>').show();
    var url = "inplaycards-shoot.php";
    $.post(url, {contentVar: cv} ,function(data) {
       $("#inPlayCards").html(data).show();
    });
}
</script>

my button for calling the script is -

            <button type="button" class="btn btn-primary btn-large" onClick="return false" onMouseDown="javascript:swapContent('inplaycards');">Click To Select Your Cards</button></p>

On the PHP page I have the following if -

$contentVar = $_POST['contentVar'];
if ($contentVar == "inplaycards") {

mysql db...

}

Now, the above script calls my url, the php page does the mysql query and returns the result in the requested div, no problems there, until I tried adding a second script to the page.

inside the script tags.

function shootone(cv) {
    $("#one").html('<img src="blueloading.gif"/>').show();
    var url = "inplaycards-shoot1.php";
    $.post(url, {contentVar: cv} ,function(data) {
       $("#one").html(data).show();
    });
}

The button for the second script is

            <button type="button" class="btn btn-success btn-large" onClick="return false" onMouseDown="javascript:shootone('shootone');">Click To Select First Card</button></p> 

The if statment on my php is

$contentVar = $_POST['contentVar'];
if ($contentVar == "shootone") {

mysql db...

}

Is it possible to have more than one script on a single page, as I need another three to run when I click each individual button.

Any help would be very much appreciated,
Thanks

3
Contributors
4
Replies
21
Views
4 Years
Discussion Span
Last Post by pixelsoul
0

On a side note, why not make one function to handle all of this rather than multiple different functions that do almost the identical thing.

0

Hi GliderPilot, No, it's not giving any error at all, when I click on the second button, nothing happens.

@Pixelsoul, I am new to js functions etc and wouldnt know where to start...

Can someone point me in the right direction how I can have multiple scripts on the same page

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.