lional Posted June 9, 2013 Share Posted June 9, 2013 Hi I have this script <script type="text/javascript"> $(document).ready(function(){ $("select#type").attr("disabled","disabled"); $("select#category").change(function(){ $("select#type").attr("disabled","disabled"); $("select#type").html("<option>wait...</option>"); var id = $("select#category option:selected").attr('value'); $.post("select_type.php", {id:id}, function(data){ $("select#type").removeAttr("disabled"); $("select#type").html(data); }); }); $("form#select_form").submit(function(){ var cat = $("select#category option:selected").attr('value'); var type = $("select#type option:selected").attr('value'); if(cat>0 && type>0) { var result = $("select#type option:selected").html(); $("#result").html('your choice: '+result); } else { $("#result").html("you must choose two options!"); } return false; }); }); </script> What I would like to do is instead of displaying output var result = $("select#type option:selected").html();$("#result").html('your choice: '+result); I would like ti redirect the post in the form of POST to another page. Any help would be appreciated Thanks Lional Link to comment https://forums.phpfreaks.com/topic/278957-redirect-to-another-page-instead-of-print/ Share on other sites More sharing options...
requinix Posted June 9, 2013 Share Posted June 9, 2013 Then use the normal form mechanisms without trying to AJAX it. Link to comment https://forums.phpfreaks.com/topic/278957-redirect-to-another-page-instead-of-print/#findComment-1434962 Share on other sites More sharing options...
lional Posted June 9, 2013 Author Share Posted June 9, 2013 Thanks Do I leave this section out then $("form#select_form").submit(function(){var cat = $("select#category option:selected").attr('value');var type = $("select#type option:selected").attr('value');if(cat>0 && type>0){var result = $("select#type option:selected").html();$("#result").html('your choice: '+result);}else{$("#result").html("you must choose two options!");}return false;}); Link to comment https://forums.phpfreaks.com/topic/278957-redirect-to-another-page-instead-of-print/#findComment-1434966 Share on other sites More sharing options...
trq Posted June 9, 2013 Share Posted June 9, 2013 Do you understand what Ajax is? Do you understand what your own code does? Link to comment https://forums.phpfreaks.com/topic/278957-redirect-to-another-page-instead-of-print/#findComment-1434980 Share on other sites More sharing options...
Irate Posted June 9, 2013 Share Posted June 9, 2013 Ajax is used just because you don't want to reload pages, so you dynamically load additional data via XMLHttpRequests. As trq said, try looking up the basics of Ajax. If you want to prevent the page from reloading when submitting a form, use jQuery(document.forms).submit(function(e){ e.preventDefault(); /* your code here */ }); Link to comment https://forums.phpfreaks.com/topic/278957-redirect-to-another-page-instead-of-print/#findComment-1434985 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.