www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Form send to XMLHTTP drives me nuts

  1. #1
    Join Date
    Mar 2009
    Posts
    36

    resolved [RESOLVED] Form send to XMLHTTP drives me nuts

    On my website i have several forms and links that use the same method to retrieve the data that should be shown on the website.
    Till now all are working great, except one. and it's driving me nuts.

    the form:
    HTML Code:
    <form name="frm_raidroster">
    <fieldset class="raid"><legend>Planned raid Monday 05 July 2010</legend>
    <a class="dkp_link" href="#" onclick="getloader('modify_for_raid_2010-07-5')">Modify</a><br>
    <fieldset><legend>Accepted</legend>  
    <table border="1" cellpadding="0" cellspacing="0">
    	<tr>
    		<td class="raid_call_header">Name</td>
    		<td class="raid_call_header">Role</td>
    		<td class="raid_call_header">Status</td>
    		<td class="raid_call_header">user note:</td>
    		<td class="raid_call_header">Admin Note</td>
    	</tr>
    	<tr>
    		<td><input name="membername[]" value="<charname>" type="hidden"><charname></td>
    		<td>
    		<select name="role[]">
    			<option value="Healer">Healer</option>
    			<option value="MDPS">M DPS</option>
    			<option value="RDPS">R DPS</option>
    			<option value="TANK" selected="selected">Tank</option>
    			<option value="Unkown">Unknown</option>
    		</select>
    		</td>
    		<td>
    		<select name="status[]">
    			<option value="ACCEPTED">Accepted</option>
    			<option value="QUEUED">Queued</option>
    			<option value="CANCELLED">Cancelled</option>
    		</select>
    		</td>
    		<td>
    			<input name="user_note[]" value="" type="hidden">
    		</td>
    		<td>
    			<input name="admin_note[]" value="" type="text">
    		</td>
    	</tr>
    	<tr>
    	..... more lines same as above 
    	</tr>
    	</table>
    </fieldset>
    <input name="raidrosterupdate" value="update" type="hidden">
    <input onclick="SaveRaidRoster('saveraidroster')" value="Apply change" type="submit">
    </fieldset>
    </form>
    <div id="raidroster"></div>
    <charname> are names from the database

    The javascript function used is:
    Code:
    function SaveRaidRoster(action){
    if (window.XMLHttpRequest)
      {
      xmlhttp=new XMLHttpRequest();
      }
    else
      {
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    var membername = document.frm_raidroster.elements["membername[]"];
    xmlhttp.onreadystatechange=function()
      {
      document.getElementById("raidroster").innerHTML='<img src="ajax-loader.gif" border="0" alt="loader" />';
      if (xmlhttp.readyState==4 && xmlhttp.status==200)
        {
        document.getElementById("raidroster").innerHTML=xmlhttp.responseText;
        }
      }
    xmlhttp.open("GET","menuaction.php?action="+action+"|"+membername ,true);
    xmlhttp.send();
    }
    When i debug the script with firebug I see the data being passed to the VAR membername., menuaction.php recieves the data in good order.

    The thing that is driving me NUTS is that after the script is done, its fills the address bar of my browser with the form data and returns to the index page.
    Where it should result in just showing the data parsed back from menuaction.php. That data is shown while I debug. but after the script leaves the onclick event from SaveRaidRoster('saveraidroster') it goes a-wall.

    would love to see someone point me in the right direction.

    /Fons

  2. #2
    Join Date
    Jul 2007
    Posts
    386
    That happens because you did not declare the action property to the form. By not declaring it the form submits to the page its on. The default method on forms is GET, which is why its shown in the URL.

    You can solve it rather easily. Just put the action property:
    Code:
    action="javascript:;"
    OR

    Code:
    onsubmit="return false;"

  3. #3
    Join Date
    Mar 2009
    Posts
    36
    That really solved one problem!
    Now all i need to get is the vars in a string, pass them on and work with them!

    thanks a lot !

    you saved my day

    /Fons

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles