Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5957071
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:20:54+00:00 2026-05-22T18:20:54+00:00

/* In the following code there is a dropdownlist, that has to call the

  • 0

/*
In the following code there is a dropdownlist, that has to call the function on every change has occurred to it.
This function name is TotalCountsOfPL().
And the drop down list is name and Id is “sltLeaveType”;

After the function called a textbox(AjxSelectedLeaveType) should be filled with the selected value of the dropdownlist.

And the textbox(AjxTakenLeave) should be filled be filled with count which has been fetched by the database.

*/

I have the used the Ajax concept in my project.

That is on the change of Dropdownlist I am calling the function(method). But this is not working.

Means when I select the content of dropdownList selected data(option) should be displayed in the text field called

my html file is
I have the used the Ajax concept in my project.

That is on the change of Dropdownlist I am calling the function(method). But this is not working.

my html file is

<html>
<head>
<script>
    function TotalCountsOfPL(str)
    {   
        if(iset(session_unregister("mySessionVariable")))
        {
            session_destroy();
        };       
        session_start();
        session_register("mySessionVariable");
        if(str!="")
        {
            $_SESSION["mySessionVariable"] = str;           
            document.getElementById("AjxSelectedLeaveType").innerHTML=str;
        }
        if (str=="")
        {
          document.getElementById("AjxTakenLeave").innerHTML="";
          //document.getElementById("AjxLeaveType").innerHTML="";
          return;
        }
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
                document.getElementById("AjxTakenLeave").innerHTML=xmlhttp.responseText;
            }
        }

        xmlhttp.open("POST","getPLCount.php",true);
        xmlhttp.send();
    }
</script>
</head>
<body>
<?php
}

$prevEmployeeId= (isset($_POST['cmbEmployeeId'])) ? $_POST['cmbEmployeeId'] : "";
$prevLeaveFromDate = (isset($_POST['txtLeaveFromDate'])) ? $_POST['txtLeaveFromDate'] : "";
$prevLeaveToDate = (isset($_POST['txtLeaveToDate'])) ? $_POST['txtLeaveToDate'] : "";
$prevLeaveType = (isset($_POST['sltLeaveType'])) ? $_POST['sltLeaveType'] : "";
$prevToTime = (isset($_POST['sltLeaveToTime'])) ? $_POST['sltLeaveToTime'] : "";+
// Gnanendra .. Here I have consider the variable  $prevFromTime as "Total days" selected by the dropdownlist
$prevFromTime = (isset($_POST['sltLeaveFromTime'])) ? $_POST['sltLeaveFromTime'] : "";
//G Comment below
$prevTotalTime = (isset($_POST['txtLeaveTotalTime'])) ? $_POST['txtLeaveTotalTime'] : "";

$prevComments = (isset($_POST['txtComments'])) ? $_POST['txtComments'] : "";

$timeElementClass = (!empty($prevLeaveFromDate) && ($prevLeaveFromDate == $prevLeaveToDate)) ?
                        "show" : "hide";

$AjxSelectedLeaveType=(isset($_POST['AjxSelectedLeaveType'])) ? $_POST['AjxSelectedLeaveType'] : "";
$AjxTakenLeave=(isset($_POST['AjxTakenLeave'])) ? $_POST['AjxTakenLeave'] : "";
?>


<form id="frmLeaveApp" name="frmLeaveApp" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?leavecode=Leave&amp;action=<?php 

