Jump to content

This topic is 7402 days old. Please don't post here. Open a new topic instead.

Recommended Posts

Posted

Hey,

I want a web page where users can edit existing records. I want some fields to have a drop-down list using values from a FileMaker value list as the options. I've got this much working fine. Also, if the record to be edited has a value for a particular field, I can get the option list to default to that value. For example:

echo "<select name='userTitle'>";

foreach ($userInfoValueList['valueLists']['Titles'] as $key=> $titleValue){

if ($titleValue == $userTitle){

echo "<option selected value='";

}else{

echo "<option value='";

}

echo $titleValue;

echo "'>";

echo $titleValue;

echo "</option>";

}

So if I have a record for Mr. John Doe, userTitle defaults to 'Mr.' If I have a record for Ms. Jane Doe, userTitle defaults to 'Ms.'

The problem is that if I have a record for Jane Doe (without a title specified), then on the web page it defaults to the first option in the list, resulting in Mr. Jane Doe, clearly wrong.

The only way I've been able to prevent this is to make a blank first entry in the value list so that it defaults to "". This works OK for static value lists like this. But this won't work for dynamic value lists.

So how do I get a value in a select list not to take the first option as the default when the record contains no data in FileMaker. How would I get Jane Doe to appear as Jane Doe, not Mr. Jane Doe.

I hope I haven't made this more complicated than it needs to be.

Thanks,

Dan

Posted

Try this:

echo "<select name='userTitle'>";

echo "<option value=''></option>";

foreach ($userInfoValueList['valueLists']['Titles'] as $key=> $titleValue){

if ($titleValue == $userTitle){

echo "<option selected value='";

}else{

echo "<option value='";

}

echo $titleValue;

echo "'>";

echo $titleValue;

echo "</option>";

}

All the best.

Garry

Posted

Obvious? Ha! It's obvious now that Garry's given the answer but I have to admit skipping the post because it did not occur to me, either. I was trying to wrap my noodle around the PHP part that I missed the simple hard code answer he enlightened us with...

echo "<option value=''></option>";

Doh! Yeah, obvious now.

--ST

Posted

Programming is like that!

It is always handy to have someone else to check your code. So many times I have had variable names wrong, something missing, simple procedures turn messy, and it has taken me ages to find it, whereas someone else can look at it and see it straight-away ???

All the best.

Garry

This topic is 7402 days old. Please don't post here. Open a new topic instead.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.