SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Smile using php with <select> html tag

    Hello Friends,

    I am kinda new to PHP/MySQL. I think they are great tools.

    I was wondering if one can use PHP to choose a list of prices displayed in a combo using the <select> tag based on a previous item choosen. For example:

    if type == Soft then
    <select>
    <SELECT NAME=amount>
    <OPTION>1000
    <OPTION>500
    elseif type == Hard then
    <OPTION>1500
    <OPTION>800
    else
    <OPTION>100
    <OPTION>150

    etc.

    Any suggestions would be greatly appreciated.

    Best regards.

  2. #2

    Join Date
    Oct 2003
    Location
    €uroLand
    Posts
    1,340
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    http://www.sitepoint.com/forums/showthread.php?t=221820

    Seems to be a quite often raised issue in the last time

  3. #3
    SitePoint Addict kiltman's Avatar
    Join Date
    Mar 2004
    Location
    scotland
    Posts
    235
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would say this is possible but its more a javascript question as its going to use bandwidth that it really doesnt need to, try posting over in the javascript forum

  4. #4
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this piece of code

    PHP Code:
      $opt '<select name="amount">';
      switch(
    $type)
      {
        case 
    'Soft':
            
    $opt .= '<option>1000</optipon>';
            
    $opt .= '<option>500</optipon>';
          break;
        case 
    'Hard':
            
    $opt .= '<option>1500</optipon>';
            
    $opt .= '<option>800</optipon>';
          break;
        default:
            
    $opt .= '<option>100</optipon>';
            
    $opt .= '<option>150</optipon>';
          break;
      }
      
    $opt .= '</select>'
    this assusmes that somewhere you will set the $type variable (perhaps from $_POST or $_GET) and that somewhere else you will build the for and echo $opt at the appropriate time.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Friends,

    I would try that when I get to that part of my application.

    One more question pls. How do you write a link statement in PHP? I tried some like this:

    echo "<a href="index.htm">Home Page</a>";

    It didn't work.

  6. #6
    SitePoint Member ravikiran's Avatar
    Join Date
    Dec 2004
    Location
    hyderabad
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    writing html coding in php

    u can write the html coding in between php coding as follows:

    echo "<a href=index.html>Index</a>";

    or

    echo "<a href=index.html>".$text."</a>";

    where $text is the text u want to place there.

  7. #7
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Friends,

    Thanks alot ravikiran. I am already feeling at home here.

  8. #8
    SitePoint Enthusiast
    Join Date
    Jan 2005
    Location
    uganda
    Posts
    46
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if the select option is within your php script then all you need to do is specify the name where you want to store it in the database.

  9. #9
    SitePoint Wizard swdev's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    1,053
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    IMHO, you should always quote HTML attributes, so for the link example (post #6) I would write

    PHP Code:
      echo '<a href="index.htm">Home Page</a>'
    If the page name and / or display text were in varaibles, I would write it
    PHP Code:
    $link 'index.htm';
     
    $link_title 'Home Page';
     
     
    $ref '<a href="' $link '">' $link_title '</a>';
     echo 
    $ref
    The reason I use a temporary variable ($ref), is that I normall build up lots of HTML stuff in a string, then do 1 final echo

  10. #10
    SitePoint Member ravikiran's Avatar
    Join Date
    Dec 2004
    Location
    hyderabad
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Friend, why ur using the variables to write the html coding and increasing the burden to memory? u can use the statement as:

    echo "<a href='index.html'>Home Page</a>";

    if u want to give any user defined link text then u can give as follows:

    echo "<a href='index.html'>".$title."</a>";

    As per the storing all html coding in a variable and then echo that variable is fine but when u r going to use the bunch of html coding and u have multiple options so on depending the option the coding will change, then ur way of coding is absolutely correct.

    Thats all....
    Ravi


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •