Pre Chosen option in Dropdown

weiseren 02 Oct, 2009
I am using a chronoform where users see a page of cars, and each car "card" has a button linking to the same form on a seperate page.

Is it possible to make a certain selection in the drop down, (or by using f.x. radio buttons) chosen. Example: so my user clicks the link from the Ford Fiesta card, is guided to the form, now i want the form to show the ford fiesta as chosen


hope i have been clear


br
Kasper
GreyHead 02 Oct, 2009
Hi Kasper,

Yes, it's certainly possible.

You'll need to get the id of the car / item from the link url and then use this to add checked='checked' to the checkbox or radio button (or selected='selected' for a drop-down)

Bob
weiseren 03 Oct, 2009
@Bob

Thanks for your reply - I am trying to understand🙂 its probably easier if is show you a URL
http://dyt-dyt.dk/lej-minibus.html

Then if you click the red button you will be directed to the form.

My questionface-meh-blank is how do i set an id for the car, (or find it, as it is not something i have done i have thrown them all on one article page, do i need to make subpages for the cars?)

And then secondly do i then add selected='selected' to the URL? So it ends up looking something like:
http://dyt-dyt.dk/lej-minibus/8.htmlselected='8'
GreyHead 03 Oct, 2009
Hi Kasper,

You already have the id in the url http://dyt-dyt.dk/lej-minibus/7.html it's the 7 in there.

In the non-sef url it will be something like id=7

You need to check this in the Form HTML, then add selected='selected' to the corresponding option in the drop-down.

It would help if the value of the options matched the id that you are using on the other page - as it doens't you'll need to look it up somewhere - either by creating an array of the values or by using a db table. An array if Ok if the list is short and more or less fixed, a table is better if the list is long or changes a lot.

Bob
weiseren 03 Oct, 2009
@bob

Hope you are not losing your patience with me🙂

I am looking in the html of the form:

<select id="1" class="cf_inputbox validate-selection" name="personbiltype" title="" size="1">
<option value="">Vælg én...</option>
<option value="Fiat 500 Diesel">Fiat 500 Diesel</option>


I have the fiat 500 which has the id=15 - where would i need to implement the selected='selected' - i tried doing it in the form wizard. Where would I find the form html located so i could add these different selected tags...

and when that is done - will creating a simple link from the fiat 500 (which has the id=15) page to the form be recognized by the form and automatically bring up the fiat 500 selection.

Cheers!
Mizpah 03 Oct, 2009
Hi weiseren,

I dont know how much PHP you know so this may not help much, however you may be able to adapt somthing from this code:


<div class="form_element cf_dropdown">
    <label for="status" class="cf_label" style="width: 150px;">Status</label>
    <select class="cf_inputbox validate-selection" id="status" size="1" tabindex="3" name="status">
      <option value='' >--?--</option>
<?php
$options = array('forsale' => 'For Sale', 'sold' => 'Sold', 'archive' => 'Delete');
foreach ( $options as $k => $v ) {
  if ( $result->status == $k ) {
    $selected = "selected='selected'";
  } else {
    $selected = "";
  }
  echo "<option value='$k' $selected >$v</option>";
}
?>
    </select>
  </div>



Note that in the case above, the value defaulted to a returned value from the database for an existing record , you could however do somthing like:
$id = JRequest::getInt('id', '', 'get'); to get the id from the url and make it a usable value in php (probably replace $result->status == with the reult of the $var ) to give you your default, then populate the array with the other possibilities - please note however I am no expert here, and there may well be an easier way of doing this for your purposes!
weiseren 08 Oct, 2009
thanks for the responses🙂

It seems to be a bigger challenge than i hoped for...😟

Thought there may have been a quick solution - but since im not a genius at code then it will be too strenuous.


Cheers.
GreyHead 08 Oct, 2009
Hi Kasper,

You don't need to be agenius but it really does help to have some moderate PHP skills to start doing more complex things with your forms. Perhaps you can find someone to do this for you, the code Mizpah posted will only need a little adjusting.

Bob
This topic is locked and no more replies can be posted.