Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Error using onchange in select tag on js and php

    Hi,


    Can anyone help with my Error.

    Just to give an idea on my objective.

    I have an user level that a user can choose between "User","Support" and "Admin" Level. If the user choose "Admin" my <div id='userlevel'> will become hidden and vise versa of the level.

    I have tested it on Html and js code it work just fine, but my error begun upon inserting it on php.
    My error on my page said " 'selectmenu' is null or not an object".


    Can anyone help me with this i'm really desperate on this.

    Thanks.

    This is my html and js code
    Code:
    <html>
    <head>
    <form >
    <select id="mymenu" size="1" >
    <option value="nothing">Select a site</option>
    <option value="User">User</option>
    <option value="Support">Support</option>
    <option value="Admin">Admin</option>
    </select>
    <div id="level">
    <table border=1>
    <tr>
    <td>Sample</td>
    </tr>
    </table>
    </div>
    </form>
    
    <script type="text/javascript">
    
    var selectmenu=document.getElementById("mymenu")
    selectmenu.onchange=function(){ //run some code when "onchange" event fires
     var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
     if (chosenoption.value=="Admin"){
     //alert('Did I mention I had a guestbook? Well SIGN IT!');  //open target site (based on option's value attr) in new window
     document.getElementById('level').style.visibility = 'hidden'; 
     }else if(chosenoption.value=="Support"){
      document.getElementById('level').style.visibility = 'visible'; 
     }else if(chosenoption.value=="User"){
      document.getElementById('level').style.visibility = 'visible'; 
     }
    }
    
    </script>
    
    </html>
    My viewsource

    Code:
    	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    	<html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<title>Edit User</title>
    	<link href="css/mystyle.css" rel="stylesheet" type="text/css"/>
    	<script src="jquery\jquery.min.js"></script>
    <script type="text/javascript" src="jquery\jquery.validate.js"></script> 
    
     <script>
      $(document).ready(function(){
      
    	$.validator.addMethod("noSpecialChars", function(value, element) {
    		  return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
    	  }, "<font size='3' color='#FF0000'>Username must contain only letters, numbers, or underscore.</font>");
    	 
        $("#edit").validate({
    	  rules: {
    		pass: "required",
    		rpass: {
    		  equalTo: "#pass"
    		},
    	
    		fname:"required",
    		lname:"required",
    		email:"required email",
    		dept:"required",
    		userlvl:"required"
    	  }
    	  
    	});
      });
      </script>
    <script type="text/javascript">
    
    var selectmenu=document.getElementById("ulvl")
    selectmenu.onchange=function(){ //run some code when "onchange" event fires
     var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
     if (chosenoption.value=="Admin"){
      document.getElementById('userlevel').style.visibility = 'hidden'; 
     }else if(chosenoption.value=="Support"){
      document.getElementById('userlevel').style.visibility = 'visible'; 
     }else if(chosenoption.value=="User"){
      document.getElementById('userlevel').style.visibility = 'visible'; 
     }
    }
    
    </script>
     <style type="text/css">
    body {
    
    font-family: arial; /* you need some backups here */
    font-size: 17px;
    
    }
    </style> 
    </head>
    <body>
    <br/>
    <br/>
    <p>		
    <table BORDERCOLOR="#0B0B0B" border='1' bgcolor="#F5F5FA" width="70%" align='center'  >
    <tr>
    	<td width="100%" align="left" valign="middle">
    		<img src='img/editprofile.png'>
    	</td>
    </tr>
    <tr>
    <td width="100%" align='center' >
    
    	<table>
    	<form method='post' id='edit' name='edit' action='edituser.php?UserName=Alphee' onSubmit="javascript: var x=window.confirm('Do you wan\'t to save this User?');if (!x) return(false);">
    	<tr>
    		<input type='hidden' value=Alphee name='uname'>
    		<td align='right'><b>User Name:</b></td>	
    		<td align='left'>Alphee</td>
    	</tr>
    	<tr>
    		<td align='right'><b>First Name:</b></td>
    		<td align='left'><input type='text' id='fname' value='Alphee' name='fname'></td>
    	</tr>
    	<tr>
    		<td align='right'><b>Last Name:</b></td>
    		<td align='left'><input type='text' id='lname'  value='Saspa' name='lname'></td>
    	</tr>	
    	<tr>
    		<td align='right'><b>Email Address:</b></td>
    		<td align='left'><input type='text' size='35' id='email' value='myemail.com' name='email'></td>
    	</tr>
    	<tr>
    		<td align='right'><b>Department:</b></td>
    		<td align='left'>
    		<select name='dept' tabindex='8'><option >MIS</option><option >Acct</option><option >HR</option></select>		</td>
    	</tr>
    	<tr>
    		<td  align='right'><b>User Level:</b></td>
    		<td align='left'>
    		<select class='ulvl' id='ulvl' name='ulvl' tabindex='9' ><option Selected=Selected>User</option><option value='User'>User</option><option value='Support'>Support</option><option value='Admin'>Admin</option></select></td></tr></table><div class='userlevel' id='userlevel'><tr><td align='center'><b>User Access</b></td></tr><tr><td><input type='checkbox' name='CreateTicket'>Create Ticket<br><input type='checkbox' name='AddUser' >Add User<br><input type='checkbox' name='EditProfile' >Edit/Delete User<br><input type='checkbox' name='ResetPass'>Reset Password<br><input type='checkbox' name='Department'>Add Department<br><input type='checkbox' name='Category'>Add Category<br><input type='checkbox' name='SubCategory'unchecked>Add Sub-Category</td></tr></div>	<tr>
    		<td align='center' >
    		<input type='submit' value='Save' name='save' title='Save User'>
    		</td>
    	</tr>
    	</form>
    </td>	
    
    
    </tr>	
    </table>
    
    	</body>
    	</html>
    My actual code with js and php
    PHP Code:
    <?php
    session_start
    ();
    if(isset( 
    $_SESSION['username'])){
    include_once(
    "conn.php");    
    ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Edit User</title>
        <link href="css/mystyle.css" rel="stylesheet" type="text/css"/>
        <script src="jquery\jquery.min.js"></script>
    <script type="text/javascript" src="jquery\jquery.validate.js"></script> 

     <script>
      $(document).ready(function(){
      
        $.validator.addMethod("noSpecialChars", function(value, element) {
              return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
          }, "<font size='3' color='#FF0000'>Username must contain only letters, numbers, or underscore.</font>");
         
        $("#edit").validate({
          rules: {
            pass: "required",
            rpass: {
              equalTo: "#pass"
            },
        
            fname:"required",
            lname:"required",
            email:"required email",
            dept:"required",
            userlvl:"required"
          }
          
        });
      });
      </script>
    <script type="text/javascript">

    var selectmenu=document.getElementById("ulvl")
    selectmenu.onchange=function(){ //run some code when "onchange" event fires
     var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
     if (chosenoption.value=="Admin"){
      document.getElementById('userlevel').style.visibility = 'hidden'; 
     }else if(chosenoption.value=="Support"){
      document.getElementById('userlevel').style.visibility = 'visible'; 
     }else if(chosenoption.value=="User"){
      document.getElementById('userlevel').style.visibility = 'visible'; 
     }
    }

    </script>
     <style type="text/css">
    body {

    font-family: arial; /* you need some backups here */
    font-size: 17px;

    }
    </style> 
    </head>
    <body>
    <br/>
    <br/>
    <p>        
    <table BORDERCOLOR="#0B0B0B" border='1' bgcolor="#F5F5FA" width="70%" align='center'  >
    <tr>
        <td width="100%" align="left" valign="middle">
            <img src='img/editprofile.png'>
        </td>
    </tr>
    <tr>
    <td width="100%" align='center' >
    <?php
    if(isset($_POST['save'])){
            
    //User Access
            
    if(isset($_POST['CreateTicket'])){
            
    $CreateTicket='1';
            }else{
            
    $CreateTicket='0';
            }
            if(isset(
    $_POST['AddUser'])){
            
    $AddUser='1';
            }else{
            
    $AddUser='0';
            }
            if(isset(
    $_POST['Department'])){
            
    $Department='1';
            }else{
            
    $Department='0';
            }
            if(isset(
    $_POST['Category'])){
            
    $Category='1';
            }else{
            
    $Category='0';
            }
            if(isset(
    $_POST['SubCategory'])){
            
    $SubCategory='1';
            }else{
            
    $SubCategory='0';
            }
            if(isset(
    $_POST['EditProfile'])){
            
    $UserEdit='1';
            }else{
            
    $UserEdit='0';
            }
            if(isset(
    $_POST['ResetPass'])){
            
    $PassReset='1';
            }else{
            
    $PassReset='0';
            }
    mssql_query("sp_edituser @lname='$_POST[lname]',@fname='$_POST[fname]',@upby='$_SESSION[username]',@uname='$_POST[uname]',@userlevel='$_POST[ulvl]',@email='$_POST[email]',@department='$_POST[dept]',@Cticket='$CreateTicket',@AddUser='$AddUser',@adept='$Department',@acat='$Category',@asubcat='$SubCategory',@edituser='$UserEdit',@pass='$PassReset'");
        
    mssql_close($con);
            echo 
    "<b><p align='center'><font color='#F0000' size='3'>User has been edit.</font></p></b>";
        }
        
        
    $d=mssql_query("Select * from vw_dept");
        
        
    $lvl=mssql_query("spvw_userlevel @username='$_GET[UserName]' ");
        
    //$lvl=mssql_query("Select UserLevel from tblUser where UserName='$_GET[UserName]'");
        
    $row=mssql_fetch_array(mssql_query("spview_edituser @username='$_GET[UserName]'"));
    //print "<meta http-equiv='refresh' content='=2;Viewuser.php'/>";    

    ?>

        <table>
        <form method='post' id='edit' name='edit' action='edituser.php?UserName=<?php echo $row['UserName'];?>' onSubmit="javascript: var x=window.confirm('Do you wan\'t to save this User?');if (!x) return(false);">
        <tr>
            <input type='hidden' value=<?php echo $row['UserName'];?> name='uname'>
            <td align='right'><b>User Name:</b></td>    
            <td align='left'><?php echo $row['UserName'];?></td>
        </tr>
        <tr>
            <td align='right'><b>First Name:</b></td>
            <td align='left'><input type='text' id='fname' value='<?php  echo $row['Firstname'];?>' name='fname'></td>
        </tr>
        <tr>
            <td align='right'><b>Last Name:</b></td>
            <td align='left'><input type='text' id='lname'  value='<?php  echo $row['Lastname'];?>' name='lname'></td>
        </tr>    
        <tr>
            <td align='right'><b>Email Address:</b></td>
            <td align='left'><input type='text' size='35' id='email' value='<?php echo $row['Email'];?>' name='email'></td>
        </tr>
        <tr>
            <td align='right'><b>Department:</b></td>
            <td align='left'>
            <?php
                    
                
    echo "<select name='dept' tabindex='8'>";
                while(
    $dept=mssql_fetch_array($d)){
                    echo 
    "<option ";
                    if (
    $row['dept']==$dept['DeptName']) echo "Selected=Selected";
                    echo 
    ">".$dept['DeptName']."</option>";
                }
                    echo 
    '</select>';
            
    ?>
            </td>
        </tr>
        <tr>
            <td  align='right'><b>User Level:</b></td>
            <td align='left'>
            <?php echo "<select class='ulvl' id='ulvl' name='ulvl' tabindex='9' >";
                while(
    $level=mssql_fetch_array($lvl)){
                    echo 
    "<option ";
                    if (
    $row['UserLevel']==$level['UserLevel']) echo "Selected=Selected";
                    echo 
    ">".$level['UserLevel']."</option>";
                    
                }
                echo 
    "<option value='User'>User</option>";
                    echo 
    "<option value='Support'>Support</option>";
                    echo 
    "<option value='Admin'>Admin</option>";
                    echo 
    '</select>';
        
            echo 
    "</td>";
        echo 
    "</tr>";
        
        echo 
    "</table>";
            if(
    $UserAccess=mssql_fetch_array(mssql_query("sp_useraccess @username='$_GET[UserName]',@userlevel='Admin'"))){
        echo 
    "<div class='userlevel' id='userlevel'>";
        echo 
    "<tr>";
        echo 
    "<td align='center'>";
        echo 
    "<b>User Access</b>";
        echo 
    "</td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
            echo 
    "<td>";
                echo
    "<input type='checkbox' name='CreateTicket'";  if(trim($UserAccess[CreateTicket])=='1'){echo 'checked';}echo ">Create Ticket<br>";
                echo 
    "<input type='checkbox' name='AddUser' "; if(trim($UserAccess[AddUser])=='1'){echo 'checked';}echo">Add User<br>";
                echo 
    "<input type='checkbox' name='EditProfile' ";if(trim($UserAccess[AEditUser])=='1'){echo 'checked';}echo">Edit/Delete User<br>";
                echo 
    "<input type='checkbox' name='ResetPass'"; if(trim($UserAccess[APass])=='1'){echo 'checked';} echo">Reset Password<br>";
                echo 
    "<input type='checkbox' name='Department'"; if(trim($UserAccess[ADept])=='1'){echo 'checked';} echo">Add Department<br>";
                echo 
    "<input type='checkbox' name='Category'";  if(trim($UserAccess[ACat])=='1'){echo 'checked';}echo">Add Category<br>";
                echo 
    "<input type='checkbox' name='SubCategory'";  if(trim($UserAccess[ASubCat])=='1'){echo 'checked';}else{ echo 'unchecked';}echo">Add Sub-Category";
                
            echo 
    "</td>";
        echo 
    "</tr>";
        echo 
    "</div>";
        }
        
    ?>
        <tr>
            <td align='center' >
            <input type='submit' value='Save' name='save' title='Save User'>
            </td>
        </tr>
        </form>
    </td>    


    </tr>    
    </table>

        </body>
        </html>
    <?php
    }else{ //not logged in
        
    header('location: login.php');
    }
    ?>
    Last edited by ryoka012; 09-06-2011 at 12:45 PM.

  • #2
    Kor
    Kor is offline
    Red Devil Mod Kor's Avatar
    Join Date
    Apr 2003
    Location
    Bucharest, ROMANIA
    Posts
    8,478
    Thanks
    58
    Thanked 379 Times in 375 Posts
    You refer an element which was not loaded, as the loading process is sequential, from top to bottom. Try to nest your codes into a function and launch it onload:
    Code:
    <script type="text/javascript">
    function attachOnchange(){
    var selectmenu=document.getElementById("mymenu")
    selectmenu.onchange=function(){ //run some code when "onchange" event fires
     var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
     if (chosenoption.value=="Admin"){
     //alert('Did I mention I had a guestbook? Well SIGN IT!');  //open target site (based on option's value attr) in new window
     document.getElementById('level').style.visibility = 'hidden'; 
     }else if(chosenoption.value=="Support"){
      document.getElementById('level').style.visibility = 'visible'; 
     }else if(chosenoption.value=="User"){
      document.getElementById('level').style.visibility = 'visible'; 
     }
    }
    }
    </script>
    And use the JQuery code to launch it:
    Code:
    $(document).ready(function(){
    attachOnchange();
    ... // the rest of the JQuery code below
    }
    KOR
    Offshore programming
    -*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*

  • #3
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the help..
    I tried what you have suggested. it does not have give an error but the it does not give the out put,This is what is have done.
    can you elaborate more..Thanks for the help.

    My php code.
    PHP Code:
    <?php
    session_start
    ();
    if(isset( 
    $_SESSION['username'])){
    include_once(
    "conn.php");    
    ?>
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <head>
            <title>Edit User</title>
        <link href="css/mystyle.css" rel="stylesheet" type="text/css"/>
        <script src="jquery\jquery.min.js"></script>
    <script type="text/javascript" src="jquery\jquery.validate.js"></script> 

     <script>
      $(document).ready(function(){
      attachOnchange();
        $.validator.addMethod("noSpecialChars", function(value, element) {
              return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
          }, "<font size='3' color='#FF0000'>Username must contain only letters, numbers, or underscore.</font>");
         
        $("#edit").validate({
          rules: {
            pass: "required",
            rpass: {
              equalTo: "#pass"
            },
        
            fname:"required",
            lname:"required",
            email:"required email",
            dept:"required",
            userlvl:"required"
          }
          
        });
      });
      </script>
    <script type="text/javascript">
    function attachOnchange(){
    var selectmenu=document.getElementById("ulvl")
    selectmenu.onchange=function(){ //run some code when "onchange" event fires
     var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
     if (chosenoption.value=="Admin"){
     //alert('Did I mention I had a guestbook? Well SIGN IT!');  //open target site (based on option's value attr) in new window
     document.getElementById('level').style.visibility = 'hidden'; 
     }else if(chosenoption.value=="Support"){
      document.getElementById('level').style.visibility = 'visible'; 
     }else if(chosenoption.value=="User"){
      document.getElementById('level').style.visibility = 'visible'; 
     }
    }
    }
    </script>
     <style type="text/css">
    body {

    font-family: arial; /* you need some backups here */
    font-size: 17px;

    }
    </style> 
    </head>
    <body>
    <br/>
    <br/>
    <p>        
    <table BORDERCOLOR="#0B0B0B" border='1' bgcolor="#F5F5FA" width="70%" align='center'  >
    <tr>
        <td width="100%" align="left" valign="middle">
            <img src='img/editprofile.png'>
        </td>
    </tr>
    <tr>
    <td width="100%" align='center' >
    <?php
    if(isset($_POST['save'])){
            
    //User Access
            
    if(isset($_POST['CreateTicket'])){
            
    $CreateTicket='1';
            }else{
            
    $CreateTicket='0';
            }
            if(isset(
    $_POST['AddUser'])){
            
    $AddUser='1';
            }else{
            
    $AddUser='0';
            }
            if(isset(
    $_POST['Department'])){
            
    $Department='1';
            }else{
            
    $Department='0';
            }
            if(isset(
    $_POST['Category'])){
            
    $Category='1';
            }else{
            
    $Category='0';
            }
            if(isset(
    $_POST['SubCategory'])){
            
    $SubCategory='1';
            }else{
            
    $SubCategory='0';
            }
            if(isset(
    $_POST['EditProfile'])){
            
    $UserEdit='1';
            }else{
            
    $UserEdit='0';
            }
            if(isset(
    $_POST['ResetPass'])){
            
    $PassReset='1';
            }else{
            
    $PassReset='0';
            }
    mssql_query("sp_edituser @lname='$_POST[lname]',@fname='$_POST[fname]',@upby='$_SESSION[username]',@uname='$_POST[uname]',@userlevel='$_POST[ulvl]',@email='$_POST[email]',@department='$_POST[dept]',@Cticket='$CreateTicket',@AddUser='$AddUser',@adept='$Department',@acat='$Category',@asubcat='$SubCategory',@edituser='$UserEdit',@pass='$PassReset'");
        
    mssql_close($con);
            echo 
    "<b><p align='center'><font color='#F0000' size='3'>User has been edit.</font></p></b>";
        }
        
        
    $d=mssql_query("Select * from vw_dept");
        
        
    $lvl=mssql_query("spvw_userlevel @username='$_GET[UserName]' ");
        
    //$lvl=mssql_query("Select UserLevel from tblUser where UserName='$_GET[UserName]'");
        
    $row=mssql_fetch_array(mssql_query("spview_edituser @username='$_GET[UserName]'"));
    //print "<meta http-equiv='refresh' content='=2;Viewuser.php'/>";    

    ?>

        <table>
        <form method='post' id='edit' name='edit' action='edituser.php?UserName=<?php echo $row['UserName'];?>' onSubmit="javascript: var x=window.confirm('Do you wan\'t to save this User?');if (!x) return(false);">
        <tr>
            <input type='hidden' value=<?php echo $row['UserName'];?> name='uname'>
            <td align='right'><b>User Name:</b></td>    
            <td align='left'><?php echo $row['UserName'];?></td>
        </tr>
        <tr>
            <td align='right'><b>First Name:</b></td>
            <td align='left'><input type='text' id='fname' value='<?php  echo $row['Firstname'];?>' name='fname'></td>
        </tr>
        <tr>
            <td align='right'><b>Last Name:</b></td>
            <td align='left'><input type='text' id='lname'  value='<?php  echo $row['Lastname'];?>' name='lname'></td>
        </tr>    
        <tr>
            <td align='right'><b>Email Address:</b></td>
            <td align='left'><input type='text' size='35' id='email' value='<?php echo $row['Email'];?>' name='email'></td>
        </tr>
        <tr>
            <td align='right'><b>Department:</b></td>
            <td align='left'>
            <?php
                    
                
    echo "<select name='dept' tabindex='8'>";
                while(
    $dept=mssql_fetch_array($d)){
                    echo 
    "<option ";
                    if (
    $row['dept']==$dept['DeptName']) echo "Selected=Selected";
                    echo 
    ">".$dept['DeptName']."</option>";
                }
                    echo 
    '</select>';
            
    ?>
            </td>
        </tr>
        <tr>
            <td  align='right'><b>User Level:</b></td>
            <td align='left'>
            <?php echo "<select class='ulvl' id='ulvl' name='ulvl' tabindex='9' >";
                while(
    $level=mssql_fetch_array($lvl)){
                    echo 
    "<option ";
                    if (
    $row['UserLevel']==$level['UserLevel']) echo "Selected=Selected";
                    echo 
    ">".$level['UserLevel']."</option>";
                    
                }
                echo 
    "<option value='User'>User</option>";
                    echo 
    "<option value='Support'>Support</option>";
                    echo 
    "<option value='Admin'>Admin</option>";
                    echo 
    '</select>';
        
            echo 
    "</td>";
        echo 
    "</tr>";
        
        echo 
    "</table>";
            if(
    $UserAccess=mssql_fetch_array(mssql_query("sp_useraccess @username='$_GET[UserName]',@userlevel='Admin'"))){
        echo 
    "<div class='ulvl' id='ulvl'>";
        echo 
    "<tr>";
        echo 
    "<td align='center'>";
        echo 
    "<b>User Access</b>";
        echo 
    "</td>";
        echo 
    "</tr>";
        echo 
    "<tr>";
            echo 
    "<td>";
                echo
    "<input type='checkbox' name='CreateTicket'";  if(trim($UserAccess[CreateTicket])=='1'){echo 'checked';}echo ">Create Ticket<br>";
                echo 
    "<input type='checkbox' name='AddUser' "; if(trim($UserAccess[AddUser])=='1'){echo 'checked';}echo">Add User<br>";
                echo 
    "<input type='checkbox' name='EditProfile' ";if(trim($UserAccess[AEditUser])=='1'){echo 'checked';}echo">Edit/Delete User<br>";
                echo 
    "<input type='checkbox' name='ResetPass'"; if(trim($UserAccess[APass])=='1'){echo 'checked';} echo">Reset Password<br>";
                echo 
    "<input type='checkbox' name='Department'"; if(trim($UserAccess[ADept])=='1'){echo 'checked';} echo">Add Department<br>";
                echo 
    "<input type='checkbox' name='Category'";  if(trim($UserAccess[ACat])=='1'){echo 'checked';}echo">Add Category<br>";
                echo 
    "<input type='checkbox' name='SubCategory'";  if(trim($UserAccess[ASubCat])=='1'){echo 'checked';}else{ echo 'unchecked';}echo">Add Sub-Category";
                
            echo 
    "</td>";
        echo 
    "</tr>";
        echo 
    "</div>";
        }
        
    ?>
        <tr>
            <td align='center' >
            <input type='submit' value='Save' name='save' title='Save User'>
            </td>
        </tr>
        </form>
    </td>    


    </tr>    
    </table>

        </body>
        </html>
    <?php
    }else{ //not logged in
        
    header('location: login.php');
    }
    ?>
    View Source
    Code:
    	<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    	<html xmlns="http://www.w3.org/1999/xhtml">
    	<head>
    		<title>Edit User</title>
    	<link href="css/mystyle.css" rel="stylesheet" type="text/css"/>
    	<script src="jquery\jquery.min.js"></script>
    <script type="text/javascript" src="jquery\jquery.validate.js"></script> 
    
     <script>
      $(document).ready(function(){
      attachOnchange();
    	$.validator.addMethod("noSpecialChars", function(value, element) {
    		  return this.optional(element) || /^[a-z0-9\_]+$/i.test(value);
    	  }, "<font size='3' color='#FF0000'>Username must contain only letters, numbers, or underscore.</font>");
    	 
        $("#edit").validate({
    	  rules: {
    		pass: "required",
    		rpass: {
    		  equalTo: "#pass"
    		},
    	
    		fname:"required",
    		lname:"required",
    		email:"required email",
    		dept:"required",
    		userlvl:"required"
    	  }
    	  
    	});
      });
      </script>
    <script type="text/javascript">
    function attachOnchange(){
    var selectmenu=document.getElementById("ulvl")
    selectmenu.onchange=function(){ //run some code when "onchange" event fires
     var chosenoption=this.options[this.selectedIndex] //this refers to "selectmenu"
     if (chosenoption.value=="Admin"){
     //alert('Did I mention I had a guestbook? Well SIGN IT!');  //open target site (based on option's value attr) in new window
     document.getElementById('level').style.visibility = 'hidden'; 
     }else if(chosenoption.value=="Support"){
      document.getElementById('level').style.visibility = 'visible'; 
     }else if(chosenoption.value=="User"){
      document.getElementById('level').style.visibility = 'visible'; 
     }
    }
    }
    </script>
     <style type="text/css">
    body {
    
    font-family: arial; /* you need some backups here */
    font-size: 17px;
    
    }
    </style> 
    </head>
    <body>
    <br/>
    <br/>
    <p>		
    <table BORDERCOLOR="#0B0B0B" border='1' bgcolor="#F5F5FA" width="70%" align='center'  >
    <tr>
    	<td width="100%" align="left" valign="middle">
    		<img src='img/editprofile.png'>
    	</td>
    </tr>
    <tr>
    <td width="100%" align='center' >
    
    	<table>
    	<form method='post' id='edit' name='edit' action='edituser.php?UserName=Alphee' onSubmit="javascript: var x=window.confirm('Do you wan\'t to save this User?');if (!x) return(false);">
    	<tr>
    		<input type='hidden' value=Alphee name='uname'>
    		<td align='right'><b>User Name:</b></td>	
    		<td align='left'>Alphee</td>
    	</tr>
    	<tr>
    		<td align='right'><b>First Name:</b></td>
    		<td align='left'><input type='text' id='fname' value='Alphee' name='fname'></td>
    	</tr>
    	<tr>
    		<td align='right'><b>Last Name:</b></td>
    		<td align='left'><input type='text' id='lname'  value='Saspa' name='lname'></td>
    	</tr>	
    	<tr>
    		<td align='right'><b>Email Address:</b></td>
    		<td align='left'><input type='text' size='35' id='email' value='myemail.com' name='email'></td>
    	</tr>
    	<tr>
    		<td align='right'><b>Department:</b></td>
    		<td align='left'>
    		<select name='dept' tabindex='8'><option >MIS</option><option >Acct</option><option >HR</option></select>		</td>
    	</tr>
    	<tr>
    		<td  align='right'><b>User Level:</b></td>
    		<td align='left'>
    		<select class='ulvl' id='ulvl' name='ulvl' tabindex='9' ><option Selected=Selected>User</option><option value='User'>User</option><option value='Support'>Support</option><option value='Admin'>Admin</option></select></td></tr></table><div class='level' id='level'><tr><td align='center'><b>User Access</b></td></tr><tr><td><input type='checkbox' name='CreateTicket'>Create Ticket<br><input type='checkbox' name='AddUser' >Add User<br><input type='checkbox' name='EditProfile' >Edit/Delete User<br><input type='checkbox' name='ResetPass'>Reset Password<br><input type='checkbox' name='Department'>Add Department<br><input type='checkbox' name='Category'>Add Category<br><input type='checkbox' name='SubCategory'unchecked>Add Sub-Category</td></tr></div>	<tr>
    		<td align='center' >
    		<input type='submit' value='Save' name='save' title='Save User'>
    		</td>
    	</tr>
    	</form>
    </td>	
    
    
    </tr>	
    </table>
    
    	</body>
    	</html>

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks a lot it works..i just adjusted my markup element on Div and it works.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •