samedi 18 avril 2015

Seeking help to create a JavaScript code to auto submit a form using Greasemonkey

I am a new bie to JavaScript and I am trying to write a grease monkey script to auto submit a form. The form which I am working on looks like this.enter image description here


The way this form works is like this, first we need to select an instrument from the first drop down menu I.e select instrument, then according to the instrument selected a list of symbols will be created which will become the options of second drop down menu symbol. In the same way the options for other three drop down menus are created according to the selected instrument from the first drop down menu. The HTML code for the first 2 drop down menus looks like this.



<form name="dataForm" id="dataForm" method="get" onSubmit="return false;" >
<div class="caption-text">Select Instrument :</div>
<div class="viewdata-content">
<select name="instrumentType" id="instrumentType" onChange="fillData();">
<option value='select'> Select Instrument Type </option>
<option value='FUTIDX'> Index Futures </option>
<option value='FUTSTK'> Stock Futures </option>
<option value='OPTIDX'> Index Options </option>
<option value='OPTSTK'> Stock Options </option>
<option value='FUTIVX'> Volatility Futures </option>
</select>
</div>
<div class="clear"></div>
<div class="caption-text">Select Symbol :</div>
<div class="viewdata-content">
<select size="1" name="symbol" id="symbol">
<option value='select'> Select Symbol </option>
</select>


I have written a very simple code to select the options which looks like this.



window.onload = function()
{
var field1 = document.getElementById("instrumentType");
field1.selectedIndex = 3;
var field2 = document.getElementById("symbol");
field2.selectedIndex = 4;
}


Briefly telling my code selects an option from the first drop down menu and the options for second drop down menu are not creating since the onchange event of first select tag didn't occur. How can I acheive this? how can I make my programm to build the options for second drop down menu according to the selected option in first drop down menu?Blindly I tried giving some sleep which didn't work


after running my code the form looks like this.enter image description here


Aucun commentaire:

Enregistrer un commentaire