echo $modifier; ?>">
<input type="hidden" value="<?php echo $token;?>" name="token" />
<?php if (isset($confirmDate)) { ?>
    <input type="hidden" name="confirmDate" value="<?php echo $prevLeaveFromDate; ?>"/>
<?php } ?>

    <?php if (isset($role)) { ?>
      <?php if(($role == authorize::AUTHORIZE_ROLE_ADMIN) || ($role == authorize::AUTHORIZE_ROLE_SUPERVISOR)){ ?>
        <label for="cmbEmployeeId"><?php echo $lang_Leave_Common_EmployeeName; ?><span class="required">*</span></label>
        <div>
        <input type="hidden" name="cmbEmployeeId" id="cmbEmployeeId" value="<?php echo isset($prevEmployeeId) ? $prevEmployeeId : ""; ?>" />


        <div class="yui-ac" id="employeeSearchAC" style="float: left">
        <input name="txtEmployeeId" autocomplete="off" class="yui-ac-input" id="txtEmployeeId" type="text" value="<?php echo isset($empName) ? 

CommonFunctions::escapeHtml($empName) : ""; ?>" tabindex="2" onfocus="showAutoSuggestTip(this)" style="color: #999999" />
              <div class="yui-ac-container" id="employeeSearchACContainer" style="top: 28px; left: 10px;">
              <div style="display: none; width: 159px; height: 0px; left: 100em" class="yui-ac-content">
              <div style="display: none;" class="yui-ac-hd"></div>
              <div class="yui-ac-bd">
                    <ul>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                          <li style="display: none;"></li>
                        </ul>
                      </div>
                     <div style="display: none;" class="yui-ac-ft"></div>
                    </div>
                   <div style="width: 0pt; height: 0pt;" class="yui-ac-shadow"></div>
              </div>
        </div>
        </div>
        <br class="clear"/>
      <?php } ?>
    <?php } ?>

    <label for="sltLeaveType"><?php echo $lang_Leave_Common_LeaveType; ?></label>
    <select name="sltLeaveType" id="sltLeaveType" class="formSelect" onchange="TotalCountsOfPL(this.value)">
        <?php
            $skippedLeaveTypesCount = 0;

            if (is_array($records[1])) {
                foreach ($records[1] as $record) {
                    $className = get_class($record);

                    if ($className == 'LeaveQuota') {
                        if ($record->isLeaveQuotaDeleted()) {
                            $skippedLeaveTypesCount++;
                            continue;
                        }
                    }

                    $selected = ($record->getLeaveTypeID() == $prevLeaveType) ? 'selected="selected"' : "";
        ?>
            <option <?php echo $selected;?> value="<?php echo $record->getLeaveTypeID();?>"><?php echo $record->getLeaveTypeName(); 

?></option>
            <?php       }

                        if ($skippedLeaveTypesCount == count($records[1])) { ?>
                                <option value="-1">-- <?php echo $lang_Error_NoLeaveTypes; ?> --</option>
                        <?php }
                } else { ?>
            <option value="-1">-- <?php echo $lang_Error_NoLeaveTypes; ?> --</option>
            <?php } ?>
    </select>
    <br class="clear"/>
<!--Gnanendra Here the Leave date range will get-->
     <?php
        if (!(is_array($records[1])) && ($modifier == 'Leave_Apply')) {  ?>
            <div class="notice"><?php echo $lang_Leave_Common_LeaveQuotaNotAllocated; ?></div>
            <br class="clear"/>
     <?php } ?>

        <label for="txtLeaveFromDate"><?php echo $lang_Leave_Common_FromDate; ?><span class="required">*</span></label>

        <input name="txtLeaveFromDate" type="text" id="txtLeaveFromDate" size="10"
            value="<?php echo $prevLeaveFromDate; ?>" class="formDateInput"/>
          <input type="button" name="Submit" value="  " class="calendarBtn" id="btFromDate"/>
        <br class="clear"/>

        <label for="txtLeaveToDate"><?php echo $lang_Leave_Common_ToDate; ?><span class="required">*</span></label>
        <input name="txtLeaveToDate" type="text" id="txtLeaveToDate" size="10"
            value="<?php echo $prevLeaveToDate; ?>" class="formDateInput"/>

          <input type="button" name="Submit" value="  " class="calendarBtn" id="btToDate"/>
        <br class="clear"/>


      <div id="trTime1" class="<?php echo $timeElementClass;?>">
       <label for="sltLeaveFromTime"><?php echo $lang_Leave_Common_FromTime; ?></label> 
    <?php $lang_Leave_Common_FromTime="Total Days"; ?>
    <label for="sltLeaveFromTime"><?php echo $lang_Leave_Common_FromTime; ?></label>
    <select name="sltLeaveFromTime" id="sltLeaveFromTime" onchange="fillTimes();"
                class="formTimeSelect"> 
        <select name="sltLeaveFromTime" id="sltLeaveFromTime" onchange="FillTheDayLength();"
                class="formTimeSelect">
            <option value=""></option>
            <!-- It will the time to the drop downlist (00:00 to 23:59) -->

            <?php
                for ($i=$startTime; $i<=$endTime; $i+=$interval) {
                    $timeVal = date('H:i', $i);
                    $selected = ($timeVal == $prevFromTime) ? 'selected="selected"' : "";
            ?>
                    <option <?php echo $selected; ?> value="<?php echo $timeVal; ?>" ><?php echo LocaleUtil::getInstance()->formatTime($timeVal); 

?></option>
            <?php } ?>

           </select>

        <label for="sltLeaveToTime"><?php echo $lang_Leave_Common_ToTime; ?></label>
        <select name="sltLeaveToTime" id="sltLeaveToTime" onchange="fillTimes();"
                class="formTimeSelect">
            <option value=""></option>
            <?php
                for ($i=$startTime; $i<=$endTime; $i+=$interval) {
                    $timeVal = date('H:i', $i);
                    $selected = ($timeVal == $prevToTime) ? 'selected="selected"' : "";

                ?>
                    <option <?php echo $selected; ?> value="<?php echo $timeVal; ?>" ><?php echo LocaleUtil::getInstance()->formatTime($timeVal); 

?></option>
            <?php } ?>
            </select>
        <br class="clear"/>

        <label for="txtLeaveTotalTime"><?php echo $lang_Leave_Common_TotalHours; ?></label>
        <input name="txtLeaveTotalTime" id="txtLeaveTotalTime" size="4" onchange="fillTimes();"
                value="<?php echo $prevTotalTime; ?>" class="formInputText" style="width:3em;"/>

        <br class="clear"/>
      </div>
      <div id="trTime2" class="<?php echo $timeElementClass;?>">
      </div>

      <div id="trTime3" class="<?php echo $timeElementClass;?>">

      </div>
      <div id="trTime4" class="<?php echo $timeElementClass;?>">
      </div>
      <br class="clear"/>
      <label for="txtComments"><?php echo $lang_Leave_Common_Comment; ?></label>
      <textarea name="txtComments" id="txtComments" class="formTextArea" rows="3" cols="20"
        ><?php echo $prevComments;?></textarea>


