Solved

Button in first row of html table does not work

Posted on 2014-04-11
2
987 Views
Last Modified: 2014-04-17
Hi all.

I have a php page (see below). Each row of data has a button, if the status is Open then the button is showed otherwise the button is not shown. When the button is clicked it goes to another file (ProcessToDoAction.php). Something weird is happening, the button on the first row of data does not work, meaning it does not go to the file ProcessToDoAction.php but rather it goes to the form's action (LookupResultsConvertJobType.php). And again this only happens on the first row of data, if I click the button on the second row it goes to the correct file (ProcessToDoAction.php).

Any idea why this is happening?

Thank you in advance.

  <head>
  <title>MyPage</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="style.css" type="text/css" />
  <link href="iphone-icon1.png" rel="apple-touch-icon">
  </head>
<body>
      				
<div class="wrapper">
    <div id="logo"></div>
    <form class="form4" action="LookupResultsConvertJobType.php" method="post">
<div class="formtitle4">Lookup Form</div>
  </head>
<body>
  <div class="input3">
                       <div class="inputtext">Job Type:</div>
               <div class="inputcontent" >
                    <?php  foreach($data as $row){ echo '<input type="text" name="jobtype" id="jobtype" value="' . html_escape($row['jobtypedescription']) . '">'; } ?>           
               </div>
               <?php if ($row['Type'] == 1 AND	$row['Status'] <> 'Completed') {
               echo '<input class="button5"  type="submit" value="Convert to D"/><p></p>'; }
               		 
               		 elseif ($row['Type'] == 2 AND	$row['Status'] <> 'Completed') {  // Job type is 2
	               		 echo '<input class="button5"  type="submit" value="Convert Back To S"/><p></p>';
               		 }  ?>              
           
          </div>
           
		  <div class="input3">
            
                <table cellpadding="0" cellspacing="0"  class="db-table" align = "center">
                <tr>
                <th>To Do</th>
                <th>Status</th>
                <th>Date</th>
                <th>Action</th>
                </tr>
                               
                <?php  foreach($data1 as $row){ 
                    echo '<tr>';
                    echo '<td>' . html_escape($row['ToDo']) . '</td>';
                    echo '<td>' . html_escape($row['Status']) . '</td>';
                    echo '<td>' . html_escape($row['ToDoStatusDate']) . '</td>';
                     if ($row['Status'] == 'Open') 
					{
						echo "<td>
						<form action='ProcessToDoAction.php' method='post'>        					
						<input type='text' id='DataEntryID' name='DataEntryID' value='" . html_escape($row['DataEntryID']) . "'/>
						<input type='text' id='todoid' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>
						<input class='button8'  type='submit'  value='Complete'/>
						</form>				
						</td>";
					}

				   else
				   {
					   echo "<td>                 
					   	<input type='hidden' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>      
					   	</td>";   
				  }
                    echo '</tr>';
                   
                } ?>                 
               </table>

			<div class="buttons" align = center>

				<input class="button1"  type="submit" formaction="BacktoLookup.php" value="Search" /> 
				<input class="button1"  type="submit" formaction="Menu.php" value="Menu" /> 
				<input class="button1"  type="submit" formaction="Shortage.php" formmethod="post" value="Shortage" /> 		
			</div>   
</form>
</div>
</body>
</html>

Open in new window

0
Comment
Question by:Sim1980
2 Comments
 
LVL 42

Assisted Solution

by:Rob Jurd, EE MVE
Rob Jurd, EE MVE earned 250 total points
ID: 39995986
This is to do with nested forms, forms within forms.  You can't do that, which is why you're getting it working once and not after that because the browser has submitted that form but even this could give you unexpected results across browsers (and versions thereof).  

You'll need to rethink your design.

Having said that, I don't think it's going to be too hard but I would need to know more info on both ProcessToDoAction and LookupResultsConvertJobType but I suspect you may be able to call the ProcessToDoAction using ajax (and hence removing those form tags in the rows).  Then you can submit the main form LookupResultsConvertJobType once all rows have been "modified"
0
 
LVL 33

Accepted Solution

by:
Slick812 earned 250 total points
ID: 39996403
Hello Sim1980, You may have better HTML if you take OUT all of the -
<form action='ProcessToDoAction.php' method='post'>

from the -
<form class="form4" action="LookupResultsConvertJobType.php" method="post">

so the browser can work with a single form at a time, ,

also your HTML is very messed up you have TWO -
</head>
<body>

which can get the browser to be inconsistent.

Also you have this DIV - <div class="input3">  start INSIDE a <form> , BUT it ends with </div>  OUTSIDE that form as -
</form>
</div>

making the browser display inconsistent, , you might try something like -
  <head>
  <title>MyPage</title>
  <meta http-equiv="content-type" content="text/html; charset=utf-8" />
  <link rel="stylesheet" href="style.css" type="text/css" />
  <link href="iphone-icon1.png" rel="apple-touch-icon">
  </head>
<body>
      				
<div class="wrapper">
    <div id="logo"></div>
    <form class="form4" action="LookupResultsConvertJobType.php" method="post">
<div class="formtitle4">Lookup Form</div>
  <div class="input3">
   <div class="inputtext">Job Type:</div>
    <div class="inputcontent" >
<?php  foreach($data as $row){ echo '<input type="text" name="jobtype" id="jobtype" value="' . html_escape($row['jobtypedescription']) . '">'; } ?>           
    </div>
<?php if ($row['Type'] == 1 AND	$row['Status'] <> 'Completed') {
  echo '<input class="button5"  type="submit" value="Convert to D"/><p></p>'; }
  elseif ($row['Type'] == 2 AND	$row['Status'] <> 'Completed') {  // Job type is 2
    echo '<input class="button5"  type="submit" value="Convert Back To S"/><p></p>';
    }  ?>              
  </div>
   
  <div class="buttons" align = center>
  <input class="button1"  type="submit" formaction="BacktoLookup.php" value="Search" /> 
  <input class="button1"  type="submit" formaction="Menu.php" value="Menu" /> 
  <input class="button1"  type="submit" formaction="Shortage.php" formmethod="post" value="Shortage" /> 		
  </div>   
</form>


<div class="input3">
     <table cellpadding="0" cellspacing="0"  class="db-table" align = "center">
<tr>
<th>To Do</th><th>Status</th><th>Date</th><th>Action</th>
</tr>
<?php  foreach($data1 as $row){ 
  echo '<tr>';
  echo '<td>' . html_escape($row['ToDo']) . '</td>';
  echo '<td>' . html_escape($row['Status']) . '</td>';
  echo '<td>' . html_escape($row['ToDoStatusDate']) . '</td>';
  if ($row['Status'] == 'Open') {
    echo "<td>
    <form action='ProcessToDoAction.php' method='post'>        					
    <input type='text' id='DataEntryID' name='DataEntryID' value='" . html_escape($row['DataEntryID']) . "'/>
    <input type='text' id='todoid' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>
    <input class='button8'  type='submit'  value='Complete'/>
    </form>				
    </td>";
  } else {
  echo "<td>                 
  <input type='hidden' name='todoid' value='" . html_escape($row['ToDoID']) . "'/>      
  </td>";   
  }
  echo '</tr>';
} ?>                 
    </table>
</div>

Open in new window

notice that I removed ALL of the <div class="input3"> OUTSIDE of the -
<form class="form4" action="LookupResultsConvertJobType.php" method="post">
    <form> code
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
In this tutorial viewers will learn how to define a gradient in CSS. Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Gradient. Define the background as "linear-gradient(to right, #ee3668, black)". Ensure you …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now