• Hey guys,

    I have the following situation:
    For one of my Websites I need a extended Searchform (taxonomy picking). This is my code, so far:

    <select id="hersteller" name="hersteller" onchange="showTextBox(this.value)+showcategory(this.value)">
    <option value="Hersteller">Hersteller</option>
    <?php $terms = get_terms('category');
    foreach ($terms as $term) { printf( '<option id="hersteller" class="level-0" value="%s">%s</option>', $term->slug, $term->name ); </select>
    
    <div id="modell" style="display:none">
    <select name="Modell">
    <option value="Modell">Modell</option>
    <?php $terms = get_terms('marke-<strong>HERE GOES THE SELECTED CATEGORY</strong>'); 
    
    foreach ($terms as $term) { printf( '<option class="level-0" value="%s">%s</option>', $term->slug, $term->name ); } ?>
    </select>
    </div>

    Inside get_terms(”) some javascript needs to pick the selected category name. For this I tried a function:

    get_terms('marke-'.'<script type="text/javascript">
    function showcategory(made){document.write(hersteller.options[hersteller.selectedIndex].value;
    }</script>'.'');

    It did not work at all, I tried so much more, but nothing helped. Does anyone have an idea? I am very happy about any suggestion!!

    Cheers Felix

Viewing 3 replies - 1 through 3 (of 3 total)
  • Moderator bcworkz

    (@bcworkz)

    You can’t mix javascript and PHP like that. Javascript runs on the client browser and PHP runs on your server. The two can only communicate via the HTTP connection. For what you are trying to do, you probably need to use AJAX like techniques.

    You could use javascript to select the category on the browser’s page. Then javascript sends a request to a server page, which gets the needed terms from the DB and sends the results back to javascript as a response to the request. Javascript receives this response and updates the particular HTML element as required.

    A very simple Ajax implementation, should help you to get started 😉

    Your get_terms should go inside the method process_reservation().

    Thread Starter Blaxsun

    (@blaxsun)

    Thank you very much for your help guys!
    I will try it with Ajax this weekend, let’s see how far I will get 🙂

    Cheers

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘get_terms() with javascript?’ is closed to new replies.