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

  • SEARCH
  • Home
  • 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 8581451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T21:03:13+00:00 2026-06-11T21:03:13+00:00

Ok, I know this has been asked before (as I have viewed it myself)

  • 0

Ok, I know this has been asked before (as I have viewed it myself) and it seems to work for everyone else except for me. Im terribly new to javascript, as I try not to use it cause its a nightmare to debug. But, here is my issue. I have a script that im working on for ajax to add an image to a gallery. The image is just an id that references another table in the database, and same for the gallery. Just two id’s. Anyways, when I click on a link, I want it to run this script to add it to the database. But, its not working, and of course, javascript is horrible at letting you know where it fails. Here is the code for the script.

function addToGallery(img)
{

 var e = document.getElementById("galleries2");
 var gal = e.options(e.selectedIndex).value;
 window.alert("Gallery Id: "+gal+" Image Id: "+img);

       if (img=="")
       {
          document.getElementById("txtHint").innerHTML="";
          return;
       } 
       if (window.XMLHttpRequest)
       {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
       }
       else
       {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
       }
          xmlhttp.onreadystatechange=function()
       {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
       {
          document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
       }
    }
       xmlhttp.open("GET","addtogallery.php?img="+img+"gal="+gal,true);
       xmlhttp.send();
    }

Ok, so the above doesnt work. I added the alert message to try to troubleshoot as much as I could. If I put the alert box above the var’s, and only ask it to reference the img variable, it works. Now, if I put it below and try to do what I did there, it just stops. No message box, no ajax, nothing. So, im betting it has something to do with the

var gal = e.options(e.selectedIndex).value;

I have also tried it with the [] instead of the () and nothing there either…
Any help would be appreciated.

UPDATE
Ok, so I have got past the problem with the select, now im trying to pass values with the xhtmlrequest.open method. I can pass 1 get value it seems, but not two. Here is the line of code in question

xmlhttp.open("GET","addtogallery.php?image="+img+"&gid="+gal,true);

Now, I know that img and gal are set because of an alert box that pops whenever this script is run to tell me that they are set. But when it gets to the php page its only putting out the img variable, and the gal variable is still not set. Anyone have this issue before?

  • 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-11T21:03:14+00:00Added an answer on June 11, 2026 at 9:03 pm

    You definitely need square brackets, but also try changing your variable “e” to something else like “el”. The function responds to a click as I understand, so it might be reserved for an event.

    Try:

    var galleries = document.getElementById("galleries2");
    var gal = galleries.options[galleries.selectedIndex].value;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this has been asked before, but nothing is working. I have signed
I know this has been asked before. But I have exhausted the options given
I know this question has been asked before but the solutions did not work
I know this question has been asked before and I have seen a plethora
I know this has been asked many times before... I have a simple ('#Div').load(file.php?id='+id+'&page='+page)
I know this has been asked before but I have looked at every answer
I know this has been asked before, but the only answers I have found
Okay, I know this question has been asked before: Previous Question I have also
I know this question has been asked before but I seem to have a
I know this question has been asked before, but I have tried the given

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.