Jump to content

Dynamic input field in post method


sihui

Recommended Posts

  <script language="JavaScript" type="text/javascript">

 

  function elemDisplayToggle(curState,objID){

  document.getElementById(objID).style.display = (curState) ? 'block' : 'none';

  }

 

function uncheckAll(field)

{

for (i = 0; i < field.length; i++)

field.checked = false ;

}

//  End -->

 

 

  </script>

<style type="text/css">

#assign_name{

 

display:none;

}

 

#loc{

 

display:none;

}

 

#assign_role{

 

display:none;

}

 

#teammembers{

 

display:none;

}

 

 

#client_name{

 

display:none;

}

 

#assigndate{

 

display:none;

}

 

#attendeesmohh{

 

display:none;

}

 

#attendeesclient{

 

display:none;

}

 

#stakeholdername{

 

display:none;

}

 

#stakeholdertype{

 

display:none;

}

 

 

</style>

<form name="myform" action="searchresults.php">

<?php

 

mysql_connect("localhost","root","") or die(mysql_error());

echo "Connected to MYSQL<br/><hr/>";

 

mysql_select_db("engagementrecord") or die(mysql_error());

echo "Connected to Database<br/><hr/>";

?>

 

<label><font size="5px">Search By:</font></label><br/><br/>

<label><font size="4px"><strong>CTS Staff:</strong></font></label><br/>

 

 

<?php

$query = "SELECT * FROM ctsstaff ORDER BY Name";

$result = mysql_query($query) or die(mysql_error());

$staffArr  = array();

while ($row = mysql_fetch_array($result)){

$staffArr[] = $row;

}

foreach($staffArr as $staff){

echo "<input name='name' type='checkbox' value='".$staff['Name']."'/>".$staff['Name']."";

echo "<select name='staffdetails' >";

echo "<option value='".$staff['Handphone']."'>Mobile:".$staff['Handphone']."</option>";

echo "<option value='".$staff['OfficeNo']."'>Office Tel:".$staff['OfficeNo']."</option>";

echo "<option value='".$staff['FaxNo']."'>Fax:".$staff['FaxNo']."</option>";

echo "<option value='".$staff['Email']."'>Email:".$staff['Email']."</option>";

echo "<option value='".$staff['Designation']."'>Designation:".$staff['Designation']."</option>";

echo "</select><br/>";

}

 

?>

 

 

<br/><hr/>

<label><font size="4px"><strong>Assignment:</strong></font></label><br/>

<table width="1200" border="0">

<tr>

<th width="200" scope="col" align="left"><label><input type="checkbox" name="assignment_name" value="assignment_name" onclick="elemDisplayToggle(this.checked,'assign_name')">Assignment Name</label></th>

<th width="1000" scope="col" align="left" id="assign_name">

<?php

$query = "SELECT * FROM assignments";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$name = $row['AssignmentName'];

$id = $row['AssignmentID'];

echo "<input name=\"assignname[]\" type=\"checkbox\" value=\"$name\"> $name<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

 

<tr>

<th scope="col" align="left"><label><input type="checkbox" name="location" value="location" onclick="elemDisplayToggle(this.checked,'loc')">Location</label></th>

<th scope="col" align="left" id="loc">

<?php

$query = "SELECT * FROM assignments";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$location = $row['Location'];

$id = $row['AssignmentID'];

echo "<input name=\"location[]\" type=\"checkbox\" value=\"$location\"> $location<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

 

<tr>

<th scope="col" align="left"><label><input type="checkbox" name="assignment_role" value="assignment_role" onclick="elemDisplayToggle(this.checked,'assign_role')">Assignment Role</label></th>

<th scope="col" align="left" id="assign_role">

<?php

$query = "SELECT * FROM assignments";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$role = $row['AssignmentRole'];

$id = $row['AssignmentID'];

echo "<input name=\"role[]\" type=\"checkbox\" value=\"$role\"> $role<br/>";

 

 

 

}

 

echo "";

 

?>

</th>

</tr>

 

<tr>

<th scope="col" align="left"><label><input type="checkbox" name="team_members" value="team_members" onclick="elemDisplayToggle(this.checked,'teammembers')">Team Members</label></th>

<th scope="col" align="left" id="teammembers">

<?php

 

$query = "SELECT * FROM assignments";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$teammembers = $row['TeamMembers'];

$id = $row['AssignmentID'];

echo "<input name=\"teammembers[]\" type=\"checkbox\" value=\"$teammembers\"> $teammembers<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

</table>

<br/><hr/>

 

<label><font size="4px"><strong>Engagement:</strong></font></label><br/>

<table width="1200" border="0">

<tr>

<th width="200" scope="col" align="left"><label><input type="checkbox" name="date" value="date" onclick="elemDisplayToggle(this.checked,'assigndate')">Date</label></th>

<th width="1000" scope="col" align="left" id="assigndate">

