473,414 Members | 1,594 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

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.



Expand|Select|Wrap|Line Numbers
  1. Code: ( text )
  2. (javascript)
  3. function addToList_city(city) 
  4. {
  5. var c =document.assess_form.cit.value;
  6.  
  7. var fso = new ActiveXObject("Scripting.FileSystemObject");
  8. var s = fso.CreateTextFile("C://test.txt", true);
  9. s.write(c)
  10.  
  11. }


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

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



)


[HTML]<html>
<form name = assess_form.php>
<select name="cit" onchange="addToList_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]
Mar 25 '08 #1
1 1031
pshm
20
hi,
you need to go for AJAX... I think this will help you.

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2. <!--
  3.     var xmlHttpObj;
  4.  
  5.     function getXMLHttpObject()
  6.     {
  7.         var xmlHttp=null;
  8.  
  9.         try{
  10.  
  11.             xmlHttp=new XMLHttpRequest();
  12.         }catch (e){
  13.  
  14.             try{
  15.                 xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  16.             }catch (e){
  17.                 try{
  18.                     xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  19.                 }catch (e){
  20.                     alert("Your browser does not support AJAX!");
  21.                     return false;
  22.                 }
  23.             }
  24.         }                
  25.         return xmlHttp;
  26.       }       
  27.  
  28.       function getTextFromPHP(){                                           
  29.  
  30.             try{
  31.  
  32.                 xmlHttpObj=getXMLHttpObject();                
  33.  
  34.                 if(xmlHttpObj == null){
  35.                     alert('Initialization/ObjectCreation faild');
  36.                     return false;
  37.                 } 
  38.  
  39.  
  40.                 xmlHttpObj.onreadystatechange=changeState;
  41.  
  42.             }catch(err){
  43.                 alert('Error :' + err.description);
  44.             }
  45.  
  46.         var strURL="textLoad.php";  // url for the .php file here
  47.  
  48.  
  49.             xmlHttpObj.open("GET",strURL,true);
  50.             xmlHttpObj.send(null);
  51.  
  52.             return false;
  53.       }
  54.  
  55.     function changeState(){  
  56.         if(xmlHttpObj == null){
  57.             alert('Initialization faild');
  58.             return false;
  59.         } 
  60.  
  61.         switch(xmlHttpObj.readyState){
  62.             case 0:
  63.                 javascript:window.status='Current Status :The request is not initialized';
  64.                 break;
  65.  
  66.             case 1:
  67.                 javascript:window.status='Current Status :The request has been set up';
  68.                 break;
  69.  
  70.             case 2:
  71.                 javascript:window.status='Current Status :The request has been sent';
  72.                 break;
  73.  
  74.             case 3:
  75.                 javascript:window.status='Current Status :The request is in process';
  76.                 break;
  77.  
  78.             case 4:
  79.                 javascript:window.status='Current Status :The request is complete';                
  80.                 document.getElementById('city').value = xmlHttpObj.responseText;               
  81.  
  82.                 break;
  83.         }                               
  84.         return true;
  85.     }   
  86. //-->
  87. </script>
  88.  
  89. <body> 
  90. <form name = "assess_form.php" action="#"> 
  91. <select name="cit" onchange="getTextFromPHP();"> 
  92. <option value="h"> Haryana </option> 
  93. <option value = "c">Chennai</option> 
  94. </select> 
  95. <input type="text" name="city" id="city" />
  96. </form> 
  97. </body>
  98.  
a small change in php code

Expand|Select|Wrap|Line Numbers
  1. // file name : textLoad.php
  2. $filename = "c://test.txt";
  3. if (file_exists($filename)) {
  4.  
  5. $fp = fopen($filename,'r');
  6. $citfile= fread($fp, filesize($filename));
  7. echo $citfile
  8.         }
  9. @unlink($filename);
  10.  
regards,
Psh:)
Mar 25 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Paul | last post by:
How would I convert the contents of a textbox into text files. Say I have a textbox containin the following... 13-02-00 - Paul Oakenfold 06-02-00 - William Orbit 30-01-00 - Laurent Garnier...
3
by: Troy | last post by:
Hello- I have a website that uses a custom built webserver to serve the pages. (Please don't ask me why my boss had his own web server written). I am displaying a log of information that is an...
0
by: Prashant | last post by:
how can i save the contents of a text box which is formatted wit hcolors and different fonts in a word file and retain the same file later in MS word without any problem
10
by: cppdev | last post by:
Hi All! I want to clear the string contents from sensitive information such as passwords, and etc. It's always a case that password will appear as string at some point or another. And i feel...
2
by: Schraalhans Keukenmeester | last post by:
I have a page consisting of three frames. Top frame shows db rows, middle frame shows contents of a file, bottom frame has buttons to change file/row status and/or delete them. The desired...
0
by: Waran | last post by:
I need to create a Auto suggests Textboox like in http://www.google.com/webhp?complete=1&hl=en I have completed this using AJAX.NET for Framework 1.1 . I have some design issues after the data is...
7
by: Arne Beruldsen | last post by:
in vbnet2005 I have a datagridview. When the user clicks on a row...I would like the contents of certain cells to populate a textbox. To do this...i need to be able to refer to the row and...
14
by: Professor Yonce | last post by:
I have made form for E-Mail. I have entered code but the Import system does not work. It has squiggly line underneath it showing it is not communicating. It Will not build. Public Class...
13
by: honey99 | last post by:
Hi! I have to fix a problem in JSP.Actually,i have a JSP page say Ex1.jsp.In this Ex1.jsp i have an anchor tag which links into another JSP page i.e when i click on the link another pop-up window...
6
by: shankari07 | last post by:
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.