Jump to content

PHP and Javascript problems


diablo908

Recommended Posts

Hello,

 

I have this form code:

<form id="form1" method="post" action="javascript:LoadPage('guestbook.php','content')" enctype="multipart/form-data" name="form1">
				<table  class="no_class" cellspacing="0" cellpadding="0">
				  <tr>
					<td style="width:200px;">
						<br style="line-height:9px">
						<span style="margin-left:33px">First Name:</span><br>
						<div class="form"><input name="Name_First" type="text" style="margin-left:33px"></div>
						<br style="line-height:8px">
						<span style="margin-left:33px">E-mail:</span><br>
						<div class="form"><input name="Email" type="text" style="margin-left:33px"></div>						</td>
					<td style="width:168px;">
					<br style="line-height:9px">
						Last Name:<br>
						<div class="form">
						  <input name="Name_Last" type="text" />
						</div>
				    <br style="line-height:8px">							<br></td>
					<td style="width:300px;">
					<br style="line-height:9px">
						Message:<br>
                            <textarea onKeyPress=check_length(this.form); onKeyDown=check_length(this.form); name="Message" rows=4 cols=30></textarea><br>
						<br>
						<input size=1 value=750 name=text_num> Characters Left
                            <br style="line-height:7px">
						<input type="submit" name="submit" value="Submit">					</td>
				  </tr>
				</table>
			  </form>

 

What I'm trying to do is post the data I enter to a database, but when I use

 

action="javascript:LoadPage('guestbook.php','content')"

 

I can't get the data to post properly. It just reloads the page.

 

This:

action="guestbook.php"

works, but I want to load guestbook.php into a div using the javascript function:

 

<script>
function LoadPage(page,usediv) {
         // Set up request varible
         try {xmlhttp = window.XMLHttpRequest?new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP");}  catch (e) { alert("Error: Could not load page.");}
         //Show page is loading
         document.getElementById(usediv).innerHTML = 'Loading Page...';
         //scroll to top
         scroll(0,0);
         //send data
         xmlhttp.onreadystatechange = function(){
                 //Check page is completed and there were no problems.
                 if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
                        //Write data returned to page
                        document.getElementById(usediv).innerHTML = xmlhttp.responseText;
                 }
         }
         xmlhttp.open("GET", page);
         xmlhttp.send(null);
         //Stop any link loading normaly
         //return false;
}
</script>

 

How can I use the javascript page load function while having the php variables properly post and get evaluated? Can I do some sort of:

 

action="javascript:LoadPage('guestbook.php?Name_First=$Name_First','content')" 

 

php GET stuff?

 

 

Totally confused, and any help would be appreciated.

Link to comment
https://forums.phpfreaks.com/topic/162400-php-and-javascript-problems/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.