Jump to content

Form data not submitting:


gamesmstr

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.