PDA

View Full Version : Recordset - Javascript



vbjohn
01-30-2007, 08:39 PM
Can you run a recordset through Javascript in an ASP page?

What I need to do is:
1.) The end user will select an option from a drop down menu (Search By).
2.) If they select a certain value then another drop down menu should appear with the data from the Javascript (When the Search By = Employee Name).
3.) If they select anything else then a text box would appear.

Right now what I have doing is 4 controls show up already in the beginning.
Dropdown (Search By), Dropdown (Operand), Textbox, Dropdown (And, OR)

When the user selects either the AND or OR then a new line would appear else they would just hit the command button to go to the next page.

javascript:


<script language="javascript">
var gRowId = 2;

function addRow()
{
var tbody = document.getElementById('table1').getElementsByTagName('tbody')[0];
var gRowId1 = gRowId;
var row = document.createElement('TR');
var cell1 = document.createElement('TD');
var cell2 = document.createElement('TD');
var cell3 = document.createElement('TD');
var cell4 = document.createElement('TD');

var br = document.createElement("br");
var inp1 = document.createElement('SELECT');
var inp2 = document.createElement('SELECT');
var inp3 = document.createElement('INPUT');
var inp4 = document.createElement('SELECT');


inp1.setAttribute('name','searchby');
inp1.id='seachby'+gRowId1;

inp2.setAttribute('name','opercmb');
inp2.id='opercmb'+gRowId1;

//window.caller = document.getElementById("usertxt" + gRowId1)

inp3.setAttribute('type','text');
inp3.setAttribute('name','srow');
inp3.id='srow'+gRowId1;

inp4.setAttribute('select');

//cell4.setAttribute('align','center');
inp4.setAttribute('name','andor');
inp4.onchange= function(){addRow();};


//Cell 1

opt = document.createElement('Option');
opt.innerHTML = '';
opt.value = '0';
inp1.appendChild(opt);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'Contract Number';
opt$start.value = '1';
inp1.appendChild(opt$start);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'Contract Name';
opt$start.value = '2';
inp1.appendChild(opt$start);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'Group Number';
opt$start.value = '3';
inp1.appendChild(opt$start);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'Employee Number';
opt$start.value = '4';
inp1.appendChild(opt$start);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'Employee Name';
opt$start.value = '5';
inp1.appendChild(opt$start);

//Cell 2

opt = document.createElement('Option');
opt.innerHTML = '';
opt.value = '0';
inp2.appendChild(opt);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'Equals ( = )';
opt$start.value = '=';
inp2.appendChild(opt$start);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'Not Equal To ( <> )';
opt$start.value = '<>';
inp2.appendChild(opt$start);

//Cell 3
// textbox

//Cell 4

inp4.setAttribute('name','itemID');

opt = document.createElement('Option');
opt.innerHTML = '';
opt.value = '';
inp4.appendChild(opt);


opt$start = document.createElement('Option');
opt$start.innerHTML = 'AND';
opt$start.value = 'AND';
inp4.appendChild(opt$start);

opt$start = document.createElement('Option');
opt$start.innerHTML = 'OR';
opt$start.value = 'OR';
inp4.appendChild(opt$start);


//cell1.innerHTML = gRowId;
cell1.appendChild(inp1);
cell2.appendChild(inp2);
cell3.appendChild(inp3);
cell4.appendChild(inp4);

row.appendChild(cell1);
row.appendChild(cell2);
row.appendChild(cell3);
row.appendChild(cell4);

tbody.appendChild(row);
gRowId++;
}
</script>


ASP/HTML:


<form name="myform" method="post">
<table id="table1" border=1>
<tbody>
<tr>
<th>Search Field</th><th></th><th></th>
</tr>
<tr>
<td> <select name="searchby" id=searchby>
<option value="0"></option>
<option value="1">Contract Number</option>
<option value="2">Contract Name</option>
<option value="3">Group Number</option>
<option value="4">Employee Number</option>
<option value="5">Employee Name</option>
</select></td>
<td>
<select name="opercmb" id=opercmb>
<option value="0"></option>
<option value="=">Equals ( = )</option>
<option value="<>">Not Equal To ( <> )</option>
</select>
</td>
<td><input name="srow" type=text value=""></td>
<td><SELECT id=andor name=andor onchange="addRow();">
<OPTION></OPTION>
<OPTION Value=AND>AND</OPTION>
<OPTION Value=OR>OR</OPTION>
</SELECT></td>
</tr>
</tbody>
</table>
<input type="submit" name="submit" value="Submit">
</form>

any ideas?