If/else dilemma

if/else is not as easy as a I thought. I’m trying to have values concatenated then converted to a product number. Nothing I do seems to work;

var x = document.getElementById(“subjects”).value;
document.getElementById(“demo6”).innerHTML = x;

var x2 = document.getElementById("subjecta").value;
document.getElementById("demo5").innerHTML = x2;


var y = hypeDocument.getElementById('text').innerHTML;
var y2 = hypeDocument.getElementById('text2').innerHTML;
var z = hypeDocument.getElementById('demo4').innerHTML;
var x = document.getElementById("subjects").value;
//document.getElementById("demo").innerHTML = x;

var res = x.concat(y, x2, y2, z);
document.getElementById("demo").innerHTML = res;

if (document.getElementById(“demo”).innerHTML == 44999944) {
document.getElementById(“demo8”) = 5;
}

When you select “Maple” and “4mm”, “44999944” is in demo, when calculate button is clicked. But no value is in demo8 box.

Any help is appreciated.

thanks,

Hi Randy, I think you meant to share a document? Hard to tell what you’re trying to do.

configure.hype.zip (347.0 KB)
Here is the hype file.

Sorry!

Randy

Where is the code for demo8 and how is it being called.

I do not see

if (document.getElementById("demo").innerHTML == 44999944) {
document.getElementById("demo8") = 5;
}

Giving us a project like this is not very helpful if you do not explain what the work flow is of the buttons an functions. Pleas go into detail.

I’ll go a little further. Sorry again.

Randy

Just cruisin' through... no elaborate analysis ;->
Wouldn't You want "innerHTML" in order to display the value in the demo8 box? e.g.

document.getElementById("demo8").innerHTML = 5;

1 Like

I’m trying to create a “Product Calculator”. The user will choose several different options, each option chosen will have a value that is concatenated when the “Calculate button” is pressed. The concatenated number will be converted to a product number depending on the options chosen. Product pictures or even a scene change will appear/take place to show the product. I’m trying to accomplish this by using if/else. My expertise is very limited, however, I thought this would be easier than it actually is. (Surprise!) I’ve tried almost all combinations I can think of but nothing seems to work. I"m sure I’m leaving out something important. Using Arrays may even be easier/better for this. Not sure. Opinions? I’ve done this before in Flash, but it’s a lot tougher to use/make changes etc. and limited to Windows and use of a flash player. I LOVE the idea of using Hype for all of these product type calculators and presentations. I can use on all devices! I’m trying to get the guts working on the basic calculators before I move on to animation and other information. This is the toughest. Any help would be greatly appreciated. I’m so glad I found Hype! I’m uploading what I have so far. The “calculate” function is what I’m concerned with for now. Let me know if I need to give more information.
TestingCopy.hype.zip (310.6 KB)

I will be honest, even looking at the second posted project I see a jumbled mess. :dizzy_face:
It looks like you are just copying and pasting code with no real understanding of what you are putting together.
This is the main problem you are having. What you have is code that does not make sense and will never do what you want unless you gain a little bit of understanding.

I do have a working modal but to be honest I think you should first have a look at

Then start over again.

With just a little bit of using the resources ( online stuff ) in the link above you will see why what you have will never work and the code you need is not very complicated.

1 Like

Lol! I do copy and paste. I’ve taken a couple online courses but every time I try to put it to practical use, it doesn’t work. I’ll try the one above and see what happens. I’ll also keep pounding the code I have. Eventually, logic kicks in and I do get a solution. I think I’m better off sticking to graphics. Thanks for helping.

Randy

2 Likes

Hi Randy!

I admire your candor… at least You gave it a go - in the deep end with no swimming lessons! :dolphin:

A book that really helped me get a grip on the general concepts of JavaScript is: “JavaScript & jQuery: The Missing Manual” (Amazon has used versions for around $21)

Even if You are not interested in learning jQuery (a JavaScript library) - the introduction to JavaScript itself is excellent and worth the price of admission just for those parts of the book. There are also additional sections on strategies of efficient~best practices Javascript coding. A very succinct informative read that does not overwhelm You with detail and in lucid terms goes into the vocabulary, syntax & grammar of JavaScript.

The book in general is aimed at designers not gearheads.

There are an abundance of useful examples that are well annotated; with none of the sort of thing that can sometimes crop up in these types of introductory books: “Why did they do that?!!” (No explanation they just did it and You have no idea why.) In “JavaScript & jQuery: The Missing Manual” I can’t recall this frustrating situation ever happening.

This book quickly got me to the point of understanding some of the more involved posts on this (and other) Forum(s). I could also do my own additional research without feeling lost~overwhelmed.

Highly recommended!

p.s. I think jQuery is an excellent library to learn - consider it a bonus part of the book.

3 Likes

thanks Jim!
I did figure out my problem. But I still don’t understand it. I have a lifetime membership on Sitepoint. That’s a great tool for just about anything. Now I’m working on a new problem. thanks, I’ll look into the book too!
Randy

1 Like

Thanks for pushing me. I’m glad you did. I’ve been learning every day and night since then. But I did work out my problem. Of course i have 10 more now. lol. I’m still learning and searching. My problem is that I’m a graphic artist and that’s what i do most. Like with any language you can’t learn if you don’t practice it every day. I spend a lot of time with the graphics and not enough time with the languages. But thanks for helping and I changed your stepper graphically to work for what I was doing. I’ll upload that for you that take a look at. And I’m stuck with it also. I need to have the value from the stepper added to the other numbers. Back to the drawing board!

thanks,

randy

1 Like

Glad to hear you are doing well with it.

The numbers you are getting are actually of a Type String.

Strings can be concatenated by using a plus symbol between each String.

example.

“4” + “4” will return “44”

There is more to this but simply because they are strings the plus symbol concatenates rather than adds mathematically.

Have a look at this page which explains some of how the operators work

Thanks Mark,

I’m getting exactly what I want now except for 1 thing. Is there a way to stop the stepper at 22.5?
I’m concatenating the numbers to convert to a product number. That’s working also. I’ll upload later today to let you test. Thank you for your help. I’m still studying though. I have to go back through some of this 2 or 3 times to catch on. thanks!
Randy