473,320 Members | 1,854 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

PHP select form

I'm new in PHP programming, I suppose that my problem will be a child's-play for experts....
I need to write a PHP script with a "select" input form, which will offer 4 languages to chose between. When the user clicks on an item in the select list, the menu (buttons), some pictures shall change on the page regarding to the choice.
Please if exists, send me an example or good links for building web pages in PHP.
Thank You!
Jul 17 '06 #1
9 51590
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <?
  2. $language = $_GET["language"];
  3. ?>
  4. if ($language = 1) {
  5. ?>
  6. this picture changes cause language is set to English
  7. <?
  8. }
  9. if ($language = 2) {
  10. ?>
  11. this picture is something cause the language is set to chinese
  12. <?
  13. }
  14. ?>
  15. <select onchange="window.location='whatever.php?language='+this.value">
  16. <option value="1">English</option>
  17. <option value="2">Chinese</option>
  18. </select>
  19.  
small sample of how this would be done whatever.php = the page your on.
Jul 17 '06 #2
Thank you for your quick help!

There are some errors in your script, I managed to correct some things, but it still doesn't work...

<?
$language = $_GET["language"];

if ($language == 1) {
?>
English
<?
}
if ($language == 2) {
?>
Chinese
<?
}
?>
<select onchange="window.location='select.php?language='+t his.value">
<option value="1">English</option>
<option value="2">Chinese</option>
</select>

The script prints "Chinese" when you select "Chinese", but in the select field is still "English", and when click on "English", nothing happens....
Jul 18 '06 #3
iam_clint
1,208 Expert 1GB
you need a better javascript then what i gave you it was an example
Expand|Select|Wrap|Line Numbers
  1. <select onchange="window.location='select.php?language='+this.value">
  2. <option value="0">- Select Language -</option>
  3. <option value="1" <?if ($language == 1) {?>selected<?}?>>English</option>
  4. <option value="2" <?if ($language == 2) {?>selected<?}?>>Chinese</option>
  5. </select>
  6.  

i am trying to refrain from giving you code without trial and error you will never know exactly what you did wrong.. anymore that needs to be done to this script you can code and i can check your code.
Jul 18 '06 #4
Hello iam_clint!

I'm back again with my probleme....

So, as I mentioned I've tried to combine php and java to build a dynamic menu with select form. Here is my code (example), I wonder if I'm going on the right way....
Please help if U have some good ideas... ;-)

<script language="JavaScript">

function jumpmenu(selLang)
{
var s = selLang;
echo "<img src=$s.gif>";
}

</script>

<?
print <<<HERE
<select name="select" onchange="jumpmenu(this)">
<option value="1" selected>Srpski</option>
<option value="2">Magyar</option>
<option value="3">English</option>
<option value="4">Deutsch</option>
</select>
HERE;
?>

As you can suppose it doesn't works...
Aug 11 '06 #5
I managed to echo a select drop-down menu with 4 languages with an array:

[php]
<?php
$language = $_GET["language"];
?>
<select onchange="window.location='select.php?language='+t his.value">
<?php
$language = array(
"",
"English",
"Deutsch",
"Magyar",
"Srpski");
for ($i = 1; $i <= 4; $i++)
{
print "<option value=$i>$language[$i]</option>";
print "<h3>Language is : $language[$i]</h3>";
}
?>
</select>
[/php]

I can't see my mistake : in the select field always stays "English" and don't change to the selecteg language... The other question: the script doesn't prints the text in <h3> tag. Why is that?
Aug 15 '06 #6
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $lang = $_GET["language"];
  3. ?>
  4. <select onchange="window.location='select.php?language='+this.value">
  5. <?php
  6. $language = array(
  7.     "-- Make A Selection --",
  8.     "English",
  9.     "Deutsch",
  10.     "Magyar",
  11.     "Srpski");
  12. for ($i = 1; $i <= 4; $i++)
  13. {
  14. ?>
  15. <option value="<?=$i?>" <?if ($lang==$language[$i]) { print "selected"; }><?=$language[$i]?></option>
  16. <?
  17. }
  18. ?>
  19. </select>
  20. <h3>Language is : <?=$lang?></h3>
  21.  
