473,382 Members | 1,424 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,382 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.  (javascript)
  2. function addToList_city(city) 
  3. {
  4. var c =document.assess_form.cit.value;
  5.  
  6. var fso = new ActiveXObject("Scripting.FileSystemObject");
  7. var s = fso.CreateTextFile("C://test.txt", true);
  8. s.write(c)
  9.  
  10. }

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

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

code: (HTML)
[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
6 1935
TheServant
1,168 Expert 1GB
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.
Mar 25 '08 #2
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.
Mar 25 '08 #3
ronverdonk
4,258 Expert 4TB
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
Mar 25 '08 #4
TheServant
1,168 Expert 1GB
Yes, AJAX can solve it. Great tutes btw. I should really learn AJAX sometime.
Mar 25 '08 #5
arggg
91
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.
Mar 25 '08 #6
TheServant
1,168 Expert 1GB
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.
Mar 25 '08 #7

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

Similar topics

3
by: GraVity via DotNetMonster.com | last post by:
Hello all I am new to asp.net or web programming I have a requirement, I have to submit a document to another server using my webpage, there is a perticular protocol for doing that. This protocol...
2
by: jdi | last post by:
Hello, I have a seemingly basic question about ASP.NET. I would like to create a page containing an image, which keeps swapping the url of the image source, without refreshing the entire page. ...
3
by: Aitham alama | last post by:
Hi There, My question is as following, I have a webform (Webform1) which contains one label control and command button, when the user clicks the button another webform (Webform2) appears,...
2
by: Ben | last post by:
Hi, One ASP.NET transactional page conducts a long transaction in a button click function. I want to display the transaction progress info in label control without refreshing page. It is...
3
by: user | last post by:
Hi, let's say a page loads on a browser. Without refreshing the page, multiple textboxes within the page gets real time data @ a few seconds interval. what is the logic behind to achieve...
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...
1
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...
3
by: manuitpro | last post by:
Hi All, I have page with many tabs, in one of the tab i have a form (only a input box) and i want to show some output on the same tab view based on the user input. (bvy using php function) I...
1
by: adige | last post by:
Hi. I would like to automatically fill in the textbox labeled "Amount 2" after choosing the value of Amount without refreshing the page. I guess it requires javascript or AJAX but i don't know how...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.