syncedit Posted February 21, 2007 Share Posted February 21, 2007 Hello, Thanks for taking the time to look at my question. I use ajax to create a dynamic form: step 1) form has some <input type=radio> and <input type=checkbox> fields to start with. step 2) this value is sent via ajax to somefile.php file. That somefile.php file generates a new part of the form (containing <input type=radio>, <input type=checkbox> and <inpu typet=text> fields) > so the user will fill in more variables than he started with. When I submit this form (<input type=submit>, no javascript involved), only the original form variables are transferred. I use a basic javascript to transfer data between the form & soemfile.php <script LANGUAGE="javascript" TYPE="text/javascript"> <!-- //Browser Support Code function showfieldsbyclass(theclass,initiate){ var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ ajaxclass.innerHTML = ajaxRequest.responseText; } } ajaxRequest.open('GET', 're_ajax.php?function=showfieldsbyclass&class='+theclass+'&initiate='+initiate, true); ajaxRequest.send(null); } //--> </script> and this is the javascript that I use: onclick=\"javascript:showfieldsbyclass('0','');\" So the ajax to build my additional form fields works great but the problem is that only the original forms variables/values are sent when I press the submit button. o jeah.. one more thing: The new form variables/values are transmitted on IE, but not on firefox! Thanks, Cedric Quote Link to comment Share on other sites More sharing options...
ScotDiddle Posted February 22, 2007 Share Posted February 22, 2007 syncedit, It sounds like the issue is with the way the php file ( re_ajax.php ) builds the response page. Post the source here so we can play around with it. Scot L. Diddle, Richmond VA Quote Link to comment Share on other sites More sharing options...
syncedit Posted February 22, 2007 Author Share Posted February 22, 2007 Example: http://www.cedriccolpaert.be/ajaxtest/ index.html <html><head><title>test</title></head><body> <script LANGUAGE="javascript" TYPE="text/javascript"> <!-- //Browser Support Code function showareas(cat){ var ajaxRequest; try{ // Opera 8.0+, Firefox, Safari ajaxRequest = new XMLHttpRequest(); } catch (e){ // Internet Explorer Browsers try{ ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ // Something went wrong alert("Your browser broke!"); return false; } } } // Create a function that will receive data sent from the server ajaxRequest.onreadystatechange = function(){ if(ajaxRequest.readyState == 4){ ajaxareas.innerHTML = ajaxRequest.responseText; } } ajaxRequest.open('GET', 'ajax.php?cat='+cat, true); ajaxRequest.send(null); } //--> </script> <table cellpadding="1" cellspacing="1"> <FORM METHOD=POST ACTION="printvariables.php"> <tr><td><input type="radio" name="category" value="category_one" onclick="javascript:showareas('category_one');" checked>category one</td></Tr> <tr><td><input type="radio" name="category" value="category_two" onclick="javascript:showareas('category_two');">category two</td></Tr> <tr><td><input type="radio" name="category" value="category_three" onclick="javascript:showareas('category_three');">category three</td></Tr> <tr><td> </td></tr> <tr><td ID="ajaxareas" align="left"> </td></tr> <tr><td> </td></tr> <tr><td><input type="submit" value="submit"></td></tr> </FORM> </table> ajax.php <? if ($_GET['cat'] == 'category_one') { echo ' variable category_one_var: <input type="text" name="category_one_var"> <br> variable category_one_var2: <input type="checkbox" name="category_one_var2" value="some value"> <br> '; } elseif ($_GET['cat'] == 'category_two') { echo ' variable category_two_var: <input type="text" name="category_two_var"> <br> variable category_two_var2: <input type="checkbox" name="category_two_var2" value="some value"> <br> '; } elseif ($_GET['cat'] == 'category_three') { echo ' variable category_three_var: <input type="text" name="category_three_var"> <br> variable category_three_var2: <input type="checkbox" name="category_three_var2" value="some value"> <br> '; } ?> printvariables.php <? print_r ($_REQUEST); ?> thanks Quote Link to comment Share on other sites More sharing options...
syncedit Posted February 24, 2007 Author Share Posted February 24, 2007 anyone? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.