Forum Moderators: coopster
whenever the onChange event occurs on the <select name="actionSelect"> tag, the $_SESSION['action'] variable should be modified with the value of the <select> tag.
then at the beginning of the file I say: $_POST['actionSelect'] = $_SESSION['action'] to populate the select bow with the right value after a refresh occurs.
this is the code I have at the moment:
<form name="actionForm" method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<span style="font-size:14px;">Choose an action:</span>
<select name="actionSelect" id="action" onChange="loadMenu()">
<?php
if (isset($_POST['actionSelect']) && $_POST['actionSelect']!= "") {
switch($_POST['actionSelect']) {
case "create": $text = "create new user"; break;
case "delete": $text = "delete user"; break;
case "modify": $text = "modify user"; break;
case "show": $text = "show details"; break;
case "passwd": $text = "change password"; break;
case "who": $text = "show activity"; break;
case "all": $text = "show all users"; break;
}
echo '<option value="'.$_POST[actionSelect].'">'.$text.'</option>';
}
?>
<option value="create">create new user</option>
<option value="delete">delete user</option>
<option value="modify">modify user</option>
<option value="show">show details</option>
<option value="passwd">change password</option>
<option value="who">show activity</option>
<option value="all">show all users</option>
</select>
<hr />
<br />
<div id="menuDiv"></div>
<br />
<hr />
<input type="submit" name="submit" value="submit" />
<input type="reset" name="reset" value="reset fields" />
</form>
as you can see, everytime the <select> tag is changd the javascript function loadMenu() is called, this is the code for loadMenu():
<script language="javascript">
function loadMenu() {
var action = document.getElementById('action').value; if (document.getElementById('action').value == "create") {
document.getElementById('menuDiv').innerHTML = "<table style='font-size:12px;'><tr><td>Username<span style='color:red;'>*</span>:</td><td><input type='text' name='user' value='<?php echo $_POST['user'];?>' /></td></tr><tr><td>Password<span style='color:red;'>*</span>:</td><td><input type='password' name='passwd' /></td></tr><tr><td>Retype password<span style='color:red;'>*</span>:</td><td><input type='password' name='passwd2' /></td></tr><tr><td> </td></tr><tr><td style='font-weight: bold;'>Advanced options</td></tr><tr><td>File quota:</td><td><input type='text' name='file_quota' size='5' /> number of files</td></tr><tr><td>Size quota:</td><td><input type='text' name='size_quota' size='5' /> MB</td></tr><tr><td>Upload ratio:</td><td><input type='text' name='upload_ratio' size='5' /> MB</td></tr><tr><td>Download ratio:</td><td><input type='text' name='download_ratio' size='5' /> MB</td></tr><tr><td>Allowed login start:</td><td><input type='text' name='login_start' size='10'> hhmm</td></tr><tr><td>Allowed login end:</td><td><input type='text' name='login_end' size='10'> hhmm</td></tr></table>";
}
else if (document.getElementById('action').value == "show") {
document.getElementById('menuDiv').innerHTML = "<table style=font-size:12px;'><tr><td>Username:</td><td><select name='user'><?php getAllUsers();?></select></td></tr><tr><td> </td></tr></table>";
}
else if (document.getElementById('action').value == "delete") {
document.getElementById('menuDiv').innerHTML = "<table style='font-size:12px;'><tr><td>Username:</td><td><select name='user'><?php getAllUsers();?></select> <input type='button' name='refresh' value='refresh' onClick='refreshmenu();' /></td></tr><tr><td>Delete content?</td><td><input type='checkbox' name='deleteContent' value='checked' checked /></td></tr></table>";
}
else if (document.getElementById('action').value == "modify") {
document.getElementById('menuDiv').innerHTML = "<table style='font-size:12px;'><tr><td>Username:</td><td><select name='user'><?php getAllUsers();?></select></td></tr><tr><td>Delete content?</td><td><input type='checkbox' name='deleteContent' value='checked' checked /></td></tr></table>";
}
else if (document.getElementById('action').value == "passwd") {
document.getElementById('menuDiv').innerHTML = "<table style='font-size:12px;'><tr><td>Username:</td><td><select name='user'><?php getAllUsers();?></select></td></tr><tr><td>New password<span style='color:red;'>*</span>: </td><td><input type='password' name='passwd' /></td></tr><tr><td>Retype password<span style='color:red;'>*</span>:</td><td><input type='password' name='passwd2' /></td></tr></table>";
}
else if (document.getElementById('action').value == "who") {
document.getElementById('menuDiv').innerHTML = "<table style='font-size:12px;'><tr><td> </td></tr></table>";
}
else if (document.getElementById('action').value == "all") {
document.getElementById('menuDiv').innerHTML = "<table style='font-size:12px;'><tr><td> </td></tr></table>";
}
}
</script>
but I don't know how to change the $_SESSION['action'] value after every onChange event.
grtz
this message put me on the right track:
Javascript (unless specified) is a "client-side" language, meaning that it runs on the clients browser AFTER has page has been compiled and sent from the server. This means that there is no PHP/ASP in the code, only HTML & Javascript.
PHP, ASP, JSP are server-side languages which only run on the server-side.
So to answer your question, no you can't directly get the Javascript to call a PHP (server-side) function, but you can post to a PHP page which will then in turn carry out whatever function u like.