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 8736863
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:23:22+00:00 2026-06-13T10:23:22+00:00

I need to create a dynamically generated window which shows an image and various

  • 0

I need to create a dynamically generated window which shows an image and various elements which are taken from a database. The pop-up window works, but it’s not getting the “id” which I am trying to get using an onclick function.

Using the console I get this message: XMLHttpRequest cannot load getProduct.php?id=undefined. Origin null is not allowed by Access-Control-Allow-Origin. I’m not sure what to do define the “id” further.

HTML & JS:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/javascript">
$(document).ready(function() {

onClickRegister = function(){   
var id = $(this).attr('id');

    b = $("#blanket");
    b.css("display","block");
    b.css("position","fixed");
    b.css("width", window.innerWidth);
    b.css("height", window.innerHeight);
    b.css("background-color", "rgba(0, 0, 0, 0.7)");
    f=$("#openImg");
    f.css("position", "fixed");
    f.css("top", "10%");
    f.css("left", "10%");

    $.getJSON("getProduct.php?id="+id,function(data){
        var img = data.data.prodImg;
        var name = data.data.prodName;
        var price = data.data.prodPrice;
        var description = data.data.prodDesc;
        var qty = data.data.prodQty;
        $("#openImg").html("<p style='float:right; margin: 0; padding: 0;'><a href='#' id='close' onClick='onClickClose();'>[X]</a></p><br /><img src='"+img+"' width='544' height='512' /><br />Name: "+name+"<br />Price: "+price+"<br />Qty: "+qty+"<br />Description: "+description)
    });
};
window.onresize = function () {
    if ($("#blanket").length > 0) {
        b.css("width", window.innerWidth);
        b.css("height", window.innerHeight);
   }
};
});
</script>
</head><body>

<div id="body"><div id="wrapper">

<a href="#" onclick="onClickRegister()" id="1"><img src="images/plug1_s.jpg" width="200" height="200" /></a>
<a href="#" onclick="onClickRegister()" id="2"><img src="images/plug2_s.jpg" width="200" height="200" /></a>
<a href="#" onclick="onClickRegister()" id="3"><img src="images/plug3_s.jpg" width="200" height="200" /></a>
<a href="#" onclick="onClickRegister()" id="4"><img src="images/plug4_s.jpg" width="200" height="200" /></a>
<a href="#" onclick="onClickRegister()" id="5"><img src="images/plug5_s.jpg" width="200" height="200" /></a>
<a href="#" onclick="onClickRegister()" id="6"><img src="images/plug6_s.jpg" width="200" height="200" /></a>

<div id="blanket"><div id="openImg">

</div></div>

<script type="text/javascript">
function onClickClose(){
    $("#blanket").hide();
}
</script></div></div>
</body></html>

PHP:

// retval: 0 - login ok, 1 - login failed, 2 - internal error
$json = array("retval" => 2, "data" => NULL, "debug" => "");

$id=json_decode($_REQUEST['id']);


$sql="SELECT * FROM prodTB WHERE prodId=" . $id;

$json['debug'] .= "SQL query was: ".$sql."\n";
$result=mysql_query($sql);
if (!$result) {
    $json['debug'] .= "SQL query failed\n";
    $json['debug'] .= "Other output: ". ob_get_contents();
    ob_end_clean();
    die(json_encode($json));
}
$count=mysql_num_rows($result);

if($count==1){
    $json['retval'] = 0;
    $json['data'] = mysql_fetch_assoc($result);
} else {
    $json['retval'] = 1;
}
$json['debug'] .= "Other output: ". ob_get_contents();
ob_end_clean();
echo json_encode($json);

Database Table Structure:

CREATE TABLE `prodTB` (
`prodId` int(11) NOT NULL,
`prodImg` varchar(80) COLLATE utf8_unicode_ci NOT NULL,
`prodName` varchar(50) COLLATE utf8_unicode_ci NOT NULL,
`prodPrice` decimal(10,2) NOT NULL,
`prodDesc` longtext COLLATE utf8_unicode_ci NOT NULL,
`prodQty` int(11) NOT NULL,
PRIMARY KEY (`prodId`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
  • 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. Editorial Team
    Editorial Team
    2026-06-13T10:23:24+00:00Added an answer on June 13, 2026 at 10:23 am

    Since you are using jQuery – you can get rid of the inline onClicks and bind the event handler at dom ready.

    $(document).ready(function() {
        var b = $("#blanket");
        var f = $("#openImg");
        $('#wrapper a').click(function() { 
            var id = $(this).attr('id');// this will get your ID now
    
            b.css("display", "block");
            b.css("position", "fixed");
            b.css("width", window.innerWidth);
            b.css("height", window.innerHeight);
            b.css("background-color", "rgba(0, 0, 0, 0.7)");
    
            f.css("position", "fixed");
            f.css("top", "10%");
            f.css("left", "10%");
    

    Also use var’s when declaring your variables or they’ll be global. You also need to move the var f and var b before the click binding since you are using them in your other function

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create a WPF grid dynamically from code behind. This is going
I need to create a dynamically generated menu for an E-Commerce web site. It
I need to create a variable storing dynamically generated HTML content. The html content
I am trying to create a CSV file from a dynamically generated table.I have
I need to dynamically create textbox. This is my code, but with this I
We need to dynamically create (i.e. during runtime, via code-behind) UserControls and position them
I need to create several Divs dynamically, and I need to add onmouseover event
I have dynamically created WrapPanel (_wp) with several Borders. And I need create handler
I need to create an array of label and text boxes dynamically. I have
I've got a simple ASHX handler that returns an dynamically generated image; the image

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.