Ask coding questions

← Back to all posts
How Would I Make JS dynamically generate a link in repl,s editor?
webmunchster (7)

So in one of the websites I am developing (read: attempting to develop), you can create an article using JavaScript. So if a user wanted to create an article after the form, the JavaScript would generate a page using variables from the form. Then there is the problem of searching and (dynamically?) adding them to a list of articles. How would I do this?

Answered by heyitsmarcus (287) [earned 5 cycles]
View Answer
Commentshotnewtop
heyitsmarcus (287)

The strategy I would go with (if you're only using client side JavaScript) is to have the "pages" be just elements on the page that are styled to take up either the full view of the window (like a normal HTML page would) or whatever view you choose. So, you would create the markdown in HTML for the new "page" then append that to a new "page-like" element that you sort in some order. And when you create the "page-like" element, give it some attribute i.e. if there was an article about modern rappers it might be data-keywords="rap,rapper,rappers,famous rappers" and then aggregate those elements into a list when searching and search through each one finding matches with the keywords listed in their attribute.

If you come up with some code, we can better help you produce a satisfying result.

webmunchster (7)

@heyitsmarcus OK, thank you! I will try to implement this into my site!

heyitsmarcus (287)

@webmunchster Sweet! Here in a little bit, I'll make up a little demo so that you have a baseline to go off of for your own code!

heyitsmarcus (287)

@webmunchster Alright man, I made a little repl that shows how to use the keywords I described to you. If you have some questions, just let me know!

https://repl.it/@heyitsmarcus/Search-Dynamic-JavaScript-App

webmunchster (7)

@heyitsmarcus Thank you so much! I would have never figured this out!

heyitsmarcus (287)

@webmunchster Not a problem! I hope everything was clear in the comments so that you can use something like that in your code.

webmunchster (7)

@heyitsmarcus Yes! I was able to implement it into my site! Again, thank you so much!

heyitsmarcus (287)

@webmunchster Awesome! I'm happy to hear that! If you feel like it and have a Twitter, give me a follow on Twitter, and I can help you as best I can, and I post a lot of developer things, too. https://twitter.com/marcusaparsons