For JavaScript coders and learners | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

For JavaScript coders and learners

I want to create an exchange webpage, but a problem is standing on my way. I want to use the if condition (true if an event function is true), but i don't know how to write that condition. I mean (take a look at the code) if the user selects euro in the"your currency" i want to execute the multiplication with 1.14. Can anyone help?? https://code.sololearn.com/WjkzUXP2iW7F/?ref=app Take a closer look at lines 11-17 and 33-37...

8th Jul 2017, 11:02 AM
Ledio Deda
Ledio Deda - avatar
20 Answers
+ 9
One of the many possible ways (without unnecessary conditions) could be: // click on the "euro" tab $('#euro2').click(function(){ // alert the value * 1.14 alert( $('#inputi').val() * 1.14 ) }) Place it inside this function: $(function() { $("#item2").click(function() { $("#submenu2").slideToggle(500); }); }); Final code: // when you click on the "convert tab" $(function() { // show me the tabs $("#item2").click(function() { $("#submenu2").slideToggle(500); }); // if you click on the "euro tab" $('#euro2').click(function(){ // make your calculations alert( $('#inputi').val() * 1.14) }) }); Tip: Your code is highly confuse, put all that stuff in a single tab, i had to search 1/2mins the HTML elements to make it.
8th Jul 2017, 11:20 AM
Maz
Maz - avatar
+ 8
Hope it helps, there are anyway different ways to do the same thing. Good luck, i'll wait the final code because it seems interesting. :)
8th Jul 2017, 11:25 AM
Maz
Maz - avatar
+ 8
Yep, ".innerHTML" property is enough. :) [ EDIT ] My bad, jQuery uses ".html( )" method. • http://api.jquery.com/html/
8th Jul 2017, 11:28 AM
Maz
Maz - avatar
+ 8
Ledio i really like the CSS layout, the converter with all the tabs should be closed only when you click on "Your Currency", should be easy to do, you can make a "click listener" everywhere in this case! Keep it up! ^^
8th Jul 2017, 2:59 PM
Maz
Maz - avatar
+ 3
How do people even understand JS im havung a hard time understanding it 😥
9th Jul 2017, 6:50 AM
Krieg7
Krieg7 - avatar
+ 3
I did
9th Jul 2017, 7:02 AM
Krieg7
Krieg7 - avatar
+ 3
I might take this advice....no no i WILL
9th Jul 2017, 7:15 AM
Krieg7
Krieg7 - avatar
+ 2
Well thanks a lot... I will fix it right now...
8th Jul 2017, 11:25 AM
Ledio Deda
Ledio Deda - avatar
+ 2
What if i dont want to alert the result, but just put it into the div with id output, I should use inner.html?? Hope i was clear
8th Jul 2017, 11:27 AM
Ledio Deda
Ledio Deda - avatar
+ 2
Thankssss... After eating lunch i will try it😂😂😂😂
8th Jul 2017, 11:28 AM
Ledio Deda
Ledio Deda - avatar
+ 2
It was very interesting what you did :) but I wanted to illustrate my point of view by pointing out some things to consider like having the code clean with as few functions as possible and the other thing is that you must not confuse the elements. Menu is not for drop down and when using jQuery don't use getElementById etc... but the end result is that you have to keep practicing. So I just did a sample program ---> https://code.sololearn.com/WWkG5hrR2yP6/#html enjoy :)
8th Jul 2017, 4:22 PM
Klodian Lula
Klodian Lula - avatar
+ 2
Well it is much better than mine... In general that was my idea, but I couldn't make it. At least I understand the improved code (I mean this is something)... I have undoubtly learnt a lot from this.. Thanks a lot to both of youu...
8th Jul 2017, 6:18 PM
Ledio Deda
Ledio Deda - avatar
+ 1
Ledio urime per vendin e dyte :) now, try to use Switch for each currency case
8th Jul 2017, 2:07 PM
Klodian Lula
Klodian Lula - avatar
+ 1
@Klodian Flm👍 Hidhi nje sy si duket deri tani. Me vone do mendoj per design-in. https://code.sololearn.com/W96mXpnyPtyZ/?ref=app
8th Jul 2017, 2:50 PM
Ledio Deda
Ledio Deda - avatar
+ 1
@Maz Would you mind taking a look at what I've done so far?? (Don't judge me about the design, i will think about it later)...
8th Jul 2017, 2:51 PM
Ledio Deda
Ledio Deda - avatar
8th Jul 2017, 2:52 PM
Ledio Deda
Ledio Deda - avatar
+ 1
I understand. It was like this, but i thought if the user has the subitem opened after he writes in the input box, he won't have to click the currency twice. However i think you are right...👍 Thanks for being able to hear all my blablabla😂 and helping me with all this. Promise I won't disturb you anymore😅
8th Jul 2017, 3:14 PM
Ledio Deda
Ledio Deda - avatar
+ 1
I have had difficulties when i started too. You should have some basic HTML knowledges in order to start. So just be patient...✋
9th Jul 2017, 7:01 AM
Ledio Deda
Ledio Deda - avatar
0
Well when i started JS i had already finished C++. All programming languaged are similar so it wasnt so bad as you... Try to repeat lessons and make some practice coding...
9th Jul 2017, 7:05 AM
Ledio Deda
Ledio Deda - avatar
0
Just don't give up. If you have lost all your patience, make a short break and then start again...
9th Jul 2017, 7:17 AM
Ledio Deda
Ledio Deda - avatar