For JavaScript coders and learners | Sololearn: Learn to code for FREE!

+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...

7/8/2017 11:02:46 AM

Ledio Deda

20 Answers

New Answer

+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.

+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. :)

+8

Yep, ".innerHTML" property is enough. :) [ EDIT ] My bad, jQuery uses ".html( )" method. โ€ข http://api.jquery.com/html/

+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! ^^

+3

How do people even understand JS im havung a hard time understanding it ๐Ÿ˜ฅ

+3

I did

+3

I might take this advice....no no i WILL

+2

Well thanks a lot... I will fix it right now...

+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

+2

Thankssss... After eating lunch i will try it๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚๐Ÿ˜‚

+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 :)

+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...

+1

Ledio urime per vendin e dyte :) now, try to use Switch for each currency case

+1

@Klodian Flm๐Ÿ‘ Hidhi nje sy si duket deri tani. Me vone do mendoj per design-in. https://code.sololearn.com/W96mXpnyPtyZ/?ref=app

+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)...

+1

https://code.sololearn.com/W96mXpnyPtyZ/?ref=app

+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๐Ÿ˜…

+1

I have had difficulties when i started too. You should have some basic HTML knowledges in order to start. So just be patient...โœ‹

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...

0

Just don't give up. If you have lost all your patience, make a short break and then start again...