Pedantic Curmudgeon
When posting code, please use the appropriate formatting codes described in the FAQs. As it happens, in this case doing so would have provided a clue as to your problem:
PHP Code:
echo '<option value="' . $key . '" .$_POST[' region '] == ' $key ' ? ' selected ' : ' > '.$value.' </ option > ';
You're missing a ' after the second " (since you haven't written any abbreviations with apostrophes, you'd expect to count an even number of them in the line - half of them opening quotes, half of them closing).
I knew i shouldve done that, with my haste didnt see the option...
OK, ive changed it, i get no error now but my result (creating <option> tags from my array) isnt showing up...
if anyone thinks its better i past my whole page let me know and ill do it.
Thanks
Can you show us a fixed copy of the PHP code snippet above? Also, can you show us the resulting output it generates?
its actually a short page ill just put it all here:
i dont know if i wrapped the code right as its my first time so if its wrong...
All i got on the page is 2 dropdowns the first one getting for a certain array and the second one is meant to choose an erray depending on the first one...
PHP Code:
<?php
$region = Array ( 'EU' , 'NON EU' );
$EUcountries = Array( 'UK' , 'Spain' );
$NONEUcountries = Array( 'Austria' , 'Australia' );
?>
<html>
<head>
<title>
</title>
<style>
#container {
border: 1px solid grey;
width: 900px;
margin: 0 auto;
min-height: 200px;
}
.header {
text-align: center;
text-transform:uppercase;
font-size: 35px;
font-family: impact;
color: #fff;
background-color: grey;
}
.country {
float: left;
top: 30px;
left: 30px;
width: 200px;
border: 1px solid grey;
text-align: center;
position: relative;
}
.select_country {
float: left;
left: 30px;
top: 30px;
width: 200px;
border: 1px solid grey;
position: relative;
text-align: center;
}
.print {
left: 30px;
top: 80px;
width: 840;
border: 1px solid grey;
text-align: left;
position: relative;
}
</style>
</head>
<body>
<div id="container">
<div class="header">
test
</div>
<div class="country" >
<form action="" method="POST" name="region">
<select name="region" id="select_type" onchange="document.region.submit()">
<option> ---Please Select--- </option>
<?php
foreach( $region as $key => $value ){
echo '<option value="' . $key . '" ' . $_POST [ 'region' ] == '$key' ? 'selected' : '>' . $value . '</option>' ;
}
?>
</select>
</form>
</div>
<div class="select_country">
<form>
<select>
<?php
if ( $_POST [ 'region' ] == '0' ) {
foreach( $EUcountries as $key => $value ){
echo '<option value="' . $key . '">' . $value . '</option>' ; //close your tags!!
}
}
?>
</select>
</form>
</div>
<div class="print">
</div>
</div>
</body>
<html>
Last edited by bradgrafelman; 01-30-2013 at 11:42 AM .
Reason: bbcode tags modified
I don't see anything glaringly wrong, so:
Originally Posted by
bradgrafelman
can you show us the resulting output it generates?
Pedantic Curmudgeon
The only significant issue I can see is in this line:
PHP Code:
echo '<option value="' . $key . '" ' . $_POST [ 'region' ] == '$key' ? 'selected' : '>' . $value . '</option>' ;
The problem would manifest itself in the generated HTML. So yes, looking at that would be good.
Hi, thanks for the correction with my post bradgrafelman!
I fixed the issue with the help of my friend.
The issue was that line
echo '<option value="'.$key.'" '.$_POST['region'] == '$key' ? 'selected' : '>'.$value.'</option>';
I had to change it like this:
echo '<option value="'.$key.'" '.(isset($_POST['region']) && $_POST['region'] == $key ? 'selected' :'').' >'.$value.'</option>';
but not before changing the name of my form to something unique rather than it being the same as the name of my <select> tag.
Thanks alot guys!
IM SORRY!!! but in the quick reply which formatting code do i use?? i thought the 'quote' button would do it :/
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Posting Permissions
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
Forum Rules
Bookmarks