mchat ajax\javascript button (mchat_body.html)

Support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
Forum rules
Please only request support for mods released by phpbbmodders.net found at either https://github.com/phpbbmodders/ or the MODDB at http://www.phpbb.com
Post Reply
ilovemchat123
New member
New member
Posts: 24
Joined: 12 May 2014, 05:01

mchat ajax\javascript button (mchat_body.html)

Post by ilovemchat123 »

I tried creating a button in mchat_avatars.html that displays a random quote in mchat:

Code: Select all

	<span style="float:right;"> 
<input type="image" src="{ROOT_PATH}mchat/dumb.gif" onClick="location.href='quote.php?annoy={mchatrow.MCHAT_USERNAME}'">
The issue is the button upon clicking executes the script and passes ?annoy= correctly and then updates mchat, but it also refreshes the page. I'm completely clueless about javascript, so I'm not sure how to go about this... perhaps ajax\javascript... which i know nothing about? This is my best attempt which has failed (I'm not sure how to use dumb.gif as the form button either).

Code: Select all

    <form id="image" action="" method="post">
        <input type="submit" value="Advertise in Public Chat">
    </form>

    <script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript" ></script>
    <script type="text/javascript">
        $(document).ready(function() {
          $('form').on('submit', function(){
              event.preventDefault();        
              var myVal = $('select[name="Type"]').val();
              $.ajax({
                type: "GET",
                url: "executethisscript.php",
                data: {
                    advertise: myVal
                }
          });
      });
    </script>
Any help would be greatly appreciated.
ilovemchat123
New member
New member
Posts: 24
Joined: 12 May 2014, 05:01

Re: mchat ajax\javascript button (mchat_body.html)

Post by ilovemchat123 »

I tried putting this in mchat body...

Code: Select all

<form id="myform"  method="POST"  class="form_statusinput">
<input type="hidden"  name="toid" id="toid" value="<?php echo {mchatrow.MCHAT_USERNAME}; ?>">
<div id="button_block">
<input type="submit" id="button" value="Enter">
</div>
</form>

<script>
$(document).ready(function(){
$("form#myform").submit(function(event) {
    event.preventDefault();
    var toid = $("#toid").val();

    $.ajax({
        type: "POST",
        url: "line.php",
        data: "toid=" + toid,
    });
});

}); 
</script>
but the variable toid does not pass... and if i click the button that is 4 messages up for example... the script executes 4 times...
ilovemchat123
New member
New member
Posts: 24
Joined: 12 May 2014, 05:01

Re: mchat ajax\javascript button (mchat_body.html)

Post by ilovemchat123 »

Any suggestions? This is especially useful for people if they are interested in 8ball, random quotes, etc scripts.
neuropass
Member
Member
Posts: 66
Joined: 12 Apr 2010, 17:07

Re: mchat ajax\javascript button (mchat_body.html)

Post by neuropass »

I think that If you are using ajax you shouldn't be using the form input stuff.. it;s not needed. the input button submits whatever in the form that's why is refreshing...
ilovemchat123
New member
New member
Posts: 24
Joined: 12 May 2014, 05:01

Re: mchat ajax\javascript button (mchat_body.html)

Post by ilovemchat123 »

neuropass wrote:I think that If you are using ajax you shouldn't be using the form input stuff.. it;s not needed. the input button submits whatever in the form that's why is refreshing...
I resolved the issue:

Code: Select all

<form id="myform" method="POST"  class="form_statusinput">
<input type="hidden" name="toid" id="toid" value="{mchatrow.MCHAT_USERNAME}">
<div id="button_block">
<input type="image" src="{ROOT_PATH}mchat/8ball.gif" alt="Submit">
</div>
</form>

<script>
$(document).ready(function(){
$("form#myform").submit(function(event) {
    event.preventDefault();
    var toid = $("#toid").val();

    $.ajax({
        type: "GET",
        url: "{ROOT_PATH}/8ball.php",
        data: "toid=" + toid
         });
    });
});
 </script>
but after clicking the button, instead of occuring one time for the intended recipient its executing for EVERY line of chat in existence
ilovemchat123
New member
New member
Posts: 24
Joined: 12 May 2014, 05:01

Re: mchat ajax\javascript button (mchat_body.html)

Post by ilovemchat123 »

another issue i realized is the form isn't inline with the admin buttons
Post Reply