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 51608 iam_clint 1,208
Recognized Expert Top Contributor -
<?
-
$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="windo w.location='sel ect.php?languag e='+this.value" >
<option value="1">Engli sh</option>
<option value="2">Chine se</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....
iam_clint 1,208
Recognized Expert Top Contributor
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="JavaS cript">
function jumpmenu(selLan g)
{
var s = selLang;
echo "<img src=$s.gif>";
}
</script>
<?
print <<<HERE
<select name="select" onchange="jumpm enu(this)">
<option value="1" selected>Srpski </option>
<option value="2">Magya r</option>
<option value="3">Engli sh</option>
<option value="4">Deuts ch</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="windo w.location='sel ect.php?languag e='+this.value" >
<?php
$language = array(
"",
"English",
"Deutsch",
"Magyar",
"Srpski");
for ($i = 1; $i <= 4; $i++)
{
print "<option value=$i>$langu age[$i]</option>";
print "<h3>Langua ge 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?
iam_clint 1,208
Recognized Expert Top Contributor -
<?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.
iam_clint 1,208
Recognized Expert Top Contributor -
<?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==$langua ge[$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="windo w.location='sel ect.php?languag e='+this.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?>.gi f" 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
iam_clint 1,208
Recognized Expert Top Contributor
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 this? eg
document.forms.form.list1.selectedIndex='NULL'; ?
Where can I find out about all options with regards to the DOM?
Thanks,
|
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 getElementById
to select a particular form?
--
Thanks,
Justin.
http://www.opera.com/mail/
|
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 switchbox which is showed in
maximum.
Is there a command where I can select a form which is stil open on the
background?
|
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, scrollbar-arrow but still I get the System Default.
Thanks in Advance. - CES
|
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) it
appears wierd:
When I disable the selevt element in IE, it continues to appear as
enabled (falsely) until I try changing it.
When I click on it, updates itself as grey as to indicate that it is
disabled.
| |
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 Variables.oSurvey.secCode)>selected="true"</cfif>>#Request.qSecCodes.org_name#</option>
</cfloop>
</select>
</form>
As you can see, I'm populating that select with the results of a query. I wanted to have a value selected by default. That's what the CFIF was put...
|
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 JS disables the select element correctly, but it does not re-enable it. Could someone please help with the right code.
here is the Javascript code.
function annconf() {
|
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 can contain other forms, sometimes known as subsubforms. This article deals only with main forms and their immediate subforms.
The books about Access I’ve read contain some useful information about subforms, but don’t adequately cover the matter of...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |