tags:

views:

62

answers:

5

My code is like this:

<script type="text/javascript">
    $(document).ready(function(){
    $("Edit").click(function(){
    $.get('fetchvalues.php');
        });
    });
</script>

<input id="Edit" name="Edit" value="Edit Record" type="button" onclick="$.get('fetchvalues.php');" />

In the file "fetchvalues.php", I have written some code along with the javascript alert window to see whether the control reaches there. But nothing is happening.

Am I calling correctly?

+1  A: 

You are making an HTTP request but not doing anything with it.

See the documentation — you need to specify a callback.

David Dorward
At least the alert window must popup. Nothing happening.
RPK
Where and how to specify callback?
RPK
The documentation that I linked to explains (and has examples)
David Dorward
+4  A: 
$("Edit").click(function(){

This should be:

$("#Edit").click(function(){

And if you have that you don't need it again in the click="" HTML attribute.

Also try your debugging alert with:

$.get('fetchvalues.php', null, function() { alert('test'); });

Also it's not very clear to me where you put the alert() in your original code. In the HTML code outputted from fetchvalues.php ? If yes then it will never be executed; you would have to load the file by adding a directive to your html file through javascript.


EDIT: Answering question asked in the comments here for better formatting.

When we call "fetchvalues.php", how to know it is being called.

You could temporarily erase all the code in fetchvalues.php and replace it with:

<?php print "Whatever you want"; ?>

After that, replace your $.get with:

$.get('fetchvalues.php', null, function(php_output_text) { alert(php_output_text); });

That should alert() "Whatever you want"!


Live demo: http://koper.wowpanda.net/so.html

Andreas Bonini
Nothing happening. The javascript code is not executing in fetchvalues.php
RPK
See my edit ....
Andreas Bonini
Still nothing. What to write in "fetchvalues.php" to check when the control reaches there?
RPK
What do you mean "when the control reaches there"? If you mean the javascript control, it never will. Javascript in fetchvalues.php will never be executed if called with $.get()!
Andreas Bonini
When we call "fetchvalues.php", how to know it is being called.
RPK
See edit.......
Andreas Bonini
$.get('fetchvalues.php', null, function(php_output_text) { alert(php_output_text); });Why php_output_text needs to be written here? Assume, it is generated dynamically then?
RPK
huh? It's the output of the HTTP file you requested.. I don't really understand what you're asking :(
Andreas Bonini
Ok, so I can give any variable there that will hold the output?
RPK
Yes ----------------
Andreas Bonini
And I need to remove the Onclick that I wrote from the Input tags?
RPK
You can leave it if you want but it's not needed (as long as you change from "Edit" to "#Edit" like I said in my answer)
Andreas Bonini
Ya, I like it that way. So I have removed. Still not getting any alert, that I included as you suggested.
RPK
Can you upload both files somewhere in the internet so I can test it and see what's wrong?
Andreas Bonini
Added below. See new post at the end.
RPK
A: 

should be $("#Edit") instead of $("Edit")

Anwar Chandra
A: 

@Koper:

Done like this:

 <script type="text/javascript">
   $(document).ready(function(){
  $("#Edit").click(function(){
     $.get('fetchvalues.php', null, function(data) { alert('reached'); });
  });
   });
 </script>

fetchvalues.php only contains:

print ("This is a test");

Still the alert is not executing.

RPK
I tested this code locally and it works. The only explanation for which it doesn't is that "fetchvalues.php" doesn't exist. Do note that it has to be in the same directory as the html page with the js code!
Andreas Bonini
The folder in which the file containing the above code is, there itself is located fetchvalues.php. But it is not working.
RPK
Well I don't know what to say then, it works locally for me. You can try to open fetchvalues.php from your browser directly; you should see a blank page with "This is a test" and nothing else (if you don't see that, there is a problem with the .php file). I'm afraid there is not much else I can do to help unless you are willing to upload the files on some website.
Andreas Bonini
Nevermind, I uploaded it myself: http://koper.wowpanda.net/so.html .. As you can see it works. If you see the HTML code you'll notice that it's the same as yours.
Andreas Bonini
Ok. Thanks for your extended help. Now when there is nothing left with the code, it must be the missing file. I will check it.Thanks again for your time.
RPK
A: 
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.cookie.js"></script>
<?php
    if ($_Session['WorkMode'] == 'UPDATE')
    {
     $query = "SELECT * from listing WHERE recordid = ". $_Session['RowID'];
     mysql_connect('localhost:3306','abcd','abcd');
     mysql_selectdb('pglobal');
     $result = mysql_query($query);

     while ($row = mysql_fetch_array($result))
     {
      $JobDate = $row['ldate'];
      $Company = $row['company'];
      $Places = $row['places'];
      $Designation = $row['designation'];
      $ProjectDetails = $row['projectdetails'];
      $DesiredCandidate = $row['desiredcandidate'];
      $HRName = $row['hrname'];
      $HRContact = $row['hrcontact'];
      $Email = $row['email'];

      echo "<script type='text/javascript'>";
      echo "document.getElementByID('LDate').value = '". $JobDate ."'";


      echo "</script>";
     }
    }
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt;
<html>
    <head>
     <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></meta>
     <link rel="stylesheet" href="css/wysiwyg.css" type="text/css">
     <script type="text/javascript" src="js/wysiwyg.js"></script>
     <script type="text/javascript" src="js/wysiwyg-settings.js"></script>
     <script src="js/calendar.js" type="text/javascript"></script>
     <link href="js/calendar.css" type="text/css" rel="stylesheet" />

     <script type="text/javascript">
      WYSIWYG.attach('all', full);
     </script>
     <script type="text/javascript" src="../js/funcAjaxCallToPHP.js"></script>

     <script type="text/javascript">
       $(document).ready(function(){
          $("#Edit").click(function(){
             $.get('fetchvalues.php', null, function(data) { alert('reached'); });
          });
       });
     </script>


     <title>Job Listing Entry</title>
    </head>
    <body>
     <table id="main" cols="2">
     <tr> 
     <td>
     <Form id="frmNewEntry" method="post" action="insert_listing.php">
      <table id="tblEntry" cols="3" style="border-color:lightblue; border-style:solid;">
       <tr><td colspan="3" bgcolor="lightblue" align="center"><strong>Real-Time Vacancy Entry</strong></td></tr>
       <tr><td>Date:</td><td><input id="LDate" name="LDate" type="text" size="20" maxlength="11"/>[Select Date from the Calendar Control]
        <script type="text/javascript">
         calendar.set("LDate");
        </script></td>
        <td>
         <table>
          <tr>
           <td rowspan="6">
           <!-- <iframe src="show_db_vacancy_entries.php" height="800px" width="300px" bordercolor="cyan">

            </iframe> -->
           </td>
          </tr>
         </table>
        </td>
       </tr>
       <tr><td>Places:</td><td><input id="Places" name="Places" type="text" size="35" maxlength="30" onblur="this.value=MakeInitialCapital(this.value);"></td></tr>
       <tr><td>Company:</td><td><input id="Company" name="Company" type="text" size="50" onblur="this.value=MakeInitialCapital(this.value);">
       <!-- <input type="button" value="Make Initial Capital" align="left" onclick="this.value=MakeInitialCapital(this.value);"></tr> -->
       <tr><td>Designation:</td><td><input id="Designation" name="Designation" type="text" size="50" onblur="this.value=MakeInitialCapital(this.value);"></td></tr>
       <tr><td>Project Details:</td><td><textarea id="ProjectDetails" name="ProjectDetails" cols="100" rows="10"></textarea></td></tr>
       <tr><td>Desired Candidate:</td><td><textarea id="DesiredCandidate" name="DesiredCandidate" rows="3" cols="100"></textarea> <br></td></tr>
       <tr><td>HR Name:</td><td><input id="HRName" name="HRName" type="text" size="50" onblur="this.value=MakeInitialCapital(this.value);"> <br></td></tr>
       <tr><td>HR Contact:</td><td><input id="HRContact" name="HRContact" type="text" size="50"> <br></td></tr>
       <tr><td>Email:</td><td><input id="Email" name="Email" type="text" size="50"> <br></td></tr>
       <tr></tr>
       <tr>
        <td  bgcolor="lightblue">
         <input id="Clear" name="Clear" value="Clear" type="button" onclick="ClearFields();">
        </td> 
        <td bgcolor="lightblue">
         <input id='Submit' name='Submit' value='Submit' type='button' />
        </td>
       </tr>

      </table>
     </Form>
     </td>
     <td>
      <table id="list" cols="2" style="border:none">
       <tr>
        <td colspan="2" style="border:none">
         <iframe src="show_db_vacancy_entries.php" height="800px" style="border:none;">

         </iframe>
        </td>
       </tr>
       <tr>
        <td align="left">
         <input id="Edit" name="Edit" value="Edit Record" type="button"  />
        </td>
        <td align="right">
         <input id="Delete" name="Delete" value="Delete" type="button" />
        </td>     
       </tr>
      </table>
     </td>
     </tr>
     </table>
    </body>
</html>

<script language="JavaScript" type="text/javascript">
    function MakeInitialCapital(str)
    {
       return str.toLowerCase().replace(/\b[a-z]/g, cnvrt);
        function cnvrt() {
            return arguments[0].toUpperCase();
        }

    }

    //Convert initials to capital in a certain control
    function MakeInitialCapitalControl(controlName)
    {
    var ctrl = document.getElementById(controlName).value;

    if(/^[A-Z]/.test(ctrl.value)) {
        ctrl.value = ctrl.value.toLowerCase();
        return;
    }        

   /* ctrl.value = ctrl.value.toLowerCase().replace(/\b[a-z]/g, function {
        return arguments[0].toUpperCase();
    });*/
    }

    function ClearFields()
    {
     document.getElementById('Email').value = "";
     document.getElementById('HRContact').value = "";
     document.getElementById('HRName').value = "";
     document.getElementById('DesiredCandidate').value = "";
     document.getElementById('ProjectDetails').value = "";
     document.getElementById('Designation').value = "";
     document.getElementById('Company').value = "";
     document.getElementById('Places').value = "";
     document.getElementById('LDate').value = "";
    }

</script>
RPK