Hi, I have some code to update a select box with shippingOptions. It works flawlessly in FireFox, but I had to hack it to work in IE. I have a php script that returns some simple javascript. <script> var selObj = document.getElementById(''STID''); selObj.options.length=null; selObj.options[0] = new Option(''Select Shipping Method'',''''); Obj.options[1] = new Option(''Ground'', ''1''); Obj.options[2] = new Option(''2nd Day Air'', ''4''); </script> My Javascript that works in FF is: function populateShippingOptions(passParams){ var url = securebase + ''getShippingOptions.php''; // Add random to avoid cache if (passParams != '''') { passParams = passParams + ''&rand=''+ Math.random() } else { passParams = ''rand=''+ Math.random() } var myAjax = new Ajax.Updater( url, { method: ''get'', parameters: passParams, evalScripts: true } ); } To make it work in IE, I remove the <script> tag from the PHP script. Then I change to Request instead of Updater. Then I remove evalScripts, and add onComplete: showResponse. function showResponse(originalRequest){ document.getElementById(''empty'').style.display = ''none''; document.getElementById(''empty'').innerHTML originalRequest.responseText; eval(document.getElementById(''empty'').innerHTML); } Am I missing something simple? I have another piece of code that returns HTML and Javascript inline. It updates a section of the page. This also works in FF, but not IE. Thanks in advance, John bowlingball.com --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Perhaps it''s as simple as not defining the script type attribute. IE supports vbscript and jscript in addition to javascript. (I don''t have IE handy, or I''d test this theory.) <script type="text/javascript"> // ... </script> Perhaps there was something happening in the Ajax object. Did you add callbacks for onFailure and onException to see if something was going wrong there? TAG On Mar 5, 2007, at 12:46 PM, bowlingball.com wrote:> > Hi, > > I have some code to update a select box with shippingOptions. It > works flawlessly in FireFox, but I had to hack it to work in IE. I > have a php script that returns some simple javascript. > <script> > var selObj = document.getElementById(''STID''); > selObj.options.length=null; > selObj.options[0] = new Option(''Select Shipping Method'',''''); > Obj.options[1] = new Option(''Ground'', ''1''); > Obj.options[2] = new Option(''2nd Day Air'', ''4''); > </script> > > My Javascript that works in FF is: > > function populateShippingOptions(passParams){ > var url = securebase + ''getShippingOptions.php''; > // Add random to avoid cache > if (passParams != '''') { passParams = passParams + ''&rand=''+ > Math.random() } > else { passParams = ''rand=''+ Math.random() } > > var myAjax = new Ajax.Updater( > url, > { method: ''get'', parameters: passParams, evalScripts: true } > ); > } > > To make it work in IE, I remove the <script> tag from the PHP script. > Then I change to Request instead of Updater. > Then I remove evalScripts, and add onComplete: showResponse. > > function showResponse(originalRequest){ > document.getElementById(''empty'').style.display = ''none''; > document.getElementById(''empty'').innerHTML > originalRequest.responseText; > eval(document.getElementById(''empty'').innerHTML); > } > > > Am I missing something simple? I have another piece of code that > returns HTML and Javascript inline. It updates a section of the > page. This also works in FF, but not IE. > > Thanks in advance, > > John > bowlingball.com > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, I had that in there originally. It really appears to be a problem with IE7 and Ajax.Updater. I tried just the standard update, without JavaScript, and that does not appear to work either. Thank you, On Mar 5, 3:30 pm, Tom Gregory <t...-PGZyUNKar/Q@public.gmane.org> wrote:> Perhaps it''s as simple as not defining the script type attribute. IE > supports vbscript and jscript in addition to javascript. (I don''t > have IE handy, or I''d test this theory.) > > <script type="text/javascript"> > // ... > </script> > > Perhaps there was something happening in the Ajax object. Did you > add callbacks for onFailure and onException to see if something was > going wrong there? > > TAG > > On Mar 5, 2007, at 12:46 PM, bowlingball.com wrote: > > > > > Hi, > > > I have some code to update a select box with shippingOptions. It > > works flawlessly in FireFox, but I had to hack it to work in IE. I > > have a php script that returns some simple javascript. > > <script> > > var selObj = document.getElementById(''STID''); > > selObj.options.length=null; > > selObj.options[0] = new Option(''Select Shipping Method'',''''); > > Obj.options[1] = new Option(''Ground'', ''1''); > > Obj.options[2] = new Option(''2nd Day Air'', ''4''); > > </script> > > > My Javascript that works in FF is: > > > function populateShippingOptions(passParams){ > > var url = securebase + ''getShippingOptions.php''; > > // Add random to avoid cache > > if (passParams != '''') { passParams = passParams + ''&rand=''+ > > Math.random() } > > else { passParams = ''rand=''+ Math.random() } > > > var myAjax = new Ajax.Updater( > > url, > > { method: ''get'', parameters: passParams, evalScripts: true } > > ); > > } > > > To make it work in IE, I remove the <script> tag from the PHP script. > > Then I change to Request instead of Updater. > > Then I remove evalScripts, and add onComplete: showResponse. > > > function showResponse(originalRequest){ > > document.getElementById(''empty'').style.display = ''none''; > > document.getElementById(''empty'').innerHTML > > originalRequest.responseText; > > eval(document.getElementById(''empty'').innerHTML); > > } > > > Am I missing something simple? I have another piece of code that > > returns HTML and Javascript inline. It updates a section of the > > page. This also works in FF, but not IE. > > > Thanks in advance, > > > John > > bowlingball.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I don''t know if that is a typo just in the code you posted but for the last two options you are using "Obj" instead of "selObj".. when using evalScripts you have to be extra careful of little things like this since the errors are often caught silently and are harder to debug. That is one reason I recommend using JSON to transport the data from the server, then writing javascript code that works on that data instead of having the server return actual javascript. For example: <? //could also easily be built from database, etc.. $json = Array(''options'' => Array( Array( ''text'' => ''Select Shipping Method'', ''value'' => '''' ), Array( ''text'' => ''Ground'', ''value'' => ''1'' ), Array( ''text'' => ''2nd Day Air'', ''value'' => ''4'' ), )); header(''X-JSON: (''.json_encode($json).'')''); //json_encode is now PECL standard ?> Javascript: //supports default selected options with .selected or .selectedIndex function fillSelectFromObject(receiver,obj){ var box = $(receiver); box.options.length = 0; var sel = obj.selected || false; var opts = obj.options; for( var i=0; i<opts.length; i++ ){ box.options[i] = new Option(opts[i].text,opts[i].value,null,(sel&&sel==opts[i].value?true:false)); } if( obj.selectedIndex ){ box.selectedIndex = obj.selectedIndex; } } function populateShippingOptions(passParams){ var url = securebase + ''getShippingOptions.php''; // Add random to avoid cache if (passParams != '''') { passParams = passParams + ''&rand=''+Math.random() } else { passParams = ''rand=''+ Math.random() } var myAjax = new Ajax.Request(url,{ method: ''get'', parameters: passParams, onSuccess: function(xhr,json){ fillSelectFromObject(''STID'',json); } }); } Also, if you are using multiple select boxes that depend on each other, consider using this: http://colin.mollenhour.com/doublecombo/index.html Colin bowlingball.com wrote:> Hi, > > I have some code to update a select box with shippingOptions. It > works flawlessly in FireFox, but I had to hack it to work in IE. I > have a php script that returns some simple javascript. > <script> > var selObj = document.getElementById(''STID''); > selObj.options.length=null; > selObj.options[0] = new Option(''Select Shipping Method'',''''); > Obj.options[1] = new Option(''Ground'', ''1''); > Obj.options[2] = new Option(''2nd Day Air'', ''4''); > </script> > > My Javascript that works in FF is: > > function populateShippingOptions(passParams){ > var url = securebase + ''getShippingOptions.php''; > // Add random to avoid cache > if (passParams != '''') { passParams = passParams + ''&rand=''+ > Math.random() } > else { passParams = ''rand=''+ Math.random() } > > var myAjax = new Ajax.Updater( > url, > { method: ''get'', parameters: passParams, evalScripts: true } > ); > } > > To make it work in IE, I remove the <script> tag from the PHP script. > Then I change to Request instead of Updater. > Then I remove evalScripts, and add onComplete: showResponse. > > function showResponse(originalRequest){ > document.getElementById(''empty'').style.display = ''none''; > document.getElementById(''empty'').innerHTML > originalRequest.responseText; > eval(document.getElementById(''empty'').innerHTML); > } > > > Am I missing something simple? I have another piece of code that > returns HTML and Javascript inline. It updates a section of the > page. This also works in FF, but not IE. > > Thanks in advance, > > John > bowlingball.com > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hi it was a typo. I was removing the PHP coding from the javascript. I just tried JSON for the first time, and it worked flawlessly. Thank you so much for teaching me something new. I will start doing some more research on JSON today. John bowlingball.com On Mar 5, 5:13 pm, Colin Mollenhour <eliteii...-NPSFNn/7+NYVo650/ln6uw@public.gmane.org> wrote:> I don''t know if that is a typo just in the code you posted but for the > last two options you are using "Obj" instead of "selObj".. when using > evalScripts you have to be extra careful of little things like this > since the errors are often caught silently and are harder to debug. That > is one reason I recommend using JSON to transport the data from the > server, then writing javascript code that works on that data instead of > having the server return actual javascript. > > For example: > <? > //could also easily be built from database, etc.. > $json = Array(''options'' => Array( > Array( ''text'' => ''Select Shipping Method'', ''value'' => '''' ), > Array( ''text'' => ''Ground'', ''value'' => ''1'' ), > Array( ''text'' => ''2nd Day Air'', ''value'' => ''4'' ), > )); > header(''X-JSON: (''.json_encode($json).'')''); > //json_encode is now PECL standard > ?> > > Javascript: > > //supports default selected options with .selected or .selectedIndex > function fillSelectFromObject(receiver,obj){ > var box = $(receiver); > box.options.length = 0; > var sel = obj.selected || false; > var opts = obj.options; > for( var i=0; i<opts.length; i++ ){ > box.options[i] = new > Option(opts[i].text,opts[i].value,null,(sel&&sel==opts[i].value?true:false)); > } > if( obj.selectedIndex ){ box.selectedIndex = obj.selectedIndex; } > > } > > function populateShippingOptions(passParams){ > var url = securebase + ''getShippingOptions.php''; > // Add random to avoid cache > if (passParams != '''') { > passParams = passParams + ''&rand=''+Math.random() > } else { passParams = ''rand=''+ Math.random() } > > var myAjax = new Ajax.Request(url,{ > method: ''get'', > parameters: passParams, > onSuccess: function(xhr,json){ > fillSelectFromObject(''STID'',json); > } > }); > > } > > Also, if you are using multiple select boxes that depend on each other, consider using this:http://colin.mollenhour.com/doublecombo/index.html > > Colin > > bowlingball.com wrote: > > Hi, > > > I have some code to update a select box with shippingOptions. It > > works flawlessly in FireFox, but I had to hack it to work in IE. I > > have a php script that returns some simple javascript. > > <script> > > var selObj = document.getElementById(''STID''); > > selObj.options.length=null; > > selObj.options[0] = new Option(''Select Shipping Method'',''''); > > Obj.options[1] = new Option(''Ground'', ''1''); > > Obj.options[2] = new Option(''2nd Day Air'', ''4''); > > </script> > > > My Javascript that works in FF is: > > > function populateShippingOptions(passParams){ > > var url = securebase + ''getShippingOptions.php''; > > // Add random to avoid cache > > if (passParams != '''') { passParams = passParams + ''&rand=''+ > > Math.random() } > > else { passParams = ''rand=''+ Math.random() } > > > var myAjax = new Ajax.Updater( > > url, > > { method: ''get'', parameters: passParams, evalScripts: true } > > ); > > } > > > To make it work in IE, I remove the <script> tag from the PHP script. > > Then I change to Request instead of Updater. > > Then I remove evalScripts, and add onComplete: showResponse. > > > function showResponse(originalRequest){ > > document.getElementById(''empty'').style.display = ''none''; > > document.getElementById(''empty'').innerHTML > > originalRequest.responseText; > > eval(document.getElementById(''empty'').innerHTML); > > } > > > Am I missing something simple? I have another piece of code that > > returns HTML and Javascript inline. It updates a section of the > > page. This also works in FF, but not IE. > > > Thanks in advance, > > > John > > bowlingball.com--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---