1) Script Title:
a) DHTML Window widget (v1.03)
b) Basic Ajax Routine (get & post)
2) Script URL (on DD):
a) http://www.dynamicdrive.com/dynamici...ndow/index.htm
b) http://www.dynamicdrive.com/dynamici...jaxroutine.htm
3) Describe problem:
Using DHTML Window widget to open a ajax div that loads a form (this is working at 100%).
Using Basic Ajax Routine (get & post) to try to send the completed data back to the php file on the server.
The form comes up in the windowfiles div just fine.
When the user presses the submit button the windowfiles div goes away.
---
Form Code (excuse the PHP, it just loads the data):
<div name=responsediv id=responsediv><form name="myform" id="myform">
<input type=hidden value="<? echo $parent['email']; ?>" name=email>
<input type=hidden value="<? echo $rvaldata; ?>" name=rcode>
<table width=100% align=center border=0><tr><td align=center><? echo $msg; ?><table border=1 width=90%><tr><td> <center><h2>Parent Data</h2></center><table><tr><td class=rsmalltxt>First Name: </td><td class=smalltxt><input class=smalltxt type=text size=40 name=fname value="<? echo $parent['fname']; ?>"></td></tr><tr><td class=rsmalltxt> Last Name: </td><td class=smalltxt><input class=smalltxt type=text size=40 name=lname value="<? echo $parent['lname']; ?>"></td></tr><tr><td class=rsmalltxt> E-Mail: </td><td class=smalltxt><? echo $parent['email']; ?></td></tr><tr><td class=rsmalltxt> Address: </td><td class=smalltxt><input class=smalltxt type=text size=40 name=addr1 value="<? echo $contact['addr1']; ?>"></td></tr><tr><td class=smalltxt> </td><td class=smalltxt><input class=smalltxt type=text size=40 name=addr2 value="<? echo $contact['addr2']; ?>"></td></tr><tr><td colspan=2> <table><tr><td class=rsmalltxt>City: </td><td class=rsmalltxt><input class=smalltxt type=text size=20 name=city value="<? echo $contact['city']; ?>"></td><td class=rsmalltxt> State: </td><td class=rsmalltxt><input class=smalltxt type=text size=2 name=state value="<? echo $contact['state']; ?>"></td><td class=rsmalltxt> Zip: </td><td class=smalltxt><input class=smalltxt type=text size=10 name=zip value="<? echo $contact['zip']; ?>"></td></tr></table></td></tr><tr><td class=rsmalltxt> Phone: </td><td class=smalltxt><input class=smalltxt type=text size=40 name=phone value="<? echo $contact['phone']; ?>"></td></tr><tr><td class=smalltxt> FAX: </td><td class=smalltxt><input class=smalltxt type=text size=40 name=fax value="<? echo $contact['fax']; ?>"></td></tr><tr><td class=smalltxt> Cell/Other: </td><td class=smalltxt><input class=smalltxt type=text size=40 name=cell value="<? echo $contact['cell']; ?>"></td></tr></table></td></tr></table>
<p><input type=submit value=Submit onclick=""var poststr=createpoststring(); ajaxpack.postAjaxRequest('<? echo $PHP_SELF; ?>', poststr, processGetPost, 'txt'); return false""> <input type=reset value=Reset></td></tr></table></form></td></tr></table></div>
---
Javascript Code
<head>
<script type="text/javascript" src="ddrive/ajaxroutine.js">
/***********************************************
* Basic Ajax Routine- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* This notice MUST stay intact for legal use
* Visit Dynamic Drive at http://www.dynamicdrive.com/ for full source code
***********************************************/
</script>
<script type="text/javascript">
function getPostParameters(){
var poststr =
"rcode=" + encodeURI( document.getElementById("myform").rcode.value ) +
"&lname=" + encodeURI( document.getElementById("myform").lname.value ) +
"&fname=" + encodeURI( document.getElementById("myform").fname.value ) +
"&email=" + encodeURI( document.getElementById("myform").email.value ) +
"&addr1=" + encodeURI( document.getElementById("myform").addr1.value ) +
"&addr2=" + encodeURI( document.getElementById("myform").addr2.value ) +
"&city=" + encodeURI( document.getElementById("myform").city.value ) +
"&state=" + encodeURI( document.getElementById("myform").state.value ) +
"&zip=" + encodeURI( document.getElementById("myform").zip.value ) +
"&phone=" + encodeURI( document.getElementById("myform").phone.value ) +
"&cell=" + encodeURI( document.getElementById("myform").cell.value ) +
"&fax=" + encodeURI( document.getElementById("myform").fax.value ) +
"&pid=" + encodeURI( document.getElementById("myform").pid.value ) +
"&cid=" + encodeURI( document.getElementById("myform").cid.value ) +
"&sfname=" + encodeURI( document.getElementById("myform").sfname.value ) +
"&slname=" + encodeURI( document.getElementById("myform").slname.value ) +
"&sage=" + encodeURI( document.getElementById("myform").sage.value ) +
"&sgrade=" + encodeURI( document.getElementById("myform").sgrade.value );
return poststr
}
function processGetPost(){
var myajax=ajaxpack.ajaxobj
var myfiletype=ajaxpack.filetype
if (myajax.readyState == 4){ //if request of file completed
if (myajax.status==200 || window.location.href.indexOf("http")==-1){ //if request was successful or running script locally
if (myfiletype=="txt")
alert(myajax.responseText)
else
alert(myajax.responseXML)
}
}
}
</script>
---
What I want to happen is that the form will either return a response that required fields are missing or the record was updated and they can close the window inside the windowfiles div. I have no idea why the windowsfiles div is closing when I press the submit button.
Any help would be appreciated.
[note: I know I am getting more "values" in the javascript than there are in the form, this same routine will actually process two forms with shared fields, although some fields will be in only one form or the other, so they should be passed back blank.]



Reply With Quote



Bookmarks