Link to home
Start Free TrialLog in
Avatar of yuhannl
yuhannl

asked on

Refresh page based on selected options without using submit()

I'm currently building a webpage which allows people to enter information as well as selecting categories which the piece of information belongs to.

The category selection is based on 2 select drop down list. First one loads from DB, and after the user selected an option, the 2nd one then gets loaded. However, at this stage I'm only able to achieve this by using onChange="submit();" to get the 2nd list to reload. In the mean time, all information on the rest of the form needs to be retained.

I've copied the code for the 2 drop down lists here:

<select onChange="submit();" name="domain" id="domain" size="1">
<?
      for ($i = 0; $i < count($domain_list1); $i ++) {
            echo "<option value=\"".$domain_list1[$i]['id']."\"";
            if ($_POST['domain'] == $domain_list1[$i]['id']) {
                  echo "SELECTED";
            }
            echo ">";
            echo $domain_list1[$i]['name'];
            echo "</option>";
      }
?>
</select>

<select name="category" size="1" <?
if ($category_list1 == null || count($category_list1) == 0 ) {
      echo "Disabled>";
} else {
      echo ">";
      for ($i = 0; $i < count($category_list1); $i ++) {
            echo "<option value=\"".$category_list1[$i]['id']."\"";
            if ($_POST['category'] == $category_list1[$i]['id']) {
                  echo "SELECTED";
            }
            echo ">";
            echo $category_list1[$i]['name'];
            echo "</option>";
      }                                                                              
}
?>
</select>

What I'm concerned as that because I'm utilising the submit() function to reload the page (and populating 2nd list), it'd be hard to differenciate whether I'm just reloading the list, or whether I'm really submitting the form.

Has anyone got ways to achieve
1. Load the 2nd dropdown list based on first one's selection
2. Still retain the rest of info on the page


I'm using PHP / MYSQL / and some Javascript on the page too.
ASKER CERTIFIED SOLUTION
Avatar of bugs021997
bugs021997
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of yuhannl
yuhannl

ASKER

Thanks guys!
I had to award more points to bug as he responded quickly even though others have provided me with samples & codes.

I did however got to the sites he suggested and done coding by following the instructions.

Thanks to you all, and all the best.