cougar23 Posted October 29, 2008 Share Posted October 29, 2008 I have an array of error messages with keys defined, and I want to output the message associated with a key to the screen, but my code is outputting the key. My array is like this: $studentErrorMessages = array( 'LATE_NEXT_DAY_ERROR' => 'You can not reserve an appointment for the following day after 3:00 PM. Please select another appointment', 'APPT_NOW_RESERVED_ERROR' => 'The requested appointment is no longer available. Please select a different appointment', 'CANCEL_NOT_ALLOWED' => 'You can not cancel your appointment after 3:00 PM the day before your appointment. Please email your advisor if you are unable to attend your scheduled appointment' ); And then my code to output the error message is this: //if key was found in the error messages array, echo javascript to show the message in RED error message color if(array_key_exists($messageKey, $errorMsgDefinitionsArray)){ echo '<script type="text/javascript">'; echo ' document.getElementById("statusMsgDiv").style.display = "block"; '; echo ' document.getElementById("statusMsgOutput").classname = "red bold"; '; echo ' document.getElementById("statusMsgOutput").value = "'.$errorMsgDefinitionsArray[$messageKey].'"; '; echo '</script>'; } So testing, I have set the $messageKey = 'LATE_NEXT_DAY_ERROR' and instead of displaying the error description, it's displaying 'LATE_NEXT_DAY_ERROR' . What am I doing wrong? Thanks for the help ahead of time. Link to comment https://forums.phpfreaks.com/topic/130523-print-value-in-an-array-with-keys-error/ Share on other sites More sharing options...
ranjuvs Posted October 29, 2008 Share Posted October 29, 2008 where you have defined the array $errorMsgDefinitionsArray? Link to comment https://forums.phpfreaks.com/topic/130523-print-value-in-an-array-with-keys-error/#findComment-677152 Share on other sites More sharing options...
cougar23 Posted October 29, 2008 Author Share Posted October 29, 2008 in a definitions.inc file that I include at the top of the page. Right now debugging, the page looks like this: <!-- import common php servier-side functions library --> <?php require_once('../includes/common_fns.inc'); ?> <!-- import directory defintions file --> <?php require_once('definitions.inc'); ?> <!-- DIV TO SHOW STATUS MESSAGE, IF REQUIRED AFTER PAGE RENDERS --> <div id="statusMsgDiv"> <label id="statusMsgOutput"></label> </div> <?php //show status message if necessary after page has rendered; HARD-CODED TEST FOR NOW $_SESSION['statusMsg'] = 'LATE_NEXT_DAY_ERROR'; displayStatusMessageIfRequired($studentErrorMessages, null); ?> and then the function code in common_fns.inc is: //if key was found in the error messages array, echo javascript to show the message in RED error message color if(array_key_exists($messageKey, $errorMsgDefinitionsArray)){ echo '<script type="text/javascript">'; echo ' document.getElementById("statusMsgDiv").style.display = "block"; '; echo ' document.getElementById("statusMsgOutput").classname = "red bold"; '; echo ' document.getElementById("statusMsgOutput").value = "'.$errorMsgDefinitionsArray[$messageKey].'"; '; echo '</script>'; } Link to comment https://forums.phpfreaks.com/topic/130523-print-value-in-an-array-with-keys-error/#findComment-677162 Share on other sites More sharing options...
ranjuvs Posted October 29, 2008 Share Posted October 29, 2008 label doesn't have a value property instead use innerText property instead of this echo ' document.getElementById("statusMsgOutput").value = "'.$errorMsgDefinitionsArray[$messageKey].'"; use echo ' document.getElementById("statusMsgOutput").innerText = "'.$errorMsgDefinitionsArray[$messageKey].'"; Link to comment https://forums.phpfreaks.com/topic/130523-print-value-in-an-array-with-keys-error/#findComment-677181 Share on other sites More sharing options...
cougar23 Posted October 29, 2008 Author Share Posted October 29, 2008 It looks like that worked I think. Thanks to all Link to comment https://forums.phpfreaks.com/topic/130523-print-value-in-an-array-with-keys-error/#findComment-677184 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.