Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 84805
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T21:59:21+00:00 2026-05-10T21:59:21+00:00

I have the following javascript code, which loads without error, however the update function

  • 0

I have the following javascript code, which loads without error, however the update function does not actually seem functional, as get_Records.php is never loaded. I can not test if get_auction.php is loaded as it is loaded from within get_records.php

One of my main concerns is that I am doing the wrong thing by having update() take the paramters pk and query, as only one of them will ever be used. That seems like a bad hack, and poor logic, but I am not aware of a better way.

Here is the code

var xmlHttp var layername var url  function update(layer, part, pk, query) {     alert ('update');     if (part=='1') {         alert ('part 1');         url = 'get_auction.php?cmd=GetAuctionData&pk='+pk+'&sid='+Math.random()     } else if (part=='2') {         alert ('part 2');         url = 'get_records.php?cmd=GetRecordSet&query='+query+'&sid='+Math.random()     }     xmlHttp=GetXmlHttpObject()     if(xmlHttp==null) {         alert('Your browser is not supported?')     }     xmlHttp.onreadystatechange = function() {         if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete') {             document.getElementById(layer).innerHTML=xmlHttp.responseText         } else if (xmlHttp.readyState==1 || xmlHttp.readyState=='loading') {             document.getElementById(layer).innerHTML='loading'         }     };     xmlHttp.open('GET',url,true)     xmlHttp.send(null) }  function GetXmlHttpObject() {     var xmlHttp=null;     try {         xmlHttp = new XMLHttpRequest();     } catch (e) {         try {             xmlHttp =new ActiveXObject('Microsoft.XMLHTTP');         } catch (e) {}     }     return xmlHttp; }  function makewindows() {     child1 = window.open ('about:blank');     child1.document.write(<?php echo htmlspecialchars(json_encode($row2['ARTICLE_DESC']), ENT_QUOTES); ?>));     child1.document.close();  } 

I placed alert statements into the update function, andnot one is displayed, indicated the update function is never called?

I do not want to, and cannot use a framework, nor do I have access to use firebug, so please do not suggest these things. I am aware of them and use them when I can.

I would also like to know if calling php from within makewindows() is preferred to having makewindows simply take a parameter.., is there any advantage or disadvantage to each approach?

I seem to get an error when trying to call the function, this is how I am doing it in PHP:

echo '<li><a href='#' onclick=update('Layer3','2','0','hello')'>Link 1</a></li>' .  

which makes this html, which should be fine?’\n’;

<li><a href='#' onclick='update('Layer3','2','0','hello')'>Link 1</a></li> 

edit: I have taken tester101’S advice and changed it to this:

echo '<li><a href='#' onclick='update(\'Layer3\',\'2\',\'0\',\'hello\')'>Link 1</a></li>' . '\n';  

Which still gives an error. I will probably end up using toms answer, but would like to know why this is not working.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-10T21:59:22+00:00Added an answer on May 10, 2026 at 9:59 pm

    You could just take Url as a parameter to update(), then you wouldn’t need to build the url within and you wouldn’t need the ‘optional’ parameters

    Edit (response to comment)

    If you have an update() function that just takes url and element id (layer) and updates it based on the result of an AJAX call, you could do something like this to remove the need for optional parameters and using a function to do two different things.

    function update(layer, url) {     var xmlHttp=GetXmlHttpObject(); //you have this defined elsewhere      if(xmlHttp==null) {         alert('Your browser is not supported?');     }      xmlHttp.onreadystatechange = function() {         if(xmlHttp.readyState==4 || xmlHttp.readyState=='complete') {             document.getElementById(layer).innerHTML=xmlHttp.responseText;         } else if (xmlHttp.readyState==1 || xmlHttp.readyState=='loading') {             document.getElementById(layer).innerHTML='loading';         }         //etc     }      xmlHttp.open('GET',url,true);     xmlHttp.send(null); }   function updateByPk(layer, pk) {    url = 'get_auction.php?cmd=GetAuctionData&pk='+pk+'&sid='+Math.random();    update(layer, url); }   function updateByQuery(layer, query) {    url = 'get_records.php?cmd=GetRecordSet&query='+query+'&sid='+Math.random();    update(layer, url); } 

    Then call either, depending on what you want to do:

    updateByPk('id_of_div', 2); 

    or

    updateByQuery('id_of_div2', 'query'); 

    e.g. in HTML

    <a href='#' onclick='updateByQuery('Layer3', 'hello');'>Link 1</a> 

    or to generate that in PHP

    <?php echo '<a href='#' onclick='updateByQuery(\'Layer3\', ' . json_encode($query) . ');'>Link 1</a>'; 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 100k
  • Answers 100k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer As the other posters have said, it seems likely that… May 11, 2026 at 7:52 pm
  • Editorial Team
    Editorial Team added an answer I played around with this a few years back -… May 11, 2026 at 7:52 pm
  • Editorial Team
    Editorial Team added an answer A known answer for this problem is using the following… May 11, 2026 at 7:52 pm

Related Questions

I have the following file file: <html> <head> <title></title> <script type=text/javascript src=/Prototype.js></script> <script type=text/javascript>
I have the following javascript snippet, which fails to load due to a missing
I have the following code, which will not work. The javascript gives no errors
I have the following JQuery code which does similar functionality like Stackoverflow where the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.