Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Drop Down Menu Troubles
Old 07-28-2010, 11:24 AM Drop Down Menu Troubles
brendanoshan's Avatar
Junior Talker

Posts: 3
Name: Brendan
Trades: 0
The company I work for is looking to expand their website traffic and business and become more 21st century friendly. On their website in the upcoming months, they want a drop down menu to filter their product by manufacturer, product and a search bar for product description. I put each form in a 1x3 table and am having troubles in making this work.

Here is the code I've been working with for the past few days. I've been searching the internet, looking at forums and asking people in the field directly what they think might be the problem, and so far nothing has come up.

HTML Code:
 <table border="0" width="100%">
  <tr>
    <td>Product Search by Manufacturer:<br />
    <form>
    <select name="manufacturer" style="width: 200px;">
    <option value="">Choose a Manufacturer</option>
    <option value="manufacturer.html">123</option>
   
    </select>
    </form>
    </td>
    <td>Product Search by Category:<br />
    <select name="category" style="width: 200px;">
    <option></option>
    </select>
    </td>
    <td>Product Description:<br />
    <input type="text" name="description" />
    </td>
  </tr>
</table>
Thanks for the help. It is very much appreciated.

Last edited by chrishirst; 08-01-2010 at 06:36 PM..
brendanoshan is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-28-2010, 01:38 PM Re: Drop Down Menu Troubles
Extreme Talker

Posts: 246
Trades: 0
Where is the code for the search? All I see is 2 dropdownlists and a textbox. Show us the code for the search.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 07-28-2010, 01:40 PM Re: Drop Down Menu Troubles
Extreme Talker

Posts: 246
Trades: 0
Just noticed also that 1 of the dropdownlists and the textbox are outside the form tag.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
stbuchok is offline
Reply With Quote
View Public Profile
 
Old 07-28-2010, 05:25 PM Re: Drop Down Menu Troubles
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Ideally, you would have every manufacturers in a database.
The pseudo code would be:

1) fetch a list of the furnishers in the DB
2) itterate over the list, and append <options> elements to the drop down, with the database id of the furnisher to display
3) upon form submit, redirect to a page which take this furnisher id as a parameter, and fetch from the db only products from this furnisher.

About this: you will need server side logic to realize this.
Javascript is a client side language, ie: it runs in the user browser.
The database and filtering should be done on the server side, using PHP, ASP, JSP or any other language you feel confident in.
In fact, it is doable using javascript only, but this means that every informations about every products and furnisher must be embedded into the page, and tagged to allow javascript to hide/show only relevant parts.
Not the most recommanded way of doing things.

Secondly, your HTML decalration is basically incomplete in your code up there.
Normally, a <form> element takes an "name", "action" and "method" parameter, that tells the browser where to send the form and how to encode the content. If not specified, it will send it to the current page using a GET request.
The "name" parameter is useful when you have severals forms, and you need to distinguish them, like a login and a search function in the same page.

And it needs, for each form, something to submit it's data. You cannot submit several forms at the same time.
But your form can hold any number of elements.
Your "search category" and "product description" fields being outside of your form, they won't be taken in account in the submit.

And, although you gave an html page in your select, it won't go to that page.
If you have a server side language at hand, you have to handle the submit on the page generation.

In your case, if you only have javascript at hand, you have to intercept the standard submit event, check the selected element in the drop down, and rewrite the browser location, like this:
HTML Code:
<html>
    <body>
        <script type="text/javascript">
        function redirect(){
            dd=document.frm1.manufacturer;
            if(dd.selectedIndex===0){
                alert('please choose a manufacturer');
            }
            else{
                page=dd.options[dd.selectedIndex].value;
                alert('Now going to the page '+page);
                top.location=page;
            }
        }
        </script>
        <table border="0" width="100%">
            <tr>
                <td>Product Search by Manufacturer:<br />
                    <form name="frm1" method="post">
                        <select name="manufacturer" style="width: 200px;">
                            <option value="">Choose a Manufacturer</option>
                            <option value="manufacturer_123.html">123</option>
                            <option value="manufacturer_456.html">465</option>
                            <option value="manufacturer_789.html">789</option>
                        </select>
                        <input type="button" value="filter" onclick="javascript:redirect();"/>
                    </form>
                </td>
                <td>Product Search by Category:<br />
                    <select name="category" style="width: 200px;">
                        <option></option>
                    </select>
                </td>
                <td>Product Description:<br />
                    <input type="text" name="description" />
                </td>
            </tr>
        </table>
    </body>
</html>
__________________
Only a biker knows why a dog sticks his head out the window.

Last edited by tripy; 07-28-2010 at 05:28 PM..
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Old 07-29-2010, 11:26 AM Re: Drop Down Menu Troubles
brendanoshan's Avatar
Junior Talker

Posts: 3
Name: Brendan
Trades: 0
Quote:
Originally Posted by tripy View Post
Ideally, you would have every manufacturers in a database.
The pseudo code would be:

1) fetch a list of the furnishers in the DB
2) itterate over the list, and append <options> elements to the drop down, with the database id of the furnisher to display
3) upon form submit, redirect to a page which take this furnisher id as a parameter, and fetch from the db only products from this furnisher.

About this: you will need server side logic to realize this.
Javascript is a client side language, ie: it runs in the user browser.
The database and filtering should be done on the server side, using PHP, ASP, JSP or any other language you feel confident in.
In fact, it is doable using javascript only, but this means that every informations about every products and furnisher must be embedded into the page, and tagged to allow javascript to hide/show only relevant parts.
Not the most recommanded way of doing things.

Secondly, your HTML decalration is basically incomplete in your code up there.
Normally, a <form> element takes an "name", "action" and "method" parameter, that tells the browser where to send the form and how to encode the content. If not specified, it will send it to the current page using a GET request.
The "name" parameter is useful when you have severals forms, and you need to distinguish them, like a login and a search function in the same page.

And it needs, for each form, something to submit it's data. You cannot submit several forms at the same time.
But your form can hold any number of elements.
Your "search category" and "product description" fields being outside of your form, they won't be taken in account in the submit.

And, although you gave an html page in your select, it won't go to that page.
If you have a server side language at hand, you have to handle the submit on the page generation.

In your case, if you only have javascript at hand, you have to intercept the standard submit event, check the selected element in the drop down, and rewrite the browser location, like this:
HTML Code:
<html>
    <body>
        <script type="text/javascript">
        function redirect(){
            dd=document.frm1.manufacturer;
            if(dd.selectedIndex===0){
                alert('please choose a manufacturer');
            }
            else{
                page=dd.options[dd.selectedIndex].value;
                alert('Now going to the page '+page);
                top.location=page;
            }
        }
        </script>
        <table border="0" width="100%">
            <tr>
                <td>Product Search by Manufacturer:<br />
                    <form name="frm1" method="post">
                        <select name="manufacturer" style="width: 200px;">
                            <option value="">Choose a Manufacturer</option>
                            <option value="manufacturer_123.html">123</option>
                            <option value="manufacturer_456.html">465</option>
                            <option value="manufacturer_789.html">789</option>
                        </select>
                        <input type="button" value="filter" onclick="javascript:redirect();"/>
                    </form>
                </td>
                <td>Product Search by Category:<br />
                    <select name="category" style="width: 200px;">
                        <option></option>
                    </select>
                </td>
                <td>Product Description:<br />
                    <input type="text" name="description" />
                </td>
            </tr>
        </table>
    </body>
</html>

is there anyway to get rid of the second part of the javascript without losing functionality? it works great and i appreciate the help and quickness of the response, but i don't like that alert box that tells the person where they are going
brendanoshan is offline
Reply With Quote
View Public Profile
 
Old 07-29-2010, 11:34 AM Re: Drop Down Menu Troubles
brendanoshan's Avatar
Junior Talker

Posts: 3
Name: Brendan
Trades: 0
@tripy:

i'm also trying to add in another drop down menu without having the one before it be activated.

does that make any sense?
brendanoshan is offline
Reply With Quote
View Public Profile
 
Old 07-29-2010, 03:20 PM Re: Drop Down Menu Troubles
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
Quote:
but i don't like that alert box that tells the person where they are going
remove the alert statement.

Quote:
i'm also trying to add in another drop down menu without having the one before it be activated.

does that make any sense?
Right now, I don't see what you mean
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Drop Down Menu Troubles
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27021 seconds with 12 queries