473,396 Members | 2,014 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,396 software developers and data experts.

XMLHttpRequest - Change Value getElementById

Hi,

I want the button on the second page to change the value of the button in the first page,this is my code:

FILE 1: Index.html(page one):

Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2.    "http://www.w3.org/TR/html4/strict.dtd">
  3.  
  4. <html lang="en">
  5. <head>
  6.     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  7.     <title>Eran Exercise</title>
  8.     <link rel="stylesheet" type="text/css" href="design.css" />
  9.     <script src="new_file.js"></script>
  10.  
  11. </head>
  12. <body>
  13.  
  14.         <div class="wrapper">
  15.  
  16.               <form> 
  17. <input type="button" id="id200" value="New Window!" onClick="window.open('page2.html','mywindow','width=400,height=200')"> 
  18.  
  19. </form> 
  20.  
  21.                         </div>
  22.  
  23.  
  24. </body>
  25. </html>
FILE 2:new_file.js(the js file)


Expand|Select|Wrap|Line Numbers
  1. function changeLink()
  2. {
  3. var someOtherName="after click";
  4.  
  5. xmlhttp=new XMLHttpRequest();
  6.  
  7. xmlhttp.onreadystatechange=function()
  8.   {
  9.   if (xmlhttp.readyState==4 && xmlhttp.status==200)
  10.     {
  11.     document.getElementById("id200").value = someOtherName;
  12.     }
  13.   }
  14. xmlhttp.open("GET","index.html");
  15. xmlhttp.send();
  16. }
FILE 3:page2.html(page two)
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
  2.    "http://www.w3.org/TR/html4/strict.dtd">
  3.  
  4. <html lang="en">
  5. <head>
  6. <script src="new_file.js"></script>
  7.  </head>
  8.  
  9. <body>
  10. <input type="button" id="id100" onclick="changeLink()" value="Change link">
  11. </body>
  12. </html> 

Thanks!
Nov 5 '11 #1
1 1639
Dormilich
8,658 Expert Mod 8TB
as you expect it, that’s not possible.

JavaScript only works within a single page, there is no JavaScript-to-JavaScript communication between two loaded pages.

the only thing that were possible is to call the second page by the first page and passing URL parameter(s) which can be read and processed by JavaScript.
Nov 7 '11 #2

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

Similar topics

1
by: Tim Begin | last post by:
I am attempting to use the ThreadPool.SetMinThreads method as shown in the MSDN example code: int minWorker, minIOPort; int newWorker,newIOPort; ThreadPool.GetAvailableThreads(out minWorker, out...
3
by: John Smith | last post by:
I'm looking into this peace of code: protected void DropDown_SelectedIndexChanged(object sender, EventArgs e) { DropDownList list = (DropDownList)sender; TableCell cell = list.Parent as...
2
by: John Smith | last post by:
Will this line of the code: item.Cells.Text = "Some text..."; change only DataGrid visual value or it will also change value in the DataSource? How can I change value in DataSource? ...
0
by: marknoten | last post by:
Hi, we are working with XML files that can be as big as 6Mb. Some XML documents that obey to a certain condition must be duplicated where only 2 elements need to change value. I thought using...
1
by: PawelR | last post by:
Hi Group, In my application I have DataTable which is displayed in DataGridView via DataView: DataView myView = new DataView(myTable); myDataGridView.DataSource = myView; One column im...
3
by: bmcomp | last post by:
Hi, A bit stuck here. I have a form and instead of having labels beside each input box i have the default value set as the label. When the user clicks on it the default value is removed. I do...
1
by: Jafri256best | last post by:
I want to change value of a variable permanently during executing a form and want to enter the value through the text box.
4
by: mikael3432 | last post by:
hey. I wonder if anyone can help me with this one: I want to change value 21 to 210 in colum A, given there is another row that has value 10 in colum A and in both rows values in colum B, C D are...
0
by: wasim jack | last post by:
sir,I want to change value of combobox of datagridview on the basis of previous combobox value of the same raw of same datagridview
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: 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...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.