473,663 Members | 2,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

PHP select form

10 New Member
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 51608
iam_clint
1,208 Recognized Expert Top Contributor
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
dujmovicv
10 New Member
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....
Jul 18 '06 #3
iam_clint
1,208 Recognized Expert Top Contributor
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
dujmovicv
10 New Member
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...
Aug 11 '06 #5
dujmovicv
10 New Member
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?
Aug 15 '06 #6
iam_clint
1,208 Recognized Expert Top Contributor
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 Recognized Expert Top Contributor
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==$langua ge[$i]) { needed to be if ($lang==$i)
Aug 15 '06 #8
dujmovicv
10 New Member
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
Aug 16 '06 #9
iam_clint
1,208 Recognized Expert Top Contributor
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
8932
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,
3
5692
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/
4
1654
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?
1
1869
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
1
2797
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.
4
3673
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 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...
4
20448
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() {
0
30376
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...
0
8436
marktang
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...
0
8345
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,...
1
8548
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,...
0
8634
tracyyun
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...
0
7371
agi2029
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...
0
5657
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();...
0
4182
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...
1
2763
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
2
1757
bsmnconsultancy
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...

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.