Jump to content

jQuery Change Function


Xtremer360

Recommended Posts

I'm going to be honest I"m not sure what I need to do here. I"m kind of in a funk. When the user gets to the control panel it uses a session to define the variable $defaultCharID which works by the way and then with the dropdown I need whatever the user chooses out of the dropdown to have the change event change the variable to the ID of the newcharacter. Below is a little bit of code from a very similiar type script and my intent is to make it more suitable for my page with the rest of the coding.

 

$defaultCharID = $_SESSION['defaultCharID'];

 

function executeformchangedefaultcharacter(newDefaultCharID) {
            
}

$('#newDefaultCharID').change(function() {
          var newDefaultCharID = $("select#newDefaultCharID").val();

});

 

<form action="#" id="changeCharacter">
<select class="dropdown" name="newDefaultCharID" id="newDefaultCharID" title="Select Character">

 

 

Similar Code Found

print "<form method=POST name=changedefaultcharacter>\n";
print "<input type=hidden name=newdefaultcharacterid value=0>\n";
print "</form>\n";

print "<script type=\"text/javascript\" language=\"javascript\">\n"; 
print "function executeformchangedefaultcharacter(newdefaultcharacterid) {\n";
print "document.changedefaultcharacter.newdefaultcharacterid.value = newdefaultcharacterid;\n";
print "document.changedefaultcharacter.submit();\n";
print "}\n";
print "</script>\n";

print "<form method=POST name=changecharacter>\n";
		print "<select name=newdefaultcharacterid class=dropdown>";

 

Link to comment
Share on other sites

This is all the necessary adjustments. I'm still a little lost how the change event handler can change the variable defaultCharID.

 

<?php

session_start(); // Access the existing session

// Include the database page
include ('inc/dbconfig.php');

// Include the variables page
include ('inc/variables.php');

$userID = $_SESSION['userID'];
$isAdmin = $_SESSION['isAdmin'];
$defaultCharID = $_SESSION['defaultCharID'];
$defaultCharacterName = $_SESSION['defaultCharacterName'];
$firstName = $_SESSION['firstName'];
$lastName = $_SESSION['lastName'];
$defaultCharShortName = $_SESSION['shortName'];

?>

 

<script>
$(document).ready(function() {
    $('#newDefaultCharID').change(function() {
        var newDefaultCharID = $('#newDefaultCharID option:selected').val();
        $('#characterID').val(newDefaultCharID);
        $.ajax({
            type: "POST"
        });  
    });
});
</script>

 

<?php
        if ((isset($userID)) && ($userID > "0")) {
        ?> 
            <div id="headerCharacter">   
        <?php
            if ($isAdmin == "Yes") {
    			$query = "SELECT
    					characters.ID
    				FROM
    					characters"; 
    			$result = mysqli_query ($dbc,$query); 
    			$totalNumCharacters = mysqli_num_rows($result);
    	
    			$query = "SELECT
    					handlerCharacters.ID
    				FROM
    					handlerCharacters
    				INNER JOIN
    					handlers
    				    ON handlers.ID = handlerCharacters.handlerID"; 
    		} else {	
    			$query = "SELECT
    					handlerCharacters.id
    				FROM
    					handlerCharacters
    				INNER JOIN
    					handlers
    				    ON handlers.ID = handlerCharacters.handlerID
    				WHERE
    					handlers.ID = '".$userID."'"; 
    		}
    		$result = mysqli_query ($dbc,$query);
    		$numAvailableCharacters = mysqli_num_rows($result);
            if (($numAvailableCharacters > "1") || (($isAdmin == "Yes") && (isset($totalNumCharacters)) && ($totalNumCharacters > "0"))) {
            ?>
    			<input type="hidden" name="characterID" id="characterID" value="0" />
                <select class="dropdown" name="newDefaultCharID" id="newDefaultCharID" title="Select Character">                
            <?php
    
    			if ($defaultCharID > "0") {
    				print "<option value=".$defaultCharID.">".$defaultCharacterName;
    			} else {
    				print "<option value=0>- Select -";
    			}
                if ($isAdmin == "Yes") {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					WHERE
    						characters.ID <> '".$defaultCharID."' AND
    						characters.statusID = '1'
    					ORDER BY
    						characters.characterName"; 
    			} else {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					INNER JOIN
    					    handlerCharacters
    					    ON characters.ID = handlerCharacters.characterID						
    					INNER JOIN
    						handlers
    					    ON handlers.ID = handlerCharacters.handlerID
    					WHERE
    						handlers.ID = '".$userID."' AND
    						handlerCharacters.characterID <> '".$defaultCharID."' AND
    						characters.statusID = '1'
    					ORDER BY
    						characters.characterName"; 
    			}
    			$result = mysqli_query ($dbc,$query);
    			$numRows = mysqli_num_rows ($result);
    			if ($numRows > 0) {
    				if ($isAdmin == "Yes") {
    					print "<optgroup label=\"** Active Characters **\">";
    				}
                    while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
    					print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r";
    				}
    			}
                if ($isAdmin == "Yes") {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					WHERE
    						characters.ID <> '".$defaultCharID."' AND
    						characters.statusID = '2'
    					ORDER BY
    						characters.characterName"; 
    			} else {
    				$query = "SELECT
    						characters.ID,
    						characters.characterName
    					FROM
    						characters
    					LEFT JOIN
    						handlerCharacters
    					    ON characters.ID = handlerCharacters.characterID						
    					LEFT JOIN
    						handlers
    					    ON handlers.ID = handlerCharacters.handlerID
                        WHERE
    						handlers.ID = '".$userID."' AND
    						handlerCharacters.characterID <> '".$defaultCharID."' AND
    						characters.statusID = '2'
    					ORDER BY
    						characters.characterName"; 
    			}
    			$result = mysqli_query ($dbc,$query); 
    			$numRows = mysqli_num_rows($result);
    			if ($numRows > "0") {
    				print "<optgroup label=\"** Inactive Characters **\">";	
    				while ( $row = mysqli_fetch_array ( $result, MYSQL_ASSOC ) ) {
    				    print "<option value=\"".$row['ID']."\">".$row['characterName']."</option>\r";    
    				}
    			}
                ?>
    			</select>
            <?php
    		} else {
    			print "<h1>".$defaultCharacterName."</h1>\n";
    		}
            ?>
            </div>
        <?php          
        }
        ?>

Link to comment
Share on other sites

  • 3 weeks later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.