This should fix your problems, hope this is helping you learn :).
You can see the changes i made. It didn't print in h3 tags because you were still in the select tag.
Aug 15 '06 #7
iam_clint
1,208 Expert 1GB
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $lang = $_GET["language"];
  3. ?>
  4. <select onchange="window.location='select.php?language='+this.value">
  5. <?php
  6. $language = array(
  7.     "-- Make A Selection --",
  8.     "English",
  9.     "Deutsch",
  10.     "Magyar",
  11.     "Srpski");
  12. for ($i = 1; $i <= 4; $i++)
  13. {
  14. ?>
  15. <option value="<?=$i?>" <?if ($lang==$i) { print "selected"; }><?=$language[$i]?></option>
  16. <?
  17. }
  18. ?>
  19. </select>
  20. <h3>Language is : <?=$lang?></h3>
  21.  
my bad changed one thing. if ($lang==$language[$i]) { needed to be if ($lang==$i)
Aug 15 '06 #8
Thank you for your efforts, you helped me a lot to learn PHP. With some corrections in your code, I have solved the problem. :)
Now I have another question, hope I'm not boring....
How to set the $language to 1 by default (when the page is being loaded for the first time)?
[php]
<?php
$lang = $_GET["language"];
?>
<select onchange="window.location='select.php?language='+t his.value">
<?php
$language = array(
"",
"English",
"Deutsch",
"Magyar",
"Srpski");
for ($i = 1; $i <= 4; $i++)
{
?>
<option value="<?=$i?>" <? if ($lang == $i) { print "SELECTED";}?>> <?=$language[$i]?></option>
<?
}
?>
</select>
<br>
<img src = " <?=$lang?>.gif" width="40" height="20">
[/php]

In that case, the field for the *.gif image is empty when the page is loaded, and after the user choice the script loads the appropriate image. How to load the 1.gif image at the start?

Best regards
Aug 16 '06 #9
iam_clint
1,208 Expert 1GB
ok to set it as 1 by default
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $lang = $_GET["language"]; 
  3. if ($lang=="") {
  4.     $lang = 1;
  5. }
  6. ?> 
  7.  
for the image you would do this on your page where you want the image
Expand|Select|Wrap|Line Numbers
  1. <? if ($lang==1) { ?>
  2. what ever here for the image
  3. <? } ?>
  4.  
Aug 16 '06 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Keiron Waites | last post by:
Hi, I have two select fields with the multiple attribute so you can see all options. When a user clicks on one form, I would like to deselect anything from the other form. Is there a way to do...
3
by: Justin Sane | last post by:
I haven't been able to select a form using getElementById. I only can select a form using the "name" property of the <form> tag. Is there another way to select a form, or is it even possible to use...
4
by: TTD | last post by:
Hi, I have a form (formA) which is maximized. On that form I have a button which opens formB in restore-mode. But when I leave formB, I don't get formA maximized on the foreground, but it's the...
1
by: CES | last post by:
All, Sorry for the question because I'm pretty sure I know the answer... Is their a way of changing the Border or Arrow color of a Select Element?? I've tried all of the foe CSS scrollbar-face,...
1
by: kebabkongen | last post by:
Hi, I'm working on a JavaScript that is enabling / disabling a select element according to whether a checkbox is selected or not. This works fine in Firefox, but in Internet Explorer (v 6.0.2900)...
4
Haitashi
by: Haitashi | last post by:
Snippet: <form> <select name="secCode" id="secCode"> <cfloop query="Request.qSecCodes"> <option value="#Request.qSecCodes.org_name#" <cfif (Request.qSecCodes.org_code EQ...
4
by: cptuser | last post by:
Hi, I have an online form which has a select element, which I;m using very basic JS to enable and disable a select element based on the selection of another select element. For some reason, the...
0
by: Gordon Padwick | last post by:
A form contains controls, one or more of which can be other forms. A form that contains another form is known as a main form. A form contained by a main form is known as a subform. A subform itself...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.