Reputation: 411
I have a running application (accessible at www.anelmad.com).It's a bilingual dictionary.
I want to implement this feature: when a word like "axxam" is entered, the dictionary will display the feminine form of this word, which is "taxxamt". I want this feminine word to be a link, so that if the user clicks on it, it displays the meaning of that word in english.
I coded the feature in my ejs file, but when I click on the link it displays: TypeError: Cannot read property 'toLowerCase' of undefined
Here are the main parts of the application:
app.js:
app.get('/', function(req, res) {res.render('index')});
app.get('/searching', function(req, res, next){
var val = req.query.search;
var options= req.query.lang;
val = val.toLowerCase().trim();
var str;
display.ejs: this is the line where I transform the feminine word into an href link:
<%= grammatical[j].pos%></i>: (<i>unti:</i> <a href="/searching"><%=
feminine %></a>,
asget:<%= grammatical[j].pl%>
Finally, to test that the clicked link returns a string, I put an alert() in main.js file:
$(function(){
$("a").click(function(event) {
var href = $(this).text();
alert(href);
I tried the solutions given in the other threads on SO without any success so far: I tried :
val= val.toString().toLowerCase().trim()
val= val.toString.toLowerCase().trim()
JSON.stringify(feminine)
In the end, what I want is to send the word (in the href link) as an input to the route: /searching.
Upvotes: 1
Views: 1643
Reputation: 321
"cannot read property "..." of undefined generally means the variable on which you are calling the method is null or undefined, in your case req.query.search. Try putting a breakpoint after the assignment to verify that val is not null
Upvotes: 1