Forums

I need help adding a javascript to a form

arevivo 08 Jan, 2012
Hello

i am using chronoform v4

i am trying to add some javascript i made to delete rows in a table. i made it work on a regular html page, but i cannot integrate it with chronoform. could someone help me.

Here is the code that i copied to the On load JS

it basicaly 2 functions the first one changes the background of the rows and the second one delete the rows that have a value of zero in a cell. the code works fine, but not on chronoform.

thank you

function altRows(id){
	if(document.getElementsByTagName){  
		
		var table = document.getElementById(id);  
		var rows = table.getElementsByTagName("tr"); 
		 
		for(i = 0; i < rows.length; i++){          
			if(i % 2 == 0){
				rows[i].className = "evenrowcolor";
			}else{
				rows[i].className = "oddrowcolor";
			}      
		}
	}
	}



	function deleterow(id){
	if(document.getElementsByTagName){  
		
	    var table = document.getElementById(id);
	    for (var i = 0, row; row = table.rows[i]; i++) {
		//iterate through rows
		//rows would be accessed using the "row" variable assigned in the for loop
		     

		     for (var j = 0, col; col = row.cells[j]; j++) {
			 //iterate through columns
			 //columns would be accessed using the "col" variable assigned in the for loop
			  
			  

			  if (table.rows[i].cells[2].innerHTML == '0'){
				//table.rows[i].cells[2].innerHTML ='GOT IT' ;
				//document.getElementById(id).deleteRow(1);
				document.getElementById(id).deleteRow(i);
				i=i-1
				j=j-2
				}  
 		
			}  
	    }
	}

		}



	window.onload=function(){
	deleterow('alternatecolor');
	deleterow('alternatecolor2');
	deleterow('alternatecolor3');
	deleterow('alternatecolor4');
	deleterow('alternatecolor5');
	altRows('alternatecolor');
	altRows('alternatecolor2');
	altRows('alternatecolor3');
	altRows('alternatecolor4');
	altRows('alternatecolor5');
	altRows('alternatecolor6');

	}
GreyHead 09 Jan, 2012
Hi arevivo,

