pjc2003 Posted January 9, 2007 Share Posted January 9, 2007 hi ive got a select box that gives a value to variable $location_id<select name="location_id"> <option =1 <?php if ($location_id = 1) echo ' selected '?> >Location A</option> <option =2 <?php if ($location_id = 2) echo ' selected '?> >Location B</option> <option =3 <?php if ($location_id = 3) echo ' selected '?> >Location C</option> <option =4 <?php if ($location_id = 4) echo ' selected '?> >Location D</option></select>Ok what i want to do is have the select box display the option "location x" etc ... all the way from A - Z which I can do fine BUT I want the location_id variable to hold its corresponding number! But no matter what I try the variable stores the value of what is actually displayed in the select box...Please help me!pj Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 9, 2007 Share Posted January 9, 2007 The comparison operater is "==" not "=".You also need to write correct HTML if you expect your forms to work:[code]<?php$location_id = 0;if(isset($_POST['submit'])) { echo '<pre>' . print_r($_POST,true) . '</pre>'; $location_id = $_POST['location_id'];}?><form method="post"><select name="location_id"> <option value="1" <?php if ($location_id == 1) echo ' selected '?> >Location A</option> <option value="2" <?php if ($location_id == 2) echo ' selected '?> >Location B</option> <option value="3" <?php if ($location_id == 3) echo ' selected '?> >Location C</option> <option value="4" <?php if ($location_id == 4) echo ' selected '?> >Location D</option></select><br><input name="submit" value="Do Test" type="submit"></form>[/code]Ken Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.