Pages: [1]   Go Down
Send this topic | Print
Author Topic: JavaScript: Auto form submit with multiple buttons  (Read 1250 times)
Robar
Member
*
Offline Offline

Posts: 1


« on: November 28, 2008, 01:57:43 AM »

Background/Description:
I play BlackJack on a website. I have firefox and use the addin GreaseMonkey which gives you the ability to run JavaScript over other websites. I do not have a lot of experience coding in JavaScript, downloaded a few scripts, saw what they did and created mine from there adapting the code. I have learned by doing this but apparently not enough lol.

The script I created fully automates BJ for me which I plan to use overnight. I have it about 99.9% functional. The script places all of my bets for me based on it being the first hand, me winning or losing or tieing. The bet placing is done through a form with just a single submit button. It reads the dealer up card by image name and reads my total or totals, depending on if I have an ace or not. It will then determine what action to perform based on both scores. The problem is that the move the script tries to do brings me back to the same pages and keeps cycling automatically since the script does not end. The only differences between the Betting sumbit button and the Hit, Stand, and Double buttons is that all the submit buttons are included in a single form for the action to perform while placing a bet only has the one button. I have tried to just sumbit the form which failed since I do not know how to tell the submit function which button I want selected so I tried to replace the form on the site by using JavaScript to create a form with only 1 submit button. However it seems like this is also having the same results as the multi-submit button form.

I am guessing that the original form submit is sending all values to the server for processing and that all values need to be there for a valid action to be performed. Based on my knowledge I am not sure how I can submit the form using the button I want to instead of just submitting the form like I did with the placing bet form.



The following code is copied from a website I play BJ on. The site is coded in php but this is the HTML code I grabbed from viewing the source code. It is a basic BJ game without a split option, but the double down option is customizable from 1 dollar to the value of your bet.

Original Form off of Website:
<div id="bjboard">
 Dealer Hand<br />
 <img src="../bj/s1.gif" width="80" height="100">
 <img src="../bj/back.gif" width="20" height="100">
 <br />
 <br />
 Your Hand<br />
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
   <td>
    <img src="../bj/h5.gif" width="80" height="100">
    <img src="../bj/c8.gif" width="80" height="100">
   </td>
   <td width="130">
    <form id="bjmove" name="bjmove" method="post" action="playbj.php?command=playbj&action=move">
     <div align="center">
      <input type="submit" name="hit" value="Hit" style="width:150px" />
      <br />
      <input type="submit" name="stand" value="Stand" style="width:150px;margin-top:7px;" />
      <br />
      <input type="text" name="doublevalue" maxlength="5" style="width:150px;margin-top:7px;" value="10"  />
      <br />
      <input type="submit" name="double" value="Double" style="width:150px;margin-top:7px;" />
     </div>
    </form>
   </td>
  </tr>
 </table>
 <br />Your Score: 13
 <br />Bet Value: $10
</div>



This is the code that I created. Originally I did not have the bjboard.innerHTML line in there. Then I added it in, I have also recreated the form using just the submit button that I want to use but that still did not work. The second line that sets the delay works when there is only one submit button but not with multiple submit buttons.

My JavaScript Code:
bjboard.innerHTML="<form id=\"bjmove\" name=\"bjmove\" method=\"post\" action=\"playbj.php?command=playbj&action=move\"><div align=\"center\"><input type=\"submit\" name=\"hit\" value=\"Hit\" style=\"width:150px\" /><br /><input type=\"submit\" name=\"stand\" value=\"Stand\" style=\"width:150px;margin-top:7px;\" /><br /><input type=\"text\" name=\"doublevalue\" maxlength=\"5\" style=\"width:150px;margin-top:7px;\" value=\"10\" /><br /><input type=\"submit\" name=\"double\" value=\"Double\" style=\"width:150px;margin-top:7px;\" /></form>";
setTimeout(function() { document.getElementsByTagName('form')[0].submit()},Math.floor((Math.random()*700)+300));



If anyone has any ideas on how to specify the submit button that I want to send to the server when submitting the form please let me know. Thanks.
Logged
worldwhy
Member
*
Offline Offline

Posts: 3


WWW
« Reply #1 on: September 09, 2009, 10:57:25 AM »

Hey do u know how to make it so when you click the submit button the info is sent to a specific place?
Logged
rvtraveller
Loyal 110MB Member
*******
Online Online

Posts: 2655


Please yell if you are paying attention.


WWW
« Reply #2 on: September 09, 2009, 11:35:54 AM »

Set the action attribute of the form tag right?

<form action="senddatahere.php" method="post">
...input
</form>
Logged

pacisle
Hyper-Active Member
***
Offline Offline

Posts: 121


WWW
« Reply #3 on: September 09, 2009, 01:20:33 PM »

You could set up multiple forms, each with its own submit button and action.
Logged
Pages: [1]   Go Up
Send this topic | Print
Jump to: