gamesmstr Posted December 11, 2008 Share Posted December 11, 2008 I have the following code: The javascript call seems to be working just fine. but the form data is not available: Can anyone help me? <table align="center" border="1" cellpadding="5" cellspacing="0" width="500"> <tr><td colspan="3" align="center"><b>Warp to Trading Post Location (Costs 30 Energy)</b></td></tr> <tr> <form action="tradingpost.php" onsubmit="javascript:buytrap('warp'); return false;" method="post"> <td>X value : <select name="warpx"> <option value="0">0</option> <option value="100">100</option> <option value="200">200</option> <option value="300">300</option> <option value="400">400</option> <option value="500">500</option> <option value="600">600</option> <option value="700">700</option> <option value="800">800</option> <option value="900">900</option> <option value="1000">1000</option> </select> </td> <td>Y value : <select name="warpy" > <option value="0">0</option> <option value="100">100</option> <option value="200">200</option> <option value="300">300</option> <option value="400">400</option> <option value="500">500</option> <option value="600">600</option> <option value="700">700</option> <option value="800">800</option> <option value="900">900</option> <option value="1000">1000</option> </select> </td> <td> <input type="submit" value="Warp For 30 Energy" /> </td> </form> </tr> </table> And the JS: function createXMLHttpRequest() { if (typeof XMLHttpRequest != 'undefined') { return new XMLHttpRequest(); } try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {} } return false; } function buytrap(type) { var xmlHttp11 = createXMLHttpRequest(); params = "type=" + type; xmlHttp11.open("POST","ajax/ajax-tradingpost.php", true); xmlHttp11.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); xmlHttp11.onreadystatechange = function() { if(xmlHttp11.readyState == 4 && xmlHttp11.status == 200) { document.getElementById("tpost-window").innerHTML = xmlHttp11.responseText; } } xmlHttp11.send(params); } Link to comment https://forums.phpfreaks.com/topic/136524-form-data-not-submitting/ Share on other sites More sharing options...
VBAssassin Posted December 11, 2008 Share Posted December 11, 2008 Looking at that, your comfortable working with JavaScript. I would suggest you now look into using a JS framework such as jQuery or Prototype. http://www.prototypejs.org/api/ajax/request Looking at your code, your just trying to post a form... and no bothered about the return data. In which case you can do it like this. Change <select name="warpx"> to <select id="warpx" onclick='javascript:send_it();'> and then add this js code function send_it() { new Ajax.Request('/url/here/of/where/to/post/it', { method: 'post', parameters: { warpx: $('warpx').value } }); } I haven't tested it though, so chances are there will be some syntax errors or something or other... but thats most of the code you should need anyway to make a simple Ajax POST request. Oh, and you will have to install the prototype framework, add this to the head part of the html: <script src='http://ajax.googleapis.com/ajax/libs/prototype/1.6.0.2/prototype.js' language='javascript' type='text/javascript'></script> Kind regards, Scott Link to comment https://forums.phpfreaks.com/topic/136524-form-data-not-submitting/#findComment-712641 Share on other sites More sharing options...
gamesmstr Posted December 11, 2008 Author Share Posted December 11, 2008 Not to invalidate your response, but can I get a solution that does not require me to completely restructure my programming? I have Jquery, but am not comfortable using it. Link to comment https://forums.phpfreaks.com/topic/136524-form-data-not-submitting/#findComment-712694 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.