<?php

$query = "SELECT * FROM engagement";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$date = $row['Date'];

$id = $row['EngagementID'];

echo "<input name=\"date[]\" type=\"checkbox\" value=\"$date\"> $date<Br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

 

<tr>

<th width="200" scope="col" align="left"><label><input type="checkbox" name="attendees_mohh" value="attendees_mohh" onclick="elemDisplayToggle(this.checked,'attendeesmohh')">Attendees(MOHH)</label></th>

<th width="1000" scope="col" align="left" id="attendeesmohh">

<?php

$query = "SELECT * FROM engagement";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$mohh = $row['AttendeesMOHH'];

$id = $row['EngagementID'];

echo "<input name=\"mohh[]\" type=\"checkbox\" value=\"$mohh\"> $mohh<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

 

<tr>

<th width="200" scope="col" align="left"><label><input type="checkbox" name="attendees_client" value="attendees_client" onclick="elemDisplayToggle(this.checked,'attendeesclient')">Attendees(CLIENT)</label></th>

<th width="1000" scope="col" align="left" id="attendeesclient">

<?php

$query = "SELECT * FROM engagement";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$client = $row['AttendeesClient'];

$id = $row['EngagementID'];

echo "<input name=\"client[]\" type=\"checkbox\" value=\"$client\"> $client<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

</table>

<br/><hr/>

 

<label><font size="4px"><strong>Stakeholder:</strong></font></label><br/>

<table width="1200" border="0">

<tr>

<th width="200" scope="col" align="left"><label><input type="checkbox" name="stakeholder_name" value="stakeholder_name" onclick="elemDisplayToggle(this.checked,'stakeholdername')">Stakeholder Name</label></th>

<th width="1000" scope="col" align="left" id="stakeholdername">

<?php

$query = "SELECT * FROM stakeholder";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$name = $row['StakeholderName'];

$id = $row['StakeholderID'];

echo "<input name=\"name[]\" type=\"checkbox\" value=\"$name\"> $name<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

 

<tr>

<th width="200" scope="col" align="left"><label><input type="checkbox" name="stakeholder_type" value="stakeholder_type" onclick="elemDisplayToggle(this.checked,'stakeholdertype')">Stakeholder Type</label></th>

<th width="1000" scope="col" align="left" id="stakeholdertype">

<?php

$query = "SELECT * FROM stakeholder";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$type= $row['StakeholderType'];

$id = $row['StakeholderID'];

echo "<input name=\"type[]\" type=\"checkbox\" value=\"$type\"> $type<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

</table>

<br/><hr/>

 

<label><font size="4px"><strong>Client Biodata:</strong></font></label><br/>

<table width="1200" border="0">

<tr>

<th width="200" scope="col" align="left"><label><input type="checkbox" name="name" value="name" onclick="elemDisplayToggle(this.checked,'client_name')">Name</label></th>

<th width="1000"scope="col" align="left" id="client_name">

<?php

$query = "SELECT * FROM clientbiodata";

$result = mysql_query($query) or die(mysql_error());

 

while ($row = mysql_fetch_assoc($result)){

$name = $row['Name'];

$id = $row['ClientID'];

echo "<input name=\"name[]\" type=\"checkbox\" value=\"$name\"> $name<br/>";

 

}

 

echo "";

 

?>

</th>

</tr>

</table>

<br/><hr/>

 

</form>

<input type="button" name="UnCheckAll" value="Reset" onClick="uncheckAll(document.myform)">

 

<input type="button" name="submit_button" value="Submit">

 

<?php

 

 

$query = "Select MAX(AssignmentID) From assignments";

$result = mysql_query($query) or die(mysql_error());

 

// Print out result

while($row = mysql_fetch_array($result)){

$maxId = $row['MAX(AssignmentID)'];

echo $maxId;

}

 

for ($i=0; $i < count($_POST['assignname']); ++$i) {

 

$assignmentname = $_POST['name'][$i];

$location = $_POST['location'][$i];

$assignmentrole = $_POST['role'][$i];

$teammembers = $_POST['teammembers'][$i];

 

if (!isset($_POST['submit_button'])) { // if page is not submitted to itself echo the form

 

echo "ERROR!!<br/>";

}

 

}

 

?>

 

 

 

I would like to do something like this. When i check the checkbox and click on the "Submit" button, it will generate the database and display the data of the selected checkboxes in the other pages. But i got this dynamic input field problem which i do not how to know. Anyone who know how to solve it can provide me with solution? Thank You. 

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/207581-dynamic-input-field-in-post-method/
Share on other sites

No-one is going to do the coding for you unless you pay them. Ask a question about a single piece of code and you will probably get an answer.

 

Let me ask you a question.

Do you have time to look through my code in one of my programs and answer the question at the end of it? I am sure you will not like my answer, but this is why there is no answer to your question.

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.