Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help.. how do I refer two forms to the same fuctions ia a page

Status
Not open for further replies.

miagol

Programmer
Jun 1, 2008
2
US
This function brings up the only raws selected when I click compare. The problem is that I have the same form twice. How can solve this?

<html>

<head>
<script type="text/javascript">
<!--
window.onload=function()
{
document.getElementById('onclick').onclick=function()
{
var check=document.getElementsByTagName('input'),
divs=document.getElementsByTagName('tr'),i=0;
for(var i;i<check.length,i<divs.length;i++)
{
divs.style.display='none';
if(check.type=='checkbox')
{
if(check.checked==true)
divs.style.display='';
}}}}
//-->
</script>
</head>

<body>

<form><label></label><label></label>
<table width="953" border="1">
<tr id="dd1">
<td width="829" >1</td>
<td width="108" ><input type="checkbox" name="modtype2" value="value1" />
<label>value1</label></td>
</tr>
<tr id="dd2">
<td >2</td>
<td ><input type="checkbox" name="modtype3" value="value2" />
<label>value2</label></td>
</tr>
<tr id="dd3">
<td >3</td>
<td ><input type="checkbox" name="modtype4" value="value3" />
<label>value3</label></td>
</tr>
<tr id="dd4">
<td >4</td>
<td ><input type="checkbox" name="modtype5" value="value4" />
<label>value4</label></td>
</tr>
<tr id="dd5">
<td >5</td>
<td ><input type="checkbox" name="modtype" value="value5" />
<label>value5</label></td>
</tr>
</table>


<br>
<input type="button" name="onclick" id="onclick" value="Compare">
<br>
</form>

<form><label></label><label></label>
<table width="953" border="1">
<tr id="dd1">
<td width="829" >1</td>
<td width="108" ><input type="checkbox" name="modtype2" value="value1" />
<label>value1</label></td>
</tr>
<tr id="dd2">
<td >2</td>
<td ><input type="checkbox" name="modtype3" value="value2" />
<label>value2</label></td>
</tr>
<tr id="dd3">
<td >3</td>
<td ><input type="checkbox" name="modtype4" value="value3" />
<label>value3</label></td>
</tr>
<tr id="dd4">
<td >4</td>
<td ><input type="checkbox" name="modtype5" value="value4" />
<label>value4</label></td>
</tr>
<tr id="dd5">
<td >5</td>
<td ><input type="checkbox" name="modtype" value="value5" />
<label>value5</label></td>
</tr>
</table>


<br>
<input type="button" name="onclick" id="onclick" value="Compare">
<br>
</form>



</body>
</html>
 
answer to my post:



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "<html>
<head>
<title>Two Forms - Demo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
<!--
.wide {
width:829px;
}
.narrow {
width:108px;
}
.comp {
margin: 1em 0;
}
-->
</style>
<script type="text/javascript">
<!--
if(document.getElementById)
window.onload=function(){
var buts = ['but1', 'but2', 'but3'],
findTr = function(el){
while (el.parentNode){
el = el.parentNode;
if (el.tagName.toLowerCase() == 'tr')
return el;
}
return false;
};
for (var i = buts.length - 1; i > -1; --i)
document.getElementById(buts).onclick = function(){
var check = this.form.elements;
for(var i = check.length - 1; i > -1 ; --i)
if(check.type && check.type == 'checkbox' && !check.checked && findTr(check))
findTr(check).style.display = 'none';
};
};
// -->
</script>
</head>

<body>

<form action="#">
<table width="953" border="1">
<tr id="dd1a">
<td class="wide">1</td>
<td class="narrow"><input type="checkbox" name="modtype2a" value="value1">
<label>value1</label></td>
</tr>
<tr id="dd2a">
<td class="wide">2</td>
<td class="narrow"><input type="checkbox" name="modtype3a" value="value2">
<label>value2</label></td>
</tr>
<tr id="dd3a">
<td class="wide">3</td>
<td class="narrow"><input type="checkbox" name="modtype4a" value="value3">
<label>value3</label></td>
</tr>
<tr id="dd4a">
<td class="wide">4</td>
<td class="narrow"><input type="checkbox" name="modtype5a" value="value4">
<label>value4</label></td>
</tr>
<tr id="dd5a">
<td class="wide">5</td>
<td class="narrow"><input type="checkbox" name="modtypea" value="value5">
<label>value5</label></td>
</tr>
</table>



<div class="comp">
<input type="button" name="onclick2" id="but1" value="Compare">
</div>

</form>

<form action="#">
<table width="953" border="1">
<tr id="dd1b">
<td class="wide">1</td>
<td class="narrow"><input type="checkbox" name="modtype2b" value="value1">
<label>value1</label></td>
</tr>
<tr id="dd2b">
<td class="wide">2</td>
<td class="narrow"><input type="checkbox" name="modtype3b" value="value2">
<label>value2</label></td>
</tr>
<tr id="dd3b">
<td class="wide">3</td>
<td class="narrow"><input type="checkbox" name="modtype4b" value="value3">
<label>value3</label></td>
</tr>
<tr id="dd4b">
<td class="wide">4</td>
<td class="narrow"><input type="checkbox" name="modtype5b" value="value4">
<label>value4</label></td>
</tr>
<tr id="dd5b">
<td class="wide">5</td>
<td class="narrow"><input type="checkbox" name="modtypeb" value="value5">
<label>value5</label></td>
</tr>
</table>



<div class="comp">
<input type="button" name="onclick2" id="but2" value="Compare">
</div>

</form>


<form action="#">
<table width="953" border="1">
<tr id="dd1c">
<td class="wide">1</td>
<td class="narrow"><input type="checkbox" name="modtype2b" value="value1">
<label>value1</label></td>
</tr>
<tr id="dd2c">
<td class="wide">2</td>
<td class="narrow"><input type="checkbox" name="modtype3b" value="value2">
<label>value2</label></td>
</tr>
<tr id="dd3c">
<td class="wide">3</td>
<td class="narrow"><input type="checkbox" name="modtype4b" value="value3">
<label>value3</label></td>
</tr>
<tr id="dd4c">
<td class="wide">4</td>
<td class="narrow"><input type="checkbox" name="modtype5b" value="value4">
<label>value4</label></td>
</tr>
<tr id="dd5d">
<td class="wide">5</td>
<td class="narrow"><input type="checkbox" name="modtypeb" value="value5">
<label>value5</label></td>
</tr>
</table>



<div class="comp">
<input type="button" name="onclick2" id="but3" value="Compare">
</div>

</form>

</body>
</html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top