user3207387 user3207387 - 4 years ago 101
HTML Question

How on one click another page div value change using JavaScript?

I have two page page1.php, page2.php and one JS file Control.js.

In page1.php


<img src="images/b.jpg" width="31" height="26" id="imgClick1" onClick="return changeImage1(this)" >

In Control.js

function changeImage1() {

document.getElementById("imgClick1").src = "images/b.jpg";
document.getElementById('num1').style.color = "#fff";
document.getElementById("text1").innerHTML = "Hello friend";

In page2.php

<div id="text1">
Hello world

So using JavaScript I am trying to write "hello friend" in the div "text1" of page page2.php when I click the image or the div of page1.php.

  1. Is there any possible way to use JS to solve this problem?

  2. Can we use any how
    or something like that in the program?

Answer Source

I suggest you make use of the include function of php (provided you absolutely want to keep your text1 div on a separate page), like this on your page1.php file:


Make sure that when you do that, page1.php and page2.php are in the same folder, otherwise you may define a path to it like this:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download