Current location: Hot Scripts Forums » Programming Languages » PHP » select combobox value?


select combobox value?

Reply
  #1 (permalink)  
Old 05-19-05, 08:09 PM
lordy lordy is offline
Newbie Coder
 
Join Date: May 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
select combobox value?

Hi all,

I'm currently fumbling my way through php, I've become stuck on what I _believe_ is quite a simple matter.

I currently have populated a combobox (location) with values from a table like so:

-->select id="location" name="location"><?php $editprop->Move(0);while ( !$editprop->EOF ) { echo "<option value=\"" . $editprop->fields["suburb"] . "\">" . $editprop->fields["suburb"]. "</option>";$editprop->MoveNext(); } ?></select>

now that that is done, I want to get the value of a specific record from the table and have that as the default selected suburb.

I was hoping this would do the trick:

<option SELECTED value=\"" . $editprop->fields["location"] . "\">" . $editprop->fields["location"]. "</option>

Now, looking at it, I think it would add the value onto the current combobox list, is that correct? I don't actually want that to happen, I just want to get the value and select it (the value would already be in the combobox from the former statement)

So not only do I not know how to do specifically what I want, but this way doesn't work either, I get an error message:

Parse error: parse error, unexpected T_STRING, expecting ']' in /var/www/html/tester.php on line 151

I believe this to be because of simple placement of the two statements. I put the latter statement directly after the first so in all, it looks like this:

--><select id="location" name="location"><?php $editprop->Move(0);while ( !$editprop->EOF ) { echo "<option value=\"" . $editprop->fields["suburb"] . "\">" . $editprop->fields["suburb"]. "</option>";$editprop->MoveNext(); } ?></select><option SELECTED value=\"" . $editprop->fields["location"] . "\">" . $editprop->fields["location"]. "</option>

Note:
I also tried putting the second option statement within the select tags, after the "?>" just before "</select>". This also produced the same error. What am I missing?

So my questions:
How do I get the value and select it from the list?
Where do I place the statement to do that?

If anyone could help that would be great, I have been at this off and on for the past couple of days and all I have managed so far is failure after failure

Any ideas?

Thanks
lordy

Last edited by lordy; 05-19-05 at 08:13 PM.
Reply With Quote
  #2 (permalink)  
Old 05-22-05, 08:06 PM
lordy lordy is offline
Newbie Coder
 
Join Date: May 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
not to bump this or anything, but does anyone know what i mean? am I not being clear enough?
Reply With Quote
  #3 (permalink)  
Old 05-23-05, 03:05 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
show us line 151!
and to access the selected elemented from the dropdown menu you simply have to use $_POST['name_of_select']
so if you had:
Code:
<select name="location" size="1">
  <option></option>
  ....
</select>
you will use $_POST['location'] to access the value after the form has been submitted.
Reply With Quote
  #4 (permalink)  
Old 05-24-05, 10:47 PM
lordy lordy is offline
Newbie Coder
 
Join Date: May 2005
Posts: 40
Thanks: 0
Thanked 0 Times in 0 Posts
I'm sorry, either I have misunderstood you or you have misunderstood me.

I don't actually need to get the value after the form has been submitted. What I need is to make the combobox have the value of "location" from my $editprop query set as default.

But I also need to have the values from "suburb" from my $editprop query to be displayed as other options in the combobox.

The problem is that if I just add them all, a suburb will appear twice. I want to be able to make sure the suburb only appears once. "location" is selected from one of the "suburb" values normally, so that's why a value will appear twice.

I'm assuming there is a way to compare values and make it so I don't add one, but how would I do that? Just a hint would do if you don't want to think about it

That way I could go and read up a little on it.

Thanks!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
SELECT DISTINCT Problem ozwald PHP 5 05-01-05 07:02 PM
Multiple Select phppick JavaScript 3 04-11-05 12:09 AM
Select List insert into DB The Omega JavaScript 1 01-12-05 12:51 PM
Problem with date in combobox. Periodically lose valu Danie Visual Basic 1 03-04-04 02:41 PM
i have 3 select box this is urgent traceMe JavaScript 0 12-02-03 01:24 AM


All times are GMT -5. The time now is 06:45 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.