Note that there are some explanatory texts on larger screens.

plurals
  1. POGet Value from Select in Javascript
    primarykey
    data
    text
    <p>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.</p> <pre><code>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 &amp;&amp; xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","addtogallery.php?img="+img+"gal="+gal,true); xmlhttp.send(); } </code></pre> <p>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 </p> <pre><code>var gal = e.options(e.selectedIndex).value; </code></pre> <p>I have also tried it with the [] instead of the () and nothing there either... Any help would be appreciated.</p> <p><strong>UPDATE</strong> 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 </p> <pre><code>xmlhttp.open("GET","addtogallery.php?image="+img+"&amp;amp;gid="+gal,true); </code></pre> <p>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?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload