If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

Enjoy an ad free experience by logging in. Not a member yet? Register.

How do I get a javascript to post data back to same page

I have this JavaScript that is pulling data based on input from the users. It is working very well and returns the data based on the criteria input by users, but it is opening a new tab and shownig the data instead of returning to the same page and displaying the data as needed.

The OP didn't tell how that code is called but I can't figure out why that code would open a new tab and generate the output there. I think the output is written on the same page erasing the current content (because of document.write). I assume the code is called onclick of the Search button.

There is still one instance where document.write can be used - where you want to generate an entire new page fron JavaScript that you want opened in a new window or tab.

document.write() is the only way to dynamically load blocking external javascript from a non-cors URL. advertisiers use this capability a lot to deliver device and browser-specific packages from a bevy of CDNs. even major sites like NYT use it to selectively show images:

that's in interesting use for it, and i can why why they choose to do it that way for performance reasons. until the <template> tags is well-supported, such hackery will be a routine part of web development.

Create, Share, and Debug HTML pages and snippets with a cool new web app I helped create: pagedemos.com

document.write() is the only way to dynamically load blocking external javascript from a non-cors URL.

As long as the JavaScript is attached to the page and references something in the page there is no cross domain issue. There are even scripts you can use (eg. postscribe) that will convert all of the document.write statements so that all the code can be moved to the bottom of the page and still load all the antiquated ads in the right places in the page.

Using a script like postscribe has the advantages that the JavaScript is all at the bottom of the page where it belongs and any delays in actually loading the ads don't block the visitor from seeing the rest of the page. The disadvantage is that it requires a relatively large additional script to be added to the page (fortunately since the ads are the least important part of the page from your visitor's viewpoint they will perceive pages using it as loading faster even though they are actually slower). You'd get the advantages without the disadvantages if the advertisers stopped using antiquated code - apart from generating entire web pages there has not been any use for document.write since Netscape 4 died.

If you attach postscribe to a web page then the web page no longer provides any way to access the native document.write call as postscribe replaces that function with its own. So any site providing scripts for others to attach to their page that uses document.write has no guarantee that their code will be run through the native document.write.

If you attach postscribe to a web page then the web page no longer provides any way to access the native document.write call as postscribe replaces that function with its own. So any site providing scripts for others to attach to their page that uses document.write has no guarantee that their code will be run through the native document.write.

if the postscribe script works, then so would your other script, even if the doc.write was non-native.

Give a little more background on what your environment is. Are you using a server-side language (C#, VB.NET, PHP, JSP, etc)? If so, then you don't need javascript. Or are you doing HTML Application (HTA) or a regular HTML that only works in IE with ActiveX enabled and the database resides locally or in the LAN?