I don't see anything obvious in your script that would prevent it working with ChronoForms. Without seeing the Form HTML or the JavaScript error it isn't possible to say anything else that is useful :-(

Bob
arevivo 09 Jan, 2012
here is the form code.

its basically some css a few tables with some selection boxes, and a submit button.
<!--  CATEGORY B 1 TO 2 PERSONS NO BABIES-->
	<?php
// Get user-information from Joomla
$user = &JFactory::getUser();
?>
	<style type="text/css">
    table.altrowstable{
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #a9c6c9;
	border-collapse: collapse;
	}
	table.altrowstable th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
	}
	table.altrowstable td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
	}
	.oddrowcolor{
	background-color:#d4e3e5;
	}
	.evenrowcolor{
	background-color:#c3dde0;
	}
	table.altrowstable2{
	font-family: verdana,arial,sans-serif;
	font-size:11px;
	color:#333333;
	border-width: 1px;
	border-color: #a9c6c9;
	border-collapse: collapse;
	}
	table.altrowstable2 th {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
	}
	table.altrowstable2 td {
	border-width: 1px;
	padding: 8px;
	border-style: solid;
	border-color: #a9c6c9;
	}
	</style>
	<table border="0" width="370px" bordercolor="#FFFFFF">
		<tr id="row">
			<td style="width:150px;">Welcome:</td>
			<td class="ccms_form_element cfdiv_text" id="label_text_container_div">
			<input style="border: none;" maxlength="150" size="30px" class="" title="" label_over="0" hide_label="0" type="text" value="<?= $user->name; ?>" name="input_text_3">
			</td>
		</tr>
	</table><br>
	<table class="altrowstable" id="alternatecolor">
		<tr id="row">
			<td id="column" width="7"> </td>
			<td id="column">BASICS</td>
			<td id="column"> </td>
			<td id="column"> </td>
		</tr>
		<tr id="row">
			<td id="column"> </td>
			<td id="column">Product Name</td>
			<td id="column">Quantity</td>
			<td id="column">Select to order</td>
		</tr>
		<tr id="row">
			<td id="column">1</td>
			<td id="column"><label style="text-transform: uppercase">Canned Pears 3 kg</label></td>
			<td id="column">0</td>
			<td id="column">
				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_1">
						<option value="0" selected>
							0
						</option>
					</select>
					<div class="clear"></div>

					<div id="error-message-input_select_1"></div>
			</div>
			</td>
		</tr>
		<tr id="row">
			<td id="column">1</td>

			<td id="column"><label style="text-transform: uppercase">ASSORTED BEANS 19 oz</label></td>
			<td id="column">2</td>
			<td id="column">
				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_2">
						<option value="0" selected>
							0
						</option>
						<option value="1">
							1
						</option>
						<option value="2">
							2
						</option>
				</select>
					<div class="clear"></div>
					<div id="error-message-input_select_2"></div>
				</div>
			</td>
		</tr>
		<tr id="row">
			<td id="column">1</td>
			<td id="column"><label style="text-transform: uppercase">DRIED CHICK PEAS</label></td>
			<td id="column">1</td>
			<td id="column">
				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_3">
						<option value="0" selected>
							0
						</option>
						<option value="1">
							1
						</option>
					</select>
					<div class="clear"></div>
					<div id="error-message-input_select_3"></div>
				</div></td></tr>

		<tr id="row">
			<td id="column">7</td>

			<td id="column"><label style="text-transform: uppercase">CEREAL - *Limits: 1 = 340 g</label></td>

			<td id="column">0</td>

			<td id="column">
				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_34">
						<option value="0" selected>
							0
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_3"></div>
				</div>
			</td>
		</tr>
	</table><br>
	<br>

	

	<table class="altrowstable" id="alternatecolor3">
		<tr id="row">
			<td id="column"> </td>

			<td id="column">NON FOOD ITEMS (LIMITED TO ONCE/MONTH)</td>

			<td id="column"> </td>

			<td id="column"> </td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td >Product Name</td>

			<td >Quantity</td>

			<td >Select to order</td>
		</tr>

		<tr id="row">
			<td id="column">15</td>

			<td ><label style="text-transform: uppercase">DISH SOAP - prestige</label></td>

			<td >0</td>

			<td id="column">
				 

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_114">
						<option value="0" selected>
							0
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_1"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column">15</td>

			<td ><label style="text-transform: uppercase">RAID PLANT BUG KILLER 350ml</label></td>

			<td >0</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_2" value="" alt="ghost" />
			<input value="2" label_over="0" hide_label="0" title="TOMATO PASTE" type="checkbox" name="input_checkbox_2" class="label_left" />
			<div id="error-message-input_checkbox_2"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_115">
						<option value="0" selected>
							0
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_2"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column">15</td>

			<td ><label>FOAM DEGREASER 4L</label></td>

			<td >1</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_3" value="" alt="ghost" />
			<input value="2" label_over="0" hide_label="0" title="ASSORTED BEANS" type="checkbox" name="input_checkbox_3" class="label_left" />
			<div id="error-message-input_checkbox_3"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_116">
						<option value="0" selected>
							0
						</option>

						<option value="1">
							1
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_3"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column">29</td>

			<td ><label style="text-transform: uppercase">WOMEN'S RAZORS (13/pack)</label></td>

			<td >0</td>

			<td id="column">
				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_133">
						<option value="0" selected>
							0
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_3"></div>
				</div>
			</td>
		</tr>
	</table><br>
	<br>

	<br>
	<br>

	<table class="altrowstable" id="alternatecolor5">
		<tr id="row">
			<td id="column"> </td>

			<td id="column">FRIDGE / FREEZER</td>

			<td id="column"> </td>

			<td id="column"> </td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column">Product Name</td>

			<td width="56">Quantity</td>

			<td id="column">Select to order</td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column"><label style="text-transform: uppercase">FROVEN ORIGINAL VEGGIE GROUND ROUND 340 g</label></td>

			<td width="56">2</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_1" value="" alt="ghost" />
			<input value="1" label_over="0" hide_label="0" title="Semolina  flour packed " type="checkbox" name="input_checkbox_1" class="label_left" />
			<div id="error-message-input_checkbox_1"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_159">
						<option value="0" selected>
							0
						</option>

						<option value="1">
							1
						</option>

						<option value="2">
							2
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_1"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column"><label style="text-transform: uppercase">FROVEN ASIAN VEGGIE GROUND ROUND 340 g</label></td>

			<td width="56">2</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_2" value="" alt="ghost" />
			<input value="2" label_over="0" hide_label="0" title="TOMATO PASTE" type="checkbox" name="input_checkbox_2" class="label_left" />
			<div id="error-message-input_checkbox_2"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_160">
						<option value="0" selected>
							0
						</option>

						<option value="1">
							1
						</option>

						<option value="2">
							2
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_2"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column"><label>FROZEN VEGGIE ROAST BEEF 155 g</label></td>

			<td width="56">2</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_3" value="" alt="ghost" />
			<input value="2" label_over="0" hide_label="0" title="ASSORTED BEANS" type="checkbox" name="input_checkbox_3" class="label_left" />
			<div id="error-message-input_checkbox_3"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_161">
						<option value="0" selected>
							0
						</option>

						<option value="1">
							1
						</option>

						<option value="2">
							2
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_3"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column"><label style="text-transform: uppercase">FROZEN VEGGIE DOGS - Yves (12)</label></td>

			<td width="56">0</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_4" value="" alt="ghost" />
			<input value="2" label_over="0" hide_label="0" title="COFFEE 71gr" type="checkbox" name="input_checkbox_4" class="label_left" />
			<div id="error-message-input_checkbox_3"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_162">
						<option value="0" selected>
							0
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_4"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column"><label style="text-transform: uppercase">STRAWBERRY RICE DREAM (pareve) 473 ml</label></td>

			<td width="56">1</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_5" value="" alt="ghost" />
			<input value="1" label_over="0" hide_label="0" title="PASTA SHELLS" type="checkbox" name="input_checkbox_5" class="label_left" />
			<div id="error-message-input_checkbox_5"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_163">
						<option value="0" selected>
							0
						</option>

						<option value="1">
							1
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_3"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column"><label style="text-transform: uppercase">ORANGE VANILLA RICE DREAM (pareve) 473 ml</label></td>

			<td width="56">1</td>

			<td id="column">
				<!-- <input type="hidden" name="input_checkbox_6" value="" alt="ghost" />
			<input value="1" label_over="0" hide_label="0" title="APPLE BLEND JAM (10x16ml)" type="checkbox" name="input_checkbox_6" class="label_left" />
			<div id="error-message-input_checkbox_6"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_164">
						<option value="0" selected>
							0
						</option>

						<option value="1">
							1
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_3"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column"> </td>

			<td id="column"><label style="text-transform: uppercase">ORANGE JUS FROZEN TREEHUGGER 1.89 L</label></td>

			<td width="56">1</td>

			<td id="column">
				<!--<input type="hidden" name="input_checkbox_7" value="" alt="ghost" />
			<input value="1" label_over="0" hide_label="0" title="ORANGE & PECTIN MARMALADE (12x16ml)" type="checkbox" name="input_checkbox_7" class="label_left" />
			<div id="error-message-input_checkbox_7"></div> -->

				<div class="ccms_form_element cfdiv_select" id="label_text_container_div">
					<select size="1" label_over="0" hide_label="0" class="" title="" type="select" name="input_select_165">
						<option value="0" selected>
							0
						</option>

						<option value="1">
							1
						</option>
					</select>

					<div class="clear"></div>

					<div id="error-message-input_select_7"></div>
				</div>
			</td>
		</tr>

		

		

		
	</table><br>
	<br>

	<table class="altrowstable" id="alternatecolor6">
		<tr id="row">
			<td id="column">PLEASE SELECT IF YOU WOULD LIKE:</td>

			<td id="column"> </td>
		</tr>

		<tr id="row">
			<td id="column"><label style="text-transform: uppercase">REPLACEMENT ITEMS for missing products</label></td>

			<td id="column">
				<div class="ccms_form_element cfdiv_radio" id="label_text_container_div">
					<input type="hidden" name="input_radio_6" value="" alt="ghost"> <input type="radio" name="input_radio_6" id="input_radio_6_yes" title="" value="Yes" class=""><label for="input_radio_6_yes">Yes</label> <input type="radio" name="input_radio_6" id="input_radio_6_no" title="" value="No" class=""><label for="input_radio_6_no">No</label>

					<div id="error-message-input_radio_5"></div>
				</div>
			</td>
		</tr>

		<tr id="row">
			<td id="column"><label style="text-transform: uppercase">MIXED ITEMS not listed</label></td>

			<td id="column">
				<div class="ccms_form_element cfdiv_radio" id="label_text_container_div">
					<input type="hidden" name="input_radio_7" value="" alt="ghost"> <input type="radio" name="input_radio_7" id="input_radio_7_yes" title="" value="Yes" class=""><label for="input_radio_7_yes">Yes</label> <input type="radio" name="input_radio_7" id="input_radio_7_no" title="" value="No" class=""><label for="input_radio_7_no">No</label>

					<div id="error-message-input_radio_7"></div>
				</div>
			</td>
		</tr>
		<tr id="row">
			<td id="column"> </td>
			<td id="column"> </td>
		</tr>
		<tr id="row">
			<td id="column"> </td>
			<td id="column"> </td>
		</tr>
		<tr id="row">
			<td id="column">
				<div class="ccms_form_element cfdiv_submit" id="input_submit_1_container_div">
					<input name="input_submit_1" type="submit" style="font-weight: 700; ><input type=; font-weight: 700;" value="Reset!">

					<div class="clear"></div>
					<div id="error-message-input_submit_1"></div>
				</div>
			</td>
			<td id="column"> </td>
		</tr>
	</table>
GreyHead 10 Jan, 2012
Hi arevivo,

I'm afraid that you need to debug your code. From a quick look it seems to fail when you delete a row while you are using the same row in the current for loop index.

Index or size is negative or greater than the allowed amount
[Break On This Error]
for (var j = 0, col; col = row.cells[j]; j++) {



Bob
arevivo 16 Jan, 2012
you are absolutely right. the problem was that all my tables had the same ID.
😶
This topic is locked and no more replies can be posted.

VPS & Email Hosting 20% discount

{item:title} {images:#}