1

I've got a dropdown and I need to put values in there that need to be escaped with javascript.

The reason why I want to use javascript is because the api I query is working with javascript and don't receive the other ways to escape quotes.

Exemple of dropdown value : "ToxKeywords:"genotoxicity" AND ToxKeywords:"ames" OR ToxKeywords:"micronucleus""

So i got this dropdown :

<form method="post" name="query">
    <label for="textQuery">Choose Query from list</label>
    <select class="form-control space" name="textQuery" id="textQuery">
        <option selected disabled>Choose here</option>
        <option value="ToxKeywords:">ToxKeywords</option>
        <option value="Molecules.Main_name:">Molecule</option>
        <option value="Query1">Query 1</option>
        <option value=ToxKeywords:systemic toxicity>Query 2</option>
        <option value=ToxKeywords:"phototoxicity">Query 3</option>
        <option value=ToxKeywords:"llna">Query 4</option>
    </select>

And i want to replace for exemple value="Query1" with javascript. I tried this :

<script>
    document.getElementById("textQuery").selectedindex = "Query 1"
    select.option.value = "ToxKeywords:\"genotoxicity\" AND ToxKeywords:\"ames\" OR ToxKeywords:\"micronucleus\"";
</script>

Apparently i can select the right value but i don't know how to change it to : "ToxKeywords:\"genotoxicity\" AND ToxKeywords:\"ames\" OR ToxKeywords:\"micronucleus\""

Can you help me to find the right Javascript syntax ?

1 Answer 1

1

You can use: document.querySelector(selectors);:

document.querySelector('#textQuery option[value="Query1"]').value =
           'http://130.88.150.30:8983/solr/NCSTOX/select?indent=on&q=Tox‌​Keywords:%22genotoxi‌​city%22%20AND%20ToxK‌​eywords:%22ames%22%2‌​0OR%20ToxKeywords:%2‌​2micronucleus%22&wt=‌​json and i got : http://130.88.150.30:8983/solr/NCSTOX/select?indent=on&amp;q‌​=ToxKeywords:&quot;g‌​enotoxicity&quot; AND ToxKeywords:&quot;ames&quot; OR ToxKeywords:&quot;micronucleus&quot;&amp;rows=10&amp;wt=json';
            
document.getElementById('textQuery').addEventListener('change', function(e) {
  console.log(this.value);
})
<form method="post" name="query">
    <label for="textQuery">Choose Query from list</label>
    <select class="form-control space" name="textQuery" id="textQuery">
        <option selected disabled>Choose here</option>
        <option value="ToxKeywords:">ToxKeywords</option>
        <option value="Molecules.Main_name:">Molecule</option>
        <option value="Query1">Query 1</option>
        <option value=ToxKeywords:systemic toxicity>Query 2</option>
        <option value=ToxKeywords:"phototoxicity">Query 3</option>
        <option value=ToxKeywords:"llna">Query 4</option>
    </select>
</form>

Sign up to request clarification or add additional context in comments.

2 Comments

Thank you your code is good so i valid it but i doesn't solve my problem as the html query should be http://130.88.150.30:8983/solr/NCSTOX/select?indent=on&q=ToxKeywords:%22genotoxicity%22%20AND%20ToxKeywords:%22ames%22%20OR%20ToxKeywords:%22micronucleus%22&wt=json and i got : http://130.88.150.30:8983/solr/NCSTOX/select?indent=on&amp;q=ToxKeywords:&quot;genotoxicity&quot; AND ToxKeywords:&quot;ames&quot; OR ToxKeywords:&quot;micronucleus&quot;&amp;rows=10&amp;wt=json
I found it. It was document.querySelector('#textQuery option[value="Query1"]').value ='ToxKeywords:%22genotoxicity%22%20AND%20ToxKeywords:%22ames%22%20OR%20ToxKeywords:%22micronucleus%22'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.