<!-- -->


        <input name="AjxSelectedLeaveType" type="text" id="AjxSelectedLeaveType" size="30"
            value="<?php (isset($_POST['AjxSelectedLeaveType'])) ? $_POST['AjxSelectedLeaveType'] : "Leave Type";?>" class="formDateInput"/>

         <input name="AjxTakenLeave" type="text" id="AjxTakenLeave" size="30"
            value="<?php (isset($_POST['AjxTakenLeave'])) ? $_POST['AjxTakenLeave'] : "Taken Leave";?>" class="formDateInput"/>

<!-- -->
      <br class="clear"/>
        <div class="formbuttons">
            <input type="button" class="<?php echo $btnClass;?>" id="saveBtn"
                onclick="addSave();" onmouseover="moverButton(this);" onmouseout="moutButton(this);"
                value="<?php echo $btnTitle;?>" title="<?php echo $btnTitle;?>"/>
        </div>
</form>
</div>

</body>


And the Following is getPLCount.php


<?php

$q=$_POST["AjxSelectedLeaveType"];

$Eid=$_SESSION["mySessionVariable"];

$con = mysql_connect('localhost', 'gnuser', 'anu123');
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("My_Database", $con);

$EmployeeId= $q;

if (isset($q))
{
    $query = "select count(leave_request_id) from leave_requests
where leave_type_id='LTY002' AND employee_id=".$q.";";
}
if(isset($Eid))
{
    $query = "select count(leave_request_id) from leave_requests
where leave_type_id='LTY002' AND employee_id=".$Eid.";";
}

$result = mysql_query($query);

echo "document.getElementById("AjxTakenLeave").innerHTML={$result}";

mysql_close($con);
?>

Please any one tell me why its not working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T18:20:55+00:00Added an answer on May 22, 2026 at 6:20 pm

    You are mixing PHP with JavaScript. Here for example:

     if(str!="")
            {
                $_SESSION["mySessionVariable"] = str;           
                document.getElementById("AjxSelectedLeaveType").innerHTML=str;
            }
    

    $_SESSION is PHP and document.getElementById is JavaScript.

    Javascript is executed on the client side (ie: the broweser) and PHP is executed on your server. You can not mix them like that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code that won't compile and although there is a way
Given the following code, is there a way I can call class A's version
In the following code there is function(i), but i hasn't been declared anywhere previous
Please, explain, why in the following code there is no error: void f() {
My program/process exited abnormally? I doubt something is wrong with the following code: There
The following code continues to be displayed even if there are entries in my
Is there any difference to the following code: class Foo { inline int SomeFunc()
Is there any performance penalty for the following code snippet? for (int i=0; i<someValue;
Hi there im using the following code for insert text and images, but I
With the following code below, There is an error saying File /home/user/web_pro/info/views.py, line 184,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.