I want the contents of a file to be put in a textbox without refreshing

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shankari07
    New Member
    • Sep 2007
    • 16

    I want the contents of a file to be put in a textbox without refreshing

    hi guys,
    I have a form in html which has the city drop down. when clicking the drop down a javascript is called and a file(test.txt) is created and the city is written into the file.

    Through php i want to open the same file(test.txt), fetch the values and display it in a text box without refreshing or reloading the form. Is it possible.

    After refreshing it works but i want without refreshing the form.

    here is the code.


    Code:
     (javascript)
    function addToList_city(city) 
    {
    var c =document.assess_form.cit.value;
    
    var fso = new ActiveXObject("Scripting.FileSystemObject");
    var s = fso.CreateTextFile("C://test.txt", true);
    s.write(c)
    
    }

    [PHP]$filename = "c://test.txt";
    if (file_exists($f ilename)) {

    $fp = fopen($filename ,'r');
    $citfile= fread($fp, filesize($filen ame));
    }
    @unlink($filena me);[/PHP]

    code: (HTML)
    [HTML]<html>
    <form name = assess_form.php >
    <select name="cit" onchange="addTo List_city(this. form)">
    <option value="h"> Haryana </option>
    <option value = "c">Chennai </option>
    </select>

    <input type="text" name="city" value="<? echo $citfile ?>">
    </form>
    </html>[/HTML]
  • TheServant
    Recognized Expert Top Contributor
    • Feb 2008
    • 1168

    #2
    php is server side which means: it is only done on page load, which is why it won't do anything until you refresh. What you want is javascript (client side) and have it so when you make a selection it runs a javascript function to change the text box contents. I am no javascript pro, so maybe best asking in the javascript forum.

    But yeah, you can't do that in php.

    Comment

    • gamernaveen
      New Member
      • Oct 2007
      • 28

      #3
      Well actually you can. There comes AJAX.
      It cannot be done without refreshing though but it can be done without refreshing the whole page. There are ajax functions to get data from server without refreshing the whole page. Check the AJAX forum.

      Comment

      • ronverdonk
        Recognized Expert Specialist
        • Jul 2006
        • 4259

        #4
        Have a look at the tutorial and demo here Dynamically loaded articles . That will tech and show you how to load pieces of text from the server and update part of the screen dynamically.

        Also have a look at THIS article by Iam Clint in the JavaScript articles section at this site.
        Ronald
        Last edited by ronverdonk; Mar 25 '08, 10:04 AM. Reason: added link

        Comment

        • TheServant
          Recognized Expert Top Contributor
          • Feb 2008
          • 1168

          #5
          Yes, AJAX can solve it. Great tutes btw. I should really learn AJAX sometime.

          Comment

          • arggg
            New Member
            • Mar 2008
            • 91

            #6
            Originally posted by gamernaveen
            Well actually you can. There comes AJAX.
            It cannot be done without refreshing though but it can be done without refreshing the whole page. There are ajax functions to get data from server without refreshing the whole page. Check the AJAX forum.
            AJAX isn't PHP it is Javascript which is basically what the post above you was saying.

            Comment

            • TheServant
              Recognized Expert Top Contributor
              • Feb 2008
              • 1168

              #7
              Originally posted by arggg
              AJAX isn't PHP it is Javascript which is basically what the post above you was saying.
              Yes! So no php, but this can be solved in AJAX. I recommend asking in the AJAX forum if you have more questions.

              Comment

              Working...