Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[HELP] HTML Form/ Priority
#1
Hello,

I created a HTML form, with a drop down list of "priority levels". These include 'High', 'Medium', 'Low'. When the user submits the form, it displays the info in a table below the form.

What I want to do is when a user selects a priority level, and fills in the rest of the form, and submits it, it will display the correct priority level image. For example, 'High' priority has a "red" dot. 'Medium' a "yellow" dot, and 'Low' a "blue" dot.

I thought about doing something like this...But don't know to implement that into an HTML drop down form.

PHP Code:
if($priority == 1)
{
    echo 
"<img src='images/high.png' alt='High' title='High'>";
}
elseif(
$priority == 2)
{
    echo 
"<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif(
$priority == 3)
{
    echo 
"<img src='images/low.png' alt='Low' title='Low'>";


Thanks
Reply
#2
Here take a look at this code.

PHP Code:
<?php

echo <<<HTML
<form action="index.php" method="post">
    <select name="priority">
        <option value="1">High
        <option value="2">Medium
        <option value="3">Low
    </select>
    <input type="submit" name="submit" value="Submit" />
</from>
HTML;

if(isset(
$_POST['submit'])) {
    
$priority $_POST['priority'];
}else{
    die();
}

if(
$priority == 1)
{
    echo 
"<img src='images/high.png' alt='High' title='High'>";
}
elseif(
$priority == 2)
{
    echo 
"<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif(
$priority == 3)
{
    echo 
"<img src='images/low.png' alt='Low' title='Low'>";


?>
Reply
#3
Ok, that worked.

Now all I need is to echo the correct image on each table row. Here is part of my php code...

PHP Code:
<?php
            
// Important
            
$id $row['id'];
            
$result mysql_query("SELECT * FROM incidents");
            while(
$row mysql_fetch_array($result))
                {
                echo 
"<input type='hidden' name='id' value='$id'/>";
                echo 
"<tr>";
                echo 
"<td align='middle'>".$row['priority']."</td>";
                echo 
"<td>".$row['type']."</td>";
                echo 
"<td>".$row['location']."</td>";
                echo 
"<td>".$row['details']."</td>";
                echo 
"<td>".$row['rp']."</td>";
                echo 
"<td>".$row['units']."</td>";
                echo 
"<td>".$row['dispo']."</td>";
                echo 
"<td><a href='#'>Edit</a> / <a href='#'>Close</a></td>";
                echo 
"</tr>";
                }
            
?>

Where I have the
PHP Code:
"<td align='middle'>".$row['priority']."</td>"
I need to echo the correct priority image with the following..

PHP Code:
if($priority == 1)
{
   echo 
"<img src='images/high.png' alt='High' title='High'>";
}
elseif(
$priority == 2)
{
    echo 
"<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif(
$priority == 3)
{
    echo 
"<img src='images/low.png' alt='Low' title='Low'>";

Reply
#4
You can just put that IF/ELSEIF block on the place of the "$row['priority']" line... but instead of checking $priority, you check $row['priority']
Or a way I would suggest more is, save the images as "priority_1.png" _2/_3....

And then in the $row line you call this.

PHP Code:
echo "<img src=\"images/priority_".$row['priority'].".png\" alt=\"Priority\" title=\"Priority\" />" 
Reply
#5
(12-30-2009, 12:07 PM)Master of The Universe Wrote: You can just put that IF/ELSEIF block on the place of the "$row['priority']" line... but instead of checking $priority, you check $row['priority']
Or a way I would suggest more is, save the images as "priority_1.png" _2/_3....

And then in the $row line you call this.

PHP Code:
echo "<img src=\"images/priority_".$row['priority'].".png\" alt=\"Priority\" title=\"Priority\" />" 

Thank you so much! That worked perfectly Smile (rep+)
Reply
#6
(12-30-2009, 11:21 AM)Dutchcoffee Wrote: Hello,

I created a HTML form, with a drop down list of "priority levels". These include 'High', 'Medium', 'Low'. When the user submits the form, it displays the info in a table below the form.

What I want to do is when a user selects a priority level, and fills in the rest of the form, and submits it, it will display the correct priority level image. For example, 'High' priority has a "red" dot. 'Medium' a "yellow" dot, and 'Low' a "blue" dot.

I thought about doing something like this...But don't know to implement that into an HTML drop down form.

PHP Code:
if($priority == 1)
{
    echo 
"<img src='images/high.png' alt='High' title='High'>";
}
elseif(
$priority == 2)
{
    echo 
"<img src='images/medium.png' alt='Medium' title='Medium'>";
}
elseif(
$priority == 3)
{
    echo 
"<img src='images/low.png' alt='Low' title='Low'>";


Thanks

Can I make a suggestion, use switch instead of [else]if, just for neater code
[Completely Honest. Seriously.]

Protip: Anonymous Reputation Points are for Pussies
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  PHP email input form - having trouble getting the form to work... abayindi 4 2,745 03-19-2012, 10:02 AM
Last Post: RainbowDashFTW
  [NEED HELP] PHP Form post, get, echo Đενɨаηсε™ 5 2,083 02-06-2012, 01:16 PM
Last Post: ★Cooldude★
  How to make a form. HB Virus 10 3,675 12-30-2011, 08:03 PM
Last Post: BreShiE
  PHP form creator? Sam 7 2,713 07-13-2011, 04:53 AM
Last Post: Skyset
  HTML&PHP Games. flAmingw0rm 25 4,498 06-04-2011, 07:23 AM
Last Post: Strafeness

Forum Jump:


Users browsing this thread: 1 Guest(s)