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? This code has some buttons which change the form’s action attribute and direct the data to different PHP controller file to do different things such as create user, modify user etc
JavaScript code:
<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 code:
<?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";
}
?>
I assume that you have only one form on page. Your code has two errors.
1
To solve your problem, change all
to
2
Also note that formAction is a reserved handler. You can not use formaction as a function name. Change the function name to formActionz or something else: