0

Hi All,

Just a quick one,

My code (Below) works in Internet Explorer, but not in Chrome, Safari or Mozilla Firefox. Not sure why, but would it be possible for someone to point me in the right direction?

Thanks!

Code attached;

<script language="javascript">

function formAction(flag) {
	switch (flag){
		case "create": 
			document.forms.useraction.action = "/apps/portal_admin/create_user1.php";
			break;
		case "modify":
			document.forms.useraction.action = "/apps/portal_admin/modify_user1.php";
			break;
		case "copy":
			document.forms.useraction.action = "/apps/portal_admin/copy_user1.php#user2";
			break;
	}
	document.forms.useraction.submit();
}
function helloworld() {
	alert("Hello World");
}
</script>
<?php
	if ($authlib->auth_authobj($posting_userid,$_COOKIE['shost_app_id'],'002')>=2) {
		echo "<input type=\"button\" value=\"Create User\" class=\"formButton\" name=\"create\" id=\"create\" onClick=\"formAction('create')\">\n";
		echo "<input type=\"button\" value=\"Copy User\" class=\"formButton\" name=\"copy\" onClick=\"formAction('copy')\">\n";
	}
	if ($authlib->auth_authobj($posting_userid,$_COOKIE['shost_app_id'],'002')>=3) {
		echo "<input type=\"button\" value=\"Edit User\" class=\"formButton\" name=\"modify\" onClick=\"formAction('modify')\">\n";
		echo "<input type=\"button\" value=\"This button works\" class=\"formButton\" name=\"Working\" onClick=\"helloworld()\">\n";
	}
?>

Everything else in my file works just fine, including my testing button - but I don't know whether my Javascript function for "formAction(flag)" works properly. (Even though it does on IE7/8/9.

Anybody have any suggestions?

Thanks!

2
Contributors
4
Replies
5
Views
5 Years
Discussion Span
Last Post by Coyx
0

I assume that you have only one form on page,
so to solve your problem, change all

document.forms.useraction.action

to

document.useraction.action

Edited by urtrivedi: n/a

0

Thanks for your prompt reply Urtrivedi!

Unfortunately, that didn't work either. It seems that (After placing an Alert right after the function call before the "switch(flag)") - and testing again, it didn't even pop the alert.

function formAction(flag) {
	alert("Testing");
	switch (flag){
		
		case "create": 
			document.useraction.action = "/apps/portal_admin/create_user1.php";
			break;
		case "modify":
			document.useraction.action = "/apps/portal_admin/modify_user1.php";
			break;
		case "copy":
			document.useraction.action = "/apps/portal_admin/copy_user1.php#user2";
			break;
	}
	document.useraction.submit();
}
0

I don't know if this will help, but the Chrome Javascript Error Console states;

Uncaught TypeError: string is not a function
(anonymous function)list_user1.php:469
onclick

0

HAH! Found it. Right on the mark to go home too. :P

Okay, it turns out that "formAction" is a reserved handler... and therefore, back in the day when this was just the name of my function and it worked... it's been fine, but since HTML5 made it a reserved handler... it wouldn't work.

I simply added a "z" to the end of each place that calls the function, then added a "z" to the end of the function name, and hey presto, it works in every browser.

WOOOO.

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.