Jump to content

Function Not Defined. (found The Error But It Was Not What I Thought)


ckrudelux

Recommended Posts

Why is my function not defined?

<?php	include "../dbconnect.php";		function managegroups($table, $type, $object_id){		$id = md5($table.$type.$object_id.rand(0000,9999));				echo "<div id=\"".$id."\">";			echo "<div class=\"items\">";				$select = mysql_query("SELECT * FROM groups");				while($row = mysql_fetch_assoc($select)){				?>					<div onclick="addgroup('<?php echo $id;?>', '<?php echo $row['g_id'];?>', '<?php echo $row['name'];?>');" class="item1"><?php echo $row['name']?></div>				<?php				}			echo "</div>";			echo "<div class\"selecteditems\">";				$select = mysql_query("SELECT * FROM $table WHERE type='$type' and object_id='$object_id'");				while($row = mysql_fetch_assoc($select)){					$g_id = $row['g_id'];					$select2 = mysql_query("SELECT * FROM groups WHERE g_id='$g_id'");					while($row2 = mysql_fetch_assoc($select2)){					?>						<div onclick="alertsometext();" class="item1"><?php echo $row2['name']?></div>					<?php					}				}			echo "</div>";		echo "</div>";	}?><!DOCTYPE html>	<head>		<style type="text/css">			.item1 {				float: left;				margin: 5px;				padding: 5px;				cursor: pointer;				border: 1px solid #000;				background: #888;			}		</style>				<script type="text/javascript">			function addgroup(objectid, objectgid, objectname){				alert("Started");				var main = document.getElementById(objectid);				var allDivs = main.getElementsByTagName('<div>');								var i = 0;				for(i=0; i < allDivs.length; i++){					alert("Loop");					if(allDivs[i].classname == "selecteditems"){						alert("Statment true");						allDivs[i] += "<div class=\"item1\">"objectname"</div>";					}				}			}		</script>	</head>	<body>		<?php			managegroups("paragraph_groups", "1", "84");		?>	</body></html>

Link to comment
Share on other sites

Because you have a syntax error in it.While not a syntax error, getElementsByTagName is supposed to be used thus:

var allDivs = main.getElementsByTagName('div');

Also, Chrome seems to be baulking at the lack of a return statement.You should really use a tool like Firebug so you can more easily debug your JavaScript code.

Link to comment
Share on other sites

I'm not sure what you're doing here either:allDivs += "<div class=\"item1\">"objectname"</div>";allDivs is a div element, not a string. You're trying to concatenate a string with a div element (your syntax error is in that line also, BTW). I'm not sure what that's going to do, but it's probably not going to be what you expect.

Link to comment
Share on other sites

I'm not sure what you're doing here either:allDivs += "<div class=\"item1\">"objectname"</div>";allDivs is a div element, not a string. You're trying to concatenate a string with a div element (your syntax error is in that line also, BTW). I'm not sure what that's going to do, but it's probably not going to be what you expect.
Should have been allDivs.innerHTML += "<div class=\"item1\">"objectname"</div>";
Link to comment
Share on other sites

That's still not right, you need to use the concatenation operator (+) to join two strings together.

Link to comment
Share on other sites

That's still not right, you need to use the concatenation operator (+) to join two strings together.
Well it works.. I don't know how bad it is but works in all my browsers. (OPERA, CHROME, FIREFOX and IE)
Link to comment
Share on other sites

Well, it's syntactically incorrect :) are you sure it's working as you expect? Is that line even being executed? If you installed Firebug (or similar), any errors will be reported in the console.

Link to comment
Share on other sites

Well, it's syntactically incorrect :) are you sure it's working as you expect? Is that line even being executed? If you installed Firebug (or similar), any errors will be reported in the console.
I got firebug installed and no it can't find any errors, and yes it works as expected and yes the line is executed.(If you want to see it for your self I can add an account so you can test it for your self.)
Link to comment
Share on other sites

Did you do the replacement justsomeguy was talking about? If we have to spell it literally, the code needs to look like:

allDivs[i].innerHTML += "<div class=\"item1\">" + objectname + "</div>";

Link to comment
Share on other sites

Did you do the replacement justsomeguy was talking about? If we have to spell it literally, the code needs to look like:
allDivs[i].innerHTML += "<div class=\"item1\">" + objectname + "</div>";

Yes it does.. :)
Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...