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!
9 51590 -
<?
-
$language = $_GET["language"];
-
?>
-
if ($language = 1) {
-
?>
-
this picture changes cause language is set to English
-
<?
-
}
-
if ($language = 2) {
-
?>
-
this picture is something cause the language is set to chinese
-
<?
-
}
-
?>
-
<select onchange="window.location='whatever.php?language='+this.value">
-
<option value="1">English</option>
-
<option value="2">Chinese</option>
-
</select>
-
small sample of how this would be done whatever.php = the page your on.
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....
you need a better javascript then what i gave you it was an example -
<select onchange="window.location='select.php?language='+this.value">
-
<option value="0">- Select Language -</option>
-
<option value="1" <?if ($language == 1) {?>selected<?}?>>English</option>
-
<option value="2" <?if ($language == 2) {?>selected<?}?>>Chinese</option>
-
</select>
-
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.
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...
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?
-
<?php
-
$lang = $_GET["language"];
-
?>
-
<select onchange="window.location='select.php?language='+this.value">
-
<?php
-
$language = array(
-
"-- Make A Selection --",
-
"English",
-
"Deutsch",
-
"Magyar",
-
"Srpski");
-
for ($i = 1; $i <= 4; $i++)
-
{
-
?>
-
<option value="<?=$i?>" <?if ($lang==$language[$i]) { print "selected"; }><?=$language[$i]?></option>
-
<?
-
}
-
?>
-
</select>
-
<h3>Language is : <?=$lang?></h3>
-
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.
-
<?php
-
$lang = $_GET["language"];
-
?>
-
<select onchange="window.location='select.php?language='+this.value">
-
<?php
-
$language = array(
-
"-- Make A Selection --",
-
"English",
-
"Deutsch",
-
"Magyar",
-
"Srpski");
-
for ($i = 1; $i <= 4; $i++)
-
{
-
?>
-
<option value="<?=$i?>" <?if ($lang==$i) { print "selected"; }><?=$language[$i]?></option>
-
<?
-
}
-
?>
-
</select>
-
<h3>Language is : <?=$lang?></h3>
-
my bad changed one thing. if ($lang==$language[$i]) { needed to be if ($lang==$i)
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
ok to set it as 1 by default -
<?php
-
$lang = $_GET["language"];
-
if ($lang=="") {
-
$lang = 1;
-
}
-
?>
-
for the image you would do this on your page where you want the image -
<? if ($lang==1) { ?>
-
what ever here for the image
-
<? } ?>
-
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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,...
|
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)...
|
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...
|
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...
|
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...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
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...
|
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...
|
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...
|
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...
|
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)...
|
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...
|
by: Defcon1945 |
last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
|
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...
| |