Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Help with form

Namecheap AuctionsNamecheap Auctions
Namecheap AuctionsNamecheap Auctions
Spacemail by SpaceshipSpacemail by Spaceship
Watch

noswad

Established Member
Impact
1
Hi

I have this code which is for a drop down box

PHP:
<table border="0" cellspacing="0" cellpadding="0"> 
<tr> 
<td width="100%"><form name="mygallery"><p><select 
name="picture" size="1" onChange="showimage()"> 
<option selected value="../mobiles/images/handsets/6230i.jpg">Nokia 6230i</option> 
<option selected value="../mobiles/images/handsets/k750i.jpg">Sony Ericsson K750i</option> 
<option selected value="../mobiles/images/handsets/6280.jpg">Nokia 6280</option> 
</select></p> 
</form> 
</td> 
</tr> 
<tr> 
<td width="100%"><p align="center"><img src="images/handsets/1100.jpg" name="pictures" width="88" 
height="130"></td> 
</tr> 
</table>

As you can see, an image displays when a user selects an object from the drop down box.

My problem is that I don't want the image location to be the object value. Is it possible for me to choose my own values whilst still displaying the images?

Thanks for reading :hehe:
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
Anyone please. It's killing me :'(

:hehe:
 
0
•••
That's pretty easy. Set the value to whatever you want and pass the value to the function. Then check that value against a db table or whatever storage method ya use to display the image.
 
0
•••
monaco said:
That's pretty easy. Set the value to whatever you want and pass the value to the function. Then check that value against a db table or whatever storage method ya use to display the image.

Thanks for the reply.

Is it not possible to do this using a similar style to above?

i.e.

PHP:
<value="Nokia 6280" display image="../mobiles/images/handsets/6280.jpg">Nokia 6280</option>

...because I won't have a clue how to do this with a db.

:hehe:
 
0
•••
Well, you could hardcode it into the dsplay function:

Code:
function foo( value ) {
  if( value == "something" ) {
    // use image a
  }
  if( value == "something else" ) {
    // use image b
  }
}
 
0
•••
Hi

Thanks for your help.

Im now receiving the following error:

Parse error: parse error, unexpected T_STRING, expecting ')' in /homepages/5/d170332235/htdocs/gimp.php on line 15

Cheers.
 
0
•••
What's line 15?
 
0
•••
Hi

Its the top line...

function foo( value ) {

Cheers
 
0
•••
Its a variable aye? All instances should be $value.

Flubb.
 
0
•••
Hi.

Still no luck guys. I'm bamboozled.

This code has NO errors but doesn't show the images

PHP:
<?  
  function foo( $phone ) { 
if( $phone == "Nokia 6230i" ) {
  echo '<img src="/mobiles/images/handsets/6230i.jpg" />';  
} elseif( $phone == "Nokia 6280" ) { 
  echo '<img src="/mobiles/images/handsets/6280.jpg" />'; 
  } 
} 
  ?>

Thanks for trying :'(
 
Last edited:
0
•••
Are you actually calling the function at the options?

Flubb.
 
0
•••
I don't follow you. I just have that code in the body which produces the table, and when I select an option (using my browser), no pictures display.

Sorry - Im still quite new to PHP :td:

Thanks for helping :hehe:
 
0
•••
Is this corrent.

There your page with a drop down on it.

There are are say 5 options, each phones.

When the user chooses one of the phones you want the picture to kind of pop up or somthing?

Is that what your looking for?
 
0
•••
Yes that is correct but I don't want the value of each item to be the image location as what is shown in my first post at the top of this page.

I need to be able to name the values what I want.

Thanks :hehe:
 
0
•••
I've done it! WOOOOOOOOO :hehe:

The code I used was:

In the head:

PHP:
<script language="javascript">
<!--
function showimage()
{
if (!document.images)
return
document.images.pictures.src=
document.form.gift.options[document.form.gift.selectedIndex].imagelocation
}
//-->
</script>

and in the body...

PHP:
<img src="../mobiles/images/handsets/6230i.jpg" name="pictures" width="84"
height="130">                    <span class="gift_sub_name">
                    <P align="center"> 
                      
                      <select name="gift" size="1" id="gift" onChange="showimage()">
                        <option selected imagelocation="../mobiles/images/handsets/6230i.jpg" value="Nokia 6230i">Nokia 6230i</option>
                        <option imagelocation="../mobiles/images/handsets/6030.jpg" value="Nokia 6030">Nokia 6030</option>
                        <option imagelocation="../mobiles/images/handsets/6101.jpg" value="Nokia 6101">Nokia 6101</option>
                      </select>

:sold:
 
0
•••
AIVikingsAIVikings

We're social

Escrow.com
Spaceship
Escrowly
CryptoExchange.com
Domain Recover

NamePros updates

Watched threads: your alert now keeps up with new replies
When you watch a thread, each new reply now updates your alert. Before, you got one alert and then nothing until you read the thread...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back