I want to create an automatic response to a URL. I can brute force tab through the on-screen form and send programmed key strokes, but I want to instead programatically fill in the JavaScript. Runs faster and less error prone.



Below is my attempt to create a response to the web site:
I have failed with the template that I used before, so there is something else wrong.
Anyway, I think I can short circuit the longer normal line by line script template and can use the unique format as in the first example below.


-----------------------------
This first one works for its unique case.
"/cgi-bin/apps/PortFolioManagement?selectedLayoutID=12345678&selectedPortID=23456&defaultPortID=2987333"


-----------------------------

This second one fails with the site logging me off.
"/cgi-bin/apps/EquityOrder?ADVANCEDORDER&mode=advanced&CollisionID=" + UserID + _
"&jsactive=false&action=" + OrSide + "&qty=" + txtOrSize + "&symbol=QQQ&terms=" _
+ OrType + "&tif=D&limit_price=" + txtOrPrice + "&special=none&perform=order"

Here is my latest candidate, untried:
"/cgi-bin/apps/EquityOrder?mode=advanced&pagehandler=PHAdvancedOrderTicket&collisionid=" + UserID + _
"jsactive=true&action=" + OrSide + "&qty=" + txtOrSize + "&symbol=QQQ&terms=" _
+ OrType + "&tif=D&limit_price=" + txtOrPrice + "&special=none&placeorder=Place Order"



I just added the "ADVANCEDORDER" part to the first one above and have not tested that.
Do I need: pagehandler value="PHAdvancedOrderTicket" or is that another locally process that I need to compensate for?
----------------------------
Below is the source JavaScript from the site that I am trying to respond to.


---------JAVA TEXT REMOVED-----------------
}
function jsactive()
{
document.ADVANCEDORDER.jsactive.value = "true"
}


---Java Text removed--------



<center>
<form NAME="ADVANCEDORDER" method=post action="/cgi-bin/apps/EquityOrder">
<input type=hidden name=mode value="advanced">
<input type=hidden name=pagehandler value="PHAdvancedOrderTicket">
<input type=hidden name="collisionid" value="123456789">
<input type=hidden name=jsactive value="false">



</tr>
<tr BGCOLOR="#FFFFFF">
<td VALIGN="TOP"><font FACE="Arial,Helvetica" SIZE="-1">
&nbsp;<input TYPE="Radio" checked NAME="action" VALUE="buy">&nbsp;Buy<br>
&nbsp;<input TYPE="Radio" NAME="action" VALUE="sell">&nbsp;Sell<br>

&nbsp;<input TYPE="Radio" NAME="action" VALUE="buy_cover">&nbsp;Buy&nbsp;to&nbsp;Cover&nbsp;<br>
&nbsp;<input TYPE="Radio" NAME="action" VALUE="sellshort">&nbsp;Sell&nbsp;Short<br>
</font>
</td>
<td VALIGN="TOP" ALIGN="LEFT"><font FACE="Verdana,Arial,Helvetica" SIZE="-2"><b>&nbsp;&nbsp;Number&nbsp;of<br>&nbsp;&nbsp;Shares:&nbsp;&nbsp;</b></font></td>

<td VALIGN="TOP"><input TYPE="Text" NAME="qty" SIZE="7" MAXLENGTH="9" value="">&nbsp;</td>
<td VALIGN="TOP" ALIGN="RIGHT">
<font FACE="Verdana,Arial,Helvetica" SIZE="-2"><b>&nbsp;Symbol:&nbsp;</b></font>
<input TYPE="Text" NAME="symbol" SIZE="7" MAXLENGTH="9" value="">&nbsp;
<br>
<input TYPE="image" NAME="FIND" SRC="/gifs/find.gif" ALT="Find Symbol" WIDTH="59" HEIGHT="16" VSPACE="2" BORDER="0">&nbsp;
</td>
<td COLSPAN="2" ALIGN="CENTER" VALIGN="TOP">



</td>

</tr>
<tr BGCOLOR="#FFFFFF">
<td ROWSPAN="2" ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#EEEEEE"><font FACE="Verdana,Arial,Helvetica" SIZE="-2">&nbsp;<b>Terms:</b>&nbsp;</font></td>
<td BGCOLOR="#EEEEEE" rowspan="2" valign="top" align="left">
<font FACE="Arial,Helvetica" SIZE="-1">
<input TYPE="Radio" NAME="terms" VALUE="M">&nbsp;Market<br>

<input TYPE="Radio" NAME="terms" VALUE="L">&nbsp;Limit<br>
<input TYPE="Radio" NAME="terms" VALUE="S">&nbsp;Stop<br>
<input TYPE="Radio" NAME="terms" VALUE="X">&nbsp;Stop&nbsp;Limit</font>
</td>
<td ALIGN="RIGHT" VALIGN="TOP" BGCOLOR="#EEEEEE"><font FACE="Verdana,Arial,Helvetica" SIZE="-2"><b>&nbsp;Price:&nbsp;</b></font></td>
<td VALIGN="TOP" BGCOLOR="#EEEEEE">&nbsp;<input TYPE="Text" NAME="limit_price" value="" SIZE="7" MAXLENGTH="9">&nbsp;</font></td>
<td COLSPAN="2" ALIGN="CENTER" VALIGN="TOP">

<font FACE="Arial,Helvetica" SIZE="-1">&nbsp;<select NAME="special" SIZE="1">
<option VALUE="none" >No Special Instructions</option>
<option VALUE="a" >All or None (AON)</option>
<option VALUE="d" >Do Not Reduce (DNR)</option>
<option VALUE="ad" >AON/DNR</option></select>&nbsp;<br>



</td>
</tr>
FACE="Verdana,Arial,Helvetica" SIZE="-2"><b>&nbsp;Good For:&nbsp;</b></font></td>
<td BGCOLOR="#EEEEEE">
<font FACE="Arial,Helvetica" SIZE="-1">
&nbsp;<input TYPE="Radio" NAME="tif" VALUE="D">Day<br>
&nbsp;<input TYPE="Radio" NAME="tif" VALUE="moc">Market&nbsp;On&nbsp;Close&nbsp;(MOC)<br>


&nbsp;<input TYPE="Radio" NAME="tif" VALUE="eow">End&nbsp;of Week (EOW)<br></font>

<br /><!-- REMOVE WITH NON ACCOUNT FLAG -->

</td>
<td BGCOLOR="#EEEEEE">
<font FACE="Arial,Helvetica" SIZE="-1">
&nbsp;<input TYPE="Radio" NAME="tif" VALUE="eom">End&nbsp;of&nbsp;Month&nbsp;(EOM)<br>

&nbsp;<input TYPE="Radio" NAME="tif" VALUE="G">Until&nbsp;Canceled&nbsp;(GTC)<br>
&nbsp;<input TYPE="Radio" NAME="tif" VALUE="gtd">Good&nbsp;ThroughDate&nbsp;(GTD)&nbsp;<br>
&nbsp;&nbsp;&nbsp;&nbsp;
<select NAME="TIF_MONTH" onChange="updateCompanyDates(this.form.TIF_MONTH)" SIZE="1" STYLE="font-size: xx-small; font-family: Arial,Helvetica

-------------- someJAVA TEXT REMOVED----------

</tr>





<input TYPE="submit" NAME="placeorder" VALUE="Place Order" onClick="return js_save()">


</font></td>




<!-- File: equityorder_adv.html PHAdvancedOrderTicket -->
<br>
</center>
</body>
</html>
--------------------------------
This is what I found on the FormName for each of these:

Name method FormAction
ADVANCEDORDER post https://wwws.ameritrade.com/cgi-bin/apps/EquityOrder

Field Name Type CurrentValue
mode hidden advanced
pagehandler hidden PHAdvancedOrderTicket
collisionid hidden 123456789
jsactive hidden
action radio buy or sell or buy_cover or sellshort
qty text
symbol text
FIND image
terms radio M or L or S or X
limit_price text
special select-one none
tif radio D
TIF_MONTH select-one 0
TIF_DAY select-one 00
TIF-YEAR select-one 0
placeorder submit Place Order

perform hidden order ,extra item found on the ST pagehandler


under 'Links', I found this:
https://wwws.ameritrade.com/cgi-bin/...?mode=advanced

I think this is the correct response:
"EquityOrder"/cgi-bin/apps/EquityOrder?mode=advanced&pagehandler=PHAdvancedOrderTicket&collisionid=" + UserID + "jsactive=true&action=" + OrSide + "&qty=" + txtOrSize + "&symbol=QQQ&terms=" _
+ OrType + "&tif=D&limit_price=" + txtOrPrice + "&special=none&placeorder=Place Order"

I eliminated the 3 TIF-responses. Do I need to put them in?
-----------------------------------------
The two following appear on the same display page,
but offer two options, one to get the 'Status'
and the second part of the page, to 'cancel' or 'edit the order,
editing the order simply jumps to a new page, the 'Order' page

Name method FormAction
Unnamed Form post https://wwws.ameritrade.com/cgi-bin/apps/OrderStatus

Field Name Type CurrentValue
period radio DAYS
time text 0
status_type radio ALL or Fills or OPEN
FORM_ACTION submit Refresh View

I think this is the correct response:
"OrderStatus?OS_account_no=" UserID + "&period=DAYS&time=0&status_type=OPEN&FORM_ACTION=Refresh View"
I added the account number, I think it is necessary, else how would freetrade know?
-----------------------------------------
Name method FormAction
Unnamed Form post https://wwws.ameritrade.com/cgi-bin/...ancelEditOrder

Field Name Type CurrentValue
preform hidden edit
FORM_ACTION submit Cancel Order(s)
confirmed hidden 0 'I think if I change this to '1', I will cancel the order without having to confirm it in a second transmission
OS_account_no hidden 123456789
FORM_ACTION submit Edit Order
period radio DAYS
time text 0
period radio MAX
status_type radio ALL or FILLS or OPEN
FORM_ACTION submit Refresh View

the immediate above includes the OrderStatus option, just above

I think this is the correct response:
ConnectTotrade "CancelEditOrder", "?confirmed=1&OS_account_no=" + UserID + "&FORM_ACTION=Cancel Order(s)"