WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How configure multiple dropdown with submit button (3 posts)

  1. crokis
    Member
    Posted 9 months ago #

    Hello people.

    I hope so that somebody can help me, please.

    I configured a dropdown with a submit button.
    Code here:

    <h2><?php _e('Categories:'); ?></h2><br>
    	<form action="<?php bloginfo('url'); ?>" method="get">
    	<div>
    	<?php wp_dropdown_categories('show_option_none=Selecciona el tipo&child_of=7'); ?>
    	<?php wp_dropdown_categories('show_option_none=Selecciona el producto&child_of=6'); ?>
    	<br>
    	<input type="submit" name="submit" value="view" />
    	</div>
    	</form>

    But, just show me results of a category.

    i would like have 3 dropdown that show the child categories and work with a single submit button

    Anybody can help me, please?
    Thanks.

  2. vtxyzzy
    Member
    Posted 9 months ago #

    I did not know the name of your third category, so I created this code with two dropdowns. You should be able to add the third yourself.

    <script type="text/javascript">
    //<![CDATA[
    
       function validateForm() {
          var tipo = document.getElementById('tipo').value;
          var producto = document.getElementById('producto').value;
    
          var catForm = document.getElementById('catForm'); // retrieve form
          catForm.action = catForm.action + '?cat=' + tipo + ',' + producto; // add cat parameter
    
          var retval = true;
          retval = confirm("action=" + catForm.action);  // For testing, comment out for production
    
          return retval;
    }
    
    //]]>
    </script>
    <h2><?php _e('Categories:'); ?></h2><br>
    <form id="catForm" action="<?php bloginfo('url'); ?>" method="post"
       onSubmit="return validateForm();">
       <div>
          <?php wp_dropdown_categories('show_option_none=Selecciona el tipo&child_of=78&id=tipo&name=tipo'); ?>
          <?php wp_dropdown_categories('show_option_none=Selecciona el producto&child_of=65&id=producto&name=producto'); ?>
          <br>
          <input type="submit" id="sub" name="submit" value="view" />
       </div>
    </form>
  3. crokis
    Member
    Posted 9 months ago #

    Hello vtxyzzy.

    Thank you so much!!!! Your code really helped me a lot.
    I can see now that javascript function, did all work.

    I began work on my first theme with WP codex, therefore i learned something new with your help.

    Regards!

Reply

You must log in to post.

About this Topic