radio button value posting image on 2nd page

Discussion in 'PHP' started by rlhanson, Jan 17, 2009.

  1. #1
    I have a form which has 2 radio buttons with onClick events that display background images in a preview table based on the selection. I want to pass the same information (values) to another page.

    I (think I) need the values (which are interacting with my db) to be passed through a php function that determines if the radio button value==414 than display "this image".

    Here's the radio button code so you can see where I am going with this:
    <input type="radio" name="optn2" value="414" onclick="document.getElementById('cardTemplate').style.backgroundImage='url(designer/images/pics/backgrounds/3bamboo.jpg)';document.getElementById ('background').value=this.src;" />
    
    <input type="radio" name="optn2" value="415" onclick="document.getElementById('cardTemplate').style.backgroundImage='url(designer/images/pics/backgrounds/9birchlake.jpg)';document.getElementById ('background').value=this.src;" />
    
    HTML:
    I have text values which are passing fine ... here's the text input code:

    
    <input type="hidden" name="optn3" value="413" />
    <input name="voptn3" type="text" id="company_name" tabindex="1" onchange="document.getElementById('companyName').innerHTML=this.value;" size="25" maxlength="50" />
    
    
    HTML:
    Here's the php code which is working:

    
    
    $company_name 	= $_POST["voptn3"];
    
    
    PHP:
    
    <table width="325" height="200" border="0" align="center" cellpadding="0" cellspacing="0" id="cardTemplate">
              <tr>
                <td colspan="3" align="center" valign="bottom" background="/images/clearpixel.gif" class="companyname"><?php echo $company_name;?></td>
              </tr></table>
    
    HTML:
    So how do I get the programming to where if $optn2 value = 414 then display this image?

    Any help would be GREATLY appreciated!!
     
    rlhanson, Jan 17, 2009 IP
  2. artiskool

    artiskool Peon

    Messages:
    34
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Use the same working code you had for company name.
    Try this
    
    $optn2 = $_POST['optn2'];
    if ($optn2 == '414') {
        // display "this image"
    }
    
    PHP:
     
    artiskool, Jan 18, 2009 IP
  3. rlhanson

    rlhanson Peon

    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    This is exactly what I was tyring to get! I have the desired images echoing onto the page now, but I need the image to display as a background image in a <TD> cell - how would I do that?
     
    rlhanson, Jan 18, 2009 IP
  4. rlhanson

    rlhanson Peon

    Messages:
    25
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I got the display to work as a background image by coding the table with php vs. html....

    Next question, since I will eventually have many, many images... how do I tell my database that the value 414 = an image so that when I echo just $optn2 it pulls the image instead of "414"?

    Any help would be great!
     
    rlhanson, Jan 18, 2009 IP