ejs string variable with space is not displayed properly

I am trying to display the search query in the search bar in HTML. But if the variable includes a space, the webpage is only going to display the first word.

Here is the code

app.get('/search', function(req, res) {
    console.log(req.originalUrl,'oro')
    console.log(req.query['search_query'],'aaaaaaa')
    res.render('search.ejs', {
        user : req.user, 
        query : req.query['search_query']
    });
});

Here is the html code

<form action="/search" method="get">
    <div class="form-group">
        <input type="submit" class="btn btn-warning btn-lg" value = "search" style = "float: right"/>
        <div style="overflow: hidden; padding-right: .5em;">
        <input type="text" value = <%= query %> class="form-control" name="search_query" style = "width:100%;"/>
        </div>
    </div>
</form>

query is the variable collected from the last webpage and passed to /search.

If I type in "I want to find xx", the webpage will only display "I" in the search box. However, in the console, the printout result is the full query " I want to find xx". The corresponding url is also correct "/search?search_query=I+want+to+find+xx".

Anyone has an idea? Thanks a lot!

Let's start with correcting your HTML, by using quotes in value:

<input type="text" value = "<%= query %>" class="form-control" name="search_query" style = "width:100%;"/>

Here under IE you should see a large error, on FF and Chrome browser will try to save the situation and catch only the first word.

Prolably rest of your words are used as attributes and ignored in this input.