Note that there are some explanatory texts on larger screens.

plurals
  1. POJavascript popup selector + PHP
    primarykey
    data
    text
    <p>I have, with the help of the SO community written a javascript and php page that allows me to pass a value from the popup page back to the parent page.</p> <p>This works 100% on internet explorer but not in google chrome or on my ipad / galaxt tablet.</p> <p>Any idea on how this can be corrected? Any help appreciated as always.</p> <p>Below is portions of my code from the parent page(newsale.php) and the popup page(sku.php). I know that other methods are recommended over using popup but I need to get this solution working with the popup page for application reasons.</p> <p><strong>newsale.php</strong> Parent Page (Code snippets, not entire page)</p> <pre><code>&lt;script type="text/javascript"&gt; function selectValue(id) { // open popup window and pass field id window.open('sku.php?id=' + encodeURIComponent(id),'popuppage', 'width=1000,toolbar=1,resizable=1,scrollbars=yes,height=200,top=100,left=100'); } function updateValue(id, value) { // this gets called from the popup window and updates the field with a new value document.getElementById(id).value = value; } &lt;/script&gt; &lt;table&gt; &lt;tr id="r1"&gt; &lt;input size=10 type=number id=sku1 name=sku1 onchange="showUser(1, this.value)" &lt;? if($rows&gt;0){echo "value=".mysql_result($resultorder,0,1);} ?&gt;&gt;&lt;img src=q.png name="choice" onClick="selectValue('sku1')" value="?"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr id="r2"&gt; &lt;td&gt; &lt;input size=10 type=number id=sku2 name=sku2 onchange="showUser(2, this.value)" &lt;? if($rows&gt;1){echo "value=".mysql_result($resultorder,1,1);} ?&gt; &gt;&lt;img src=q.png name="choice" onClick="selectValue('sku2')" value="?"&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p><strong>sku.php</strong> Popup Page (entire page)</p> <pre><code>&lt;? $con = mysql_connect('localhost', 'username', 'password'); if (!$con) { die('Could not connect to server: ' . mysql_error()); } $db=mysql_select_db("DBName", $con); if (!$db) { die('Could not connect to DB: ' . mysql_error()); } $sql="select packcode,category,description,grouping,packconfig,sellingunits,eottpoints from skudata order by category, packcode"; $result=mysql_query($sql); ?&gt; &lt;script type="text/javascript"&gt; function AjaxFunction(cat_id) { var httpxml; try { // Firefox, Opera 8.0+, Safari httpxml = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { httpxml = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { httpxml = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { alert("Your browser does not support AJAX!"); return false; } } } function stateck() { if (httpxml.readyState == 4) { var myarray = eval(httpxml.responseText); // Before adding new we must remove previously loaded elements for (j = document.testform.subcat.options.length - 1; j &gt;= 0; j--) { document.testform.subcat.remove(j); } for (i = 0; i &lt; myarray.length; i++) { var optn = document.createElement("OPTION"); optn.text = myarray[i]; optn.value = myarray[i]; document.testform.subcat.options.add(optn); } } } var url="dd.php"; url = url+"?cat_id="+cat_id; url = url+"&amp;sid="+Math.random(); httpxml.onreadystatechange = stateck; httpxml.open("GET",url,true); httpxml.send(null); } &lt;/script&gt; &lt;script type="text/javascript"&gt; function sendValue(value) { var e = document.getElementById("subcat"); value = e.options[e.selectedIndex].value; var parentId = &lt;?php echo json_encode($_GET['id']); ?&gt;; window.opener.updateValue(parentId, value); window.close(); } &lt;/script&gt; &lt;script type="text/javascript"&gt; function updateinput(){ var e = document.getElementById("subcat"); var catSelected = e.options[e.selectedIndex].value; document.getElementById("copycat").value=catSelected; } &lt;/script&gt; &lt;form name="testform"&gt; Category: &amp;nbsp; &lt;select name=cat id=cat onchange="AjaxFunction(this.value);" style="width=300"&gt; &lt;br&gt; &lt;option value='' style="width=300"&gt;Select One&lt;/option&gt; &lt;br&gt; &lt;? require "config.php";// connection to database $q=mysql_query("select * from categories"); while($n=mysql_fetch_array($q)){ echo "&lt;option value=$n[cat_id]&gt;$n[category]&lt;/option&gt;"; } ?&gt; &lt;/select&gt; &lt;br&gt;&lt;br&gt; Pack Code: &lt;select name=subcat onchange="updateinput();" &gt; &lt;br&gt;&lt;br&gt; &lt;/select&gt; &lt;br&gt;&lt;br&gt; &lt;input type=hidden name=copycat id=copycat &gt; &lt;td&gt;&lt;input type=button value="Select" onClick="sendValue(document.getElementById(copycat))" /&gt;&lt;/td&gt; &lt;/form&gt; </code></pre> <p><strong>dd.php</strong> (for dynamic drop down list)</p> <pre><code>&lt;? $cat_id=$_GET['cat_id']; require "config.php"; $q=mysql_query("select concat(packcode,', ',description) as details from skudata where cat_id='$cat_id'"); echo mysql_error(); $myarray=array(); $str=""; while($nt=mysql_fetch_array($q)){ $str=$str . "\"$nt[details]\"".","; } $str=substr($str,0,(strLen($str)-1)); // Removing the last char , from the string echo "new Array($str)"; ?&gt; </code></pre> <p>I dont think dd.php has any influence on the functionality of the parent popup relationship but have included it so you can follow the code.</p> <p>As mentioned this works 100% on Internet explorer but not in google chrome or my ipad.</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