Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing a line of code in html

Status
Not open for further replies.

Coogan

Programmer
Jun 21, 2004
38
GB
Hi Guys,

I am trying to find out if it is possible to change a line of html code in another webpage by clicking a button.

Basically I want to change a value on index.htm when i cilck a button on admin.htm

Is this possible? If so can someone please point me in the right direction.

Thanks

Martin
 
You might be able to do it withj Javascript. if you could, for example, surround the line with a <div> or <span> element you could access the html values from there. Best ask in the Javascript forum
 
Ok i am begining to userstand this a lttle bit.

I would use the fopen() command to open the file.
Code:
$myfile = fopen("index.html", "r+")
Then I would need to reset the file pointer to the line of code that I want, say line 83
Code:
fseek($myfile,82)
Then write the data that I want to change.
Code:
fwrite($myfile,"<div id="mystatus">My Status is: OFFLINE</div>")
And all that would need to be done then is close the file.
Code:
fclose($myfile)

Do you think that this would work?? Its seems to be a very simple solution to what I though was going to be very complicated!!

Thanks

Martin
 
Not sure about PHP, but from a general programming perspective you might have trouble with mucking up good parts of the html file if your output isn't exactly the same size as the original.

I would locate the position of the string to change and also the length (to find the start of the data I want left alone). Then read from the end of the string to the end of file into a variable.

Then, write out your string followed by the rest of the file.
 
Just out of interest as your going to use php can you not check a status variable and write out the appropriate line.
What is it your trying to do ?
 
Also look at preg-replace or str-replace if you want to go this route.

A simpler method may invovle a data storage mechanism (db, flatfile) and changing the pages to php. Then changing making changes with the admin page are easily reflected in the index.php page when its connected to the data source

Bastien

Cat, the other other white meat
 
Thanks to everyone for their help on this.

I ended up doing basically what Bastien said. I created a txt file with the information in and then changed the index file to PHP so that I could read the data out of the file and place it where I needed on the page.

One thing I was curious about was calling functions from button clicks. At the moment when i press the button on the admin page it calls another PHP page and makes the changes. Is there anyway that I could code the functions into the admin page rather than having to call another page to make the changes??

Thanks

Martin
 
Because php is a server side language you have to open a page in order for it to run. If you want to run your php code without moving away from your admin.htm then you could use javascript to open a new window which will load the php page that does what you want.
 
You need another "page" to do the work, but it can be in the same PHP file. Try checking to see if a post variable is set, or which button is pressed:

if (isset($_POST["Submit"]))
{
... process form variables
} else
{
... display form
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top