Html dropdown with three possibilities

This replaces my earlier post (Html select menu).

I have been trying to fix the following for several weeks, with no success, and hope someone can help.

I have four html input boxes:

            <input name="search-input" type="text" id="name" placeholder="taxon name" data-key="taxon" />
            <input name="search-input" type="text" id="strain" placeholder="strain" data-key="strain" />
            <input name="search-input" type="text" id="accession" placeholder="accession" data-key="accession" />
            <input name="search-input" type="text" id="length" placeholder="length" data-key="length" />
an html select menu:
            <label>
                Please Choose a search criteria
                <select class="length-dropdown">
                    <option value="exact value">exact value</option>
                    <option value="greater than">greater than</option>
                    <option value="less than">less than</option>
                </select>
            </label>

and an html table:
{ taxon: “Alice Johnson”, strain: “AB”, accession: “XY”, length: 370 },
{ taxon: “Bob Smith”, strain: “CD”, accession: “XY”, length: 350 },
{ taxon: “Carol Davis”, strain: “EF”, accession: “GH”, length: 470 },
{ taxon: “David Wilson”, strain: “AB”, accession: “IJ”, length: 460 },
{ taxon: “Eve Martinez”, strain: “GH”, accession: “KL”, length: 300 },
{ taxon: “Frank Brown”, strain: “IJ”, accession: “MN”, length: 360 },

selecting ‘less than’ in the select menu and ‘360’ in the length input box correctly returns the rows containing ‘350’ and ‘300’. However, data are not always available for some rows. If a length value is changed to “”, the row is still found (treated as less than 360); alphabetic characters like ‘n/a’ or ‘-’, or a blank value, prevent the table from loading.
I add here the code that deals with the select box:

function validateSize(sizeValue, userSize) {
    if (userSize === 0) return true;

    const searchCriteria = criteriaMenu.value;
    switch (searchCriteria) {
        case ("greater than"): {
            return sizeValue > userSize;
        }
        case ("less than"): {
            return sizeValue < userSize;
        }
        default: {
            return sizeValue === userSize;
        }
    }
}

How can I work with missing data?

If the length input field should always accept a number, then maybe instead of type text, it should be type number?

1 Like

please do not open multiple topics for the same question. This time I will unlist the other topic for you, but please keep in mind the rule of one project/step/challenge = 1 topic on the forum

1 Like

Thanks for being so kind, and for putting me straight on the rules.
I wanted to delete the other topic, but could not do so.
Thanks again.

1 Like

That won’t solve the issue, since the main problem lies in the text values within the table itself.

Okay. Then maybe you should filter out those rows as you search? (By checking if the specific field contains the correct type of value?)

That is exactly what is needed - but how to do it?

I am not sure what you mean by how?
It is just code that you would add?

Your other thread starts on Jul 6, so you’ve actually been working on this for over 2 months. Your other thread was closed because you ended up having someone do the coding for you and then just copying their solution.

Can you please explain how is this thread is any different than the thread that was closed? Why shouldn’t this thread be closed as well?

Yes, given that the rows containing “” appear in the ‘less than’ results, those rows should be filtered out. Probably, the only way to do this is to add, or modify the existing, code

1 Like

so where would you start in adding this feature? what part of the code deals with searching and filtering?

I am surprised to see from your post that my other thread started so long ago, I need to change ‘several weeks’ to ‘several months’!

The current thread differs from the other in addressing a SPECIFIC issue, rather than a more global one. As such, it should not be closed.

The feature could either be integrated into the size dropdown, or dealt with in the code. I posted the part of the code dealing with this already. A small modification may do it; I have been trying, without success. The essential is to filter out all rows containing the blank values (“”).

show what you have tried

if you have opened this to have others write the code for you, it will be closed. Show your attempts, do not ask for code to be written.

OK, I will show what I tried as soon as I can. At the moment, I am writing from MS windows, since the linux system containing the code became corrupted. It may take several days to fix.

I disagree. This is simply a continuation of the same problem.

I’ve gone through the previous thread:

https://forum.freecodecamp.org/t/how-to-select-values-greater-or-less-than-a-search-value-in-an-html-table/699256

And based on these comments:

And lines of code like this:

var match4 = return Number(cells[3].innerText.toLowerCase()) = Number(length);

Frankly, if you are writing this line of code, I don’t see how you could have written the rest of this code that you brought to the forum. I think you are trying to get the forum to modify someone else’s code for you.

I feel that you may not have a good enough grasp of JS and programming in order to complete this project or understand the advice that people are giving you. I would suggest learning basic JS from the beginning and getting a better understanding of the fundamentals.

I would suggest that you start with either HTML or JS:
https://www.freecodecamp.org/learn/2022/responsive-web-design/

https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/

This thread is like you are trying to learn programming from a forum thread of this specific project. And/or trying to convince people to write code for you by continually saying “I don’t understand, I’m lost”

Are you trying to learn to code?

1 Like

Thanks for your detailed reply. Unfortunately, you are mixing-up the threads. Your comments refer to the thread ’ how-to-select-values-greater-or-less-than-a-search-value-in-an-html-table/699256’ which you closed, whereas the help currently needed with the code is discussed in the thread ’ Html dropdown with three possibilities’.

no, pkdvalis is not mixing up the threads, these are valid concerns which I notice you did not answer at all.

if you are interested in learning to code, this is a good place. If you want other people to want the code for you, this is not the place.

1 Like

OK, all you lot do is nitpick and confuse the issue further.

Close all threads, I am finished with freeCodeCamp and will post to Quora.

1 Like