KevinB Posted March 24, 2009 Share Posted March 24, 2009 Hi. This is my first post here. I'm a beginner when it comes to PHP and am currently developing a website which I need a little bit of help with. It's mostly done and working etc... but there are a few small issues I would like to iron out. First - I have a total value which prints out conditionally based on what item from the drop down list is selected. switch ($format) { case kb: print("<td> <input type ='text' disabled value ='$kilobytes' size = '10'> </td>"); break; case mb: print("<td> <input type ='text' disabled value ='$megabytes' size = '10'> </td>"); break; case gb: print("<td> <input type ='text' disabled value ='$gigabytes' size = '10'> </td>"); break; case tb: print("<td> <input type ='text' disabled value ='$terabytes' size = '10'> </td>"); break; default: echo "Error"; } This works fine but I would like it to display in a HTML table I have created. Here to be precise: <tr> <td><span class="style1"><b>Total:</b></span></td> <td><input name="total" type="text" disabled onFocus="blur();" class="inputWidth" size = '12' value=" "/></td> </tr> I would also like to set the the first column in the table as the focus so that when the page loads the cursor will default to that position. Any help would be muchly appreciated. Link to comment https://forums.phpfreaks.com/topic/150823-solved-php-help-small-issue/ Share on other sites More sharing options...
deerly Posted March 24, 2009 Share Posted March 24, 2009 <tr> <td><span class="style1"><b>Total:</b></span></td> <?php switch ($format) { case kb: print("<td> <input type ='text' disabled value ='$kilobytes' size = '10'> </td>"); break; case mb: print("<td> <input type ='text' disabled value ='$megabytes' size = '10'> </td>"); break; case gb: print("<td> <input type ='text' disabled value ='$gigabytes' size = '10'> </td>"); break; case tb: print("<td> <input type ='text' disabled value ='$terabytes' size = '10'> </td>"); break; default: echo "Error"; } ?> <td><input name="total" type="text" disabled onFocus="blur();" class="inputWidth" size = '12' value=" "/></td> </tr> Wouldn't that work? Except I think I would put the table structure outside the PHP tags and then just fill in the value or error message depending on the switch result. Link to comment https://forums.phpfreaks.com/topic/150823-solved-php-help-small-issue/#findComment-792375 Share on other sites More sharing options...
KevinB Posted March 24, 2009 Author Share Posted March 24, 2009 Hi. Thanks for the quick reply. Unfortunately that did not solve my problem. I have attached a screenshot below and the code for the table and the switch statement to make the problem a little clearer. http://img21.imageshack.us/my.php?image=phpproblem.jpg As you can see the program is working fine and printing to the screen but its printing to the bottom left rather than to the 'total' text box within the table. The table is written in html and the output box on the bottom left is written in php and only executes within a case statement. Table: <form method="post" action="/my.php" class="contactForm"> <table width="194" border="1" align="center"> <tr> <td width="67"><span class="style1">Hours:</span></td> <td width="150"><input name="hours" type="text" onFocus=" class="inputWidth" size = '12' value=" "/></td> </tr> <tr> <td><span class="style1">Minutes:</span></td> <td><input name="minutes" type="text" class="inputWidth" size = '12' value=" "/></td> </tr> <tr> <td><span class="style1">Seconds:</span></td> <td><input name="seconds" type="text" class="inputWidth" size = '12' value=" "/></td> </tr> <tr> <td><span class="style1">Format:</span></td> <td><select name="format"> <option value="kb">Kilobytes</option> <option value="mb">Megabytes</option> <option selected value="gb">Gigabytes</option> <option value="tb">Terabytes</option> </select></td> </tr> <tr> <td><span class="style1"><b>Total:</b></span></td> <td><input name="total" type="text" disabled onFocus="blur();" class="inputWidth" size = '12' value= " "/></td> </tr> </table> <p align="center"> <input type="submit" name="submit" value="Calculate"/> <input type="reset" name="reset" onclick="cleartext()" value="Clear"/> </p> <p> </p> <p> </p> <br /> </form> PHP Print Code: else { switch ($format) { case kb: print("<td> <input type ='text' disabled value ='$kilobytes' size = '10'> </td>"); break; case mb: print("<td> <input type ='text' disabled value ='$megabytes' size = '10'> </td>"); break; case gb: print("<td> <input type ='text' disabled value ='$gigabytes' size = '10'> </td>"); break; case tb: print("<td> <input type ='text' disabled value ='$terabytes' size = '10'> </td>"); break; default: echo "Error"; } I just need to get the output from the switch to print in the text box called 'total' which is in the HTML table. Link to comment https://forums.phpfreaks.com/topic/150823-solved-php-help-small-issue/#findComment-792538 Share on other sites More sharing options...
lonewolf217 Posted March 24, 2009 Share Posted March 24, 2009 fix the screenshot link pls Link to comment https://forums.phpfreaks.com/topic/150823-solved-php-help-small-issue/#findComment-792540 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.