is null or not an object

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
zyntrax
Forum Commoner
Posts: 32
Joined: Wed Apr 13, 2011 2:23 am
Location: Sweden

is null or not an object

Post by zyntrax »

document.form.ban is null or not an object, i can't figure out why!
Does anyone have an idea? Thank you.

Code: Select all

<script type="text/javascript" language="javascript">
function hide_show_combo()
{
	if(document.form.ban.selectedIndex == 0) 
	{
		document.form.day.style.visibility = "hidden";
		document.form.min.style.visibility = "hidden";
	}
	else if(document.form.ban.selectedIndex == 1)
	{
		document.form.day.style.visibility = "hidden";
		document.form.min.style.visibility = "hidden";
	}
	else 
	{
		document.form.day.style.visibility = "visible";
		document.form.min.style.visibility = "visible";
	}
}
</script>
<?php
include 'config.php';
include 'opendb.php';

$query = "SELECT * FROM characters;";
if($result = mysql_query($query))  
{
	if($success = mysql_num_rows($result) > 0)
	{
		echo '<form action="process.php" method="post">';
		while ($row = mysql_fetch_array($result))
		{
			echo '<input type="checkbox" name="characters[]" value="'.$row['username'].'" /><a href="character.php?username='.$row['username'].'">'.$row['character_name'].'</a><br />';
		}
		
	}
}
else 
{ 
	echo "Failed to connect to database."; 
}
?>
<br />
<br />

<h3>User(s) role</h3>
<select name="role">
<option value="" selected>No change</option>
<option value="guest">Guest</option>
<option value="user">User</option>
<option value="mod">Moderator</option>
<option value="admin">Administrator</option>
</select>

<br />
<br />

<h3>Ban</h3>
<select name="ban" onchange="hide_show_combo();">
<option value="0" selected>No</option>
<option value="1">Forever</option>
<option value="2">Temp</option>
</select>

<select name="day" style="visibility: hidden;">
<option value="" selected>Days</option>
<?php
	for($i=0; $i<=32; $i=$i+1)
	{
		echo '<option value="'.$i.'">'.$i.'</option>';
	}
?>
</select>

<select name="min" style="visibility: hidden;">
<option value="" selected>Minutes</option>
<?php
	for($i=0; $i<=61; $i=$i+1)
	{
		echo '<option value="'.$i.'">'.$i.'</option>';
	}
?>
</select>
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: is null or not an object

Post by AbraCadaver »

The correct way to access it if you have only the one form is:

[text]document.forms[0].ban.selectedIndex[/text]
Or name the form and use the name instead of forms[0].
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
zyntrax
Forum Commoner
Posts: 32
Joined: Wed Apr 13, 2011 2:23 am
Location: Sweden

Re: is null or not an object

Post by zyntrax »

Oh wow yeah i forgot the name of the form, it was named before but i must have accidently removed it. Anyway thank you so much.
Post Reply