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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Object Expected????

Status
Not open for further replies.

SuaveRick

Programmer
Apr 12, 2004
142
0
0
CA
What the heck, this is the simplest thing and I can't get it to work, I've used the onClick event a hundred times but what is it about this time??

When I call a function from a buton's onClick event I get an error in IE saying Object expected... I can't figure out what's going on here, maybe you guys can:

<html>
<body>
<head>
<?
include('database_functions.inc');//holds the db_connect() function
db_connect('localhost','rick','','test');
function insertrow2($table,$values)
{
//setup the insert statement to be run
$query="insert into $table values ('";
foreach($values as $v)
{
$query=$query+",\'".$v."\'";
};
$query=$query+");";
$result = mysql_query($query) or die(mysql_error());
print mysql_affected_rows()." rows inserted";
}
print "<input type='button' value='insert' onclick=\"insertrow2('users','justin')\">";
mysql_close();
?>
</head>
</body>
</html>
 
Hmmm...
Looks like you are trying to call a PHP function from Javascript.

Just right-click on your browser-> ViewSource, and look for the insertrow2 function's definition.
You will not find it.

PM

___
____
 
Your function is server-side ASP, and does not exist for the onclick event handler to use on the client computer.

Lee
 
That seemed way to easy for you guys yet is definatly the problem. I can't belive I didn't think of that!! I'll switch this over so the page will post back to itself from a form, that'll fix it.

Thanks both of you!

Suave
 
Suave-

I think I might have spotted another error in your code....
Code:
 $query=$qu[COLOR=red]ery+",\'"[/color].$v."\'";

change to:

 $query=$qu[COLOR=green]ery.",\'"[/color].$v."\'";

But I might be wrong on that one....after all, it is 1am here.

Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

robert (at) robertcarpenter (dot) net
 
;-) No problem

Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

robert (at) robertcarpenter (dot) net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top