Hi,
I am wondering if anyone tried to mix PHP and Javascript innerHTML elements to change certain elements to decrease the number of submits without losing data when passing through forms.
For some reason, I kept getting errors in my code and I could only get PHP to submit the form one submit after another. Is it possible just to change one portion of the form element here and interact with PHP using Javascript?
Here is the code,
<html>
<head>
<title>Data Enter</title>
<script>
function change(field){
previousInnerHTML = document.getElementById('start').innerHTML = "<p>Hello</p>";
<?php
$query="SELECT name FROM end_from WHERE type='" . $type2 . "'";
$result = mysql_query ($query);
previousInnerHTML = previousInnerHTML.concat("<select name='end_location'>";
while($nt=mysql_fetch_array($result)){//Arrayor records stored in $nt
previousInnerHTML += "<option value=$nt[0]>$nt[0]</option>";
}
previousInnerHTML += "</select></p>";// Closing of list box
?>
}
</script>
</head>
<body>
<?php
// Make a MySQL Connection
mysql_connect("localhost", "xxx", "xxxx") or die(mysql_error());
mysql_select_db("xxx") or die(mysql_error());
$type = $_POST['type'];
$start_time = $_POST['start_time'];
if (isset($_POST['submit'])) { // if page is not submitted to itself echo the form
echo $type . " " . $start_time . "\n";
?>
<form action="test2.php" method="post" name="start">
<p><div id="start">
<?php
$query="SELECT name FROM start_from WHERE type='" . $type . "'";
$result = mysql_query ($query);
echo "<select name='start_location'>"; // printing the list box select command
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option value=$nt[0]>$nt[0]</option>";
/* Option values are added by looping through the array */
}
echo "</select>";// Closing of list box
?>
</div>
<br/>
<input type="hidden" name="start_time" value="<?=$start_time?>"/>
<input type="submit" name="submit" value="Submit" >
</p>
</form>
<? }
else {
?>
<form action="" name="form1" method="post">
<p>
What Time Would You Like to Start? <input type="text" name="start_time" size="25"/><br />
Select the type for your starting point:<br>
<div id="start">
<input type="radio" value="Apartment" name="type" onchange="check(document.form1.type)"/>Apartment
<input type="radio" value="Grocery" name="type" onchange="check(document.form1.type)"/> Grocery </div>
<input type="submit" name="submit" value="Submit" >
</p>
</form>
<?
}
?>
Have I done something wrong here?
Thanks for your help.