0

Hi guys!

I'm back with more problems! I've tried everything... I just can't seem to get it to work. :(

Okay, a short explanation of what the goal is.

I have 5 buttons, and a list of records which are pulled from the database.

Import CSV
Create
Edit
Delete
View Details

Each one runs through a validation check to make sure the radio button (which is assigned the value of the employee ID in the database) - then it performs the action submit and submits to X php file to do the deed. For some reason though, I'm getting quite a few errors and the buttons either don't work (have no reaction to being clicked), don't pass through the variables, or anything! As the code stands before I touched it; the error console is stating "radioButton is undefined" - so... god knows.

Here's the code:

<script language="Javascript">

function returnSelection(radioButton) {
	var selection=null;
	for(var i=0; i<radioButton.length; i++) {
	
		if(radioButton[i].checked) {
			selection=radioButton[i].value;
			return selection;
		}
	}
	return selection;
}

function importCSV() {
// Import CSV Files
	document.forms.emp_list.newurl.value='import_csv.php';
	document.forms.emp_list.session_name.value='employee';
	document.forms.emp_list.action='import_csv.php';
	document.forms.emp_list.submit()
}

function createNew() {
// Update form action to submit to the beginning of the Create functionality
	document.forms.emp_list.newurl.value='create_employee.php';
	document.forms.emp_list.session_name.value='employee';
	document.forms.emp_list.action='create_employee.php';
	document.forms.emp_list.submit()
}
function noneselwarn() {
	alert("There are no employees to delete.");
}
function removeEmployees() {
// Update form action to submit to the View Detail page
	document.forms.emp_list.session_name.value='employee';
	document.forms.emp_list.action='emp_delete.php';
	document.forms.emp_list.submit()
}
function removeEmployee() {
// Validate that an exisitng report has been selected
	if (returnSelection(document.forms.emp_list.userSelection) == null) {
		alert("You must select an employee to erase in order to perform this function.");
		return false;
	}
// Update form action to submit to the delete page
	document.forms.emp_list.session_name.value='employee';
	document.forms.emp_list.action='emp_delete.php';
	document.forms.emp_list.submit()
}

function viewDetail() {
// Validate that an exisitng report has been selected
	if (returnSelection(document.forms.emp_list.userSelection) == null) {
		alert("You must select an employee to view in order to perform this function.");
		return false;
	}
// Update form action to submit to the View Detail page
	document.forms.emp_list.session_name.value='employee';
	document.forms.emp_list.action='emp_view.php';
	document.forms.emp_list.submit()
}

function changeDetail() {
// Validate that an exisitng report has been selected
	if (returnSelection(document.forms.emp_list.userSelection) == null) {
		alert("You must select an employee to view in order to perform this function.");
		return false;
	}
		
// Update form action to submit to modify the employee.
	document.forms.emp_list.session_name.value='employee';
	document.forms.emp_list.action='modify_employee.php';
	document.forms.emp_list.submit()
}

</script>

The HTML in reference;

<form method="get" action="emp_search_unused.php" name="emp_list">
		<input type="hidden" name="session_name" class="formButton">
		<input type="hidden" name="newurl" class="formButton">
<?php print("<tr valign=\"middle\" align=\"left\" onmouseover=\"this.style.backgroundColor='#c4daf0'\" onmouseout=\"this.style.backgroundColor=''\">\n"); ?>											
<td align="center">											<input type="radio" name="userSelection" value="<?=$clientfields_array[0]?>" class="formButton">											</td>
<td  align="center"><font face="Verdana" size="1">											<?php echo $clientfields_array[2]; ?>											</font></td>
<td  align="center"><font face="Verdana" size="1">
<?php echo $clientfields_array[3]; ?>
</font></td>
<td  align="center"><font face="Verdana" size="1">
<?php echo $clientfields_array[8]; ?>
<?php echo $clientfields_array[9]; ?>
</font></td>
<td  align="center"><font face="Verdana" size="1">
<?php if ($clientfields_array[13] == 2) { echo "Female"; }
if ($clientfields_array[13] == 1) { echo "Male"; } 
?>
</font></td>
<td  align="center"><font face="Verdana" size="1">
<?php echo $clientfields_array[14]; ?>
</font></td>
<td  align="center"><font face="Verdana" size="1">
<?php echo $clientfields_array[10]; ?>
</font></td>
</tr><input type="button" value="Import CSV" class="formButton" onClick="importCSV()">
<input type="button" value="Create" class="formButton" onClick="createNew()">
<input type="button" value="Edit" class="formButton" onClick="changeDetail()">
								
<?php
if ($counts==1) {
echo "<input type=\"button\" value=\"Delete\" class=\"formButton\" onClick=\"removeEmployees()\">";
} elseif($counts>1) {
echo "<input type=\"button\" value=\"Delete\" class=\"formButton\" onClick=\"removeEmployee()\">";
} else {
echo "<input type=\"button\" value=\"Delete\" class=\"formButton\" onClick=\"noneselwarn()\">";
}
?>
<input type="button" value="View Detail" onClick="viewDetail()" class="formButton">
</form>

Some bits are missing as they're just table cells and what not, but that's the general gist of the HTML that hits the Javascript then is supposed to go to the PHP to do the action. All the HTML and PHP works as intended, it's just the buttons and posting the information that don't work. :(

Any help would be GREATLY appreciated!

Much love!

Edited by Coyx: fixed up the code to display half decent

2
Contributors
1
Reply
6
Views
6 Years
Discussion Span
Last Post by stbuchok
0

Use document.getElementById('idOfFormElement'); instead of document.forms.idOfFormElement. Clean this up first and then if you still have issues I will try to help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.