TO semi-colon or not to semi-colon, that is the question

Having a dog of a time trying to get two code blocks to work together. Doing the first one (as shown) works fine but when I do the second one, it just doesn’t work, and I’m sure I have y end of code block thingy’s wrong. Can you explain when and when not to put the end of code semicolon and how many times?

For example, I’ve see }); and sometimes I’ve seen }) and sometimes I’ve seen them twice and sometimes only once.

Here’s what I have… (using one or the other independently works, but never both.)

$w.onReady( function () {
//TODO: write your page related code here…

// This is the CURRENTLY IN OR VETERAN STATUS line
$w.onReady( function (){
$w(“#vectorImage14”).hide()
$w(“#dropdown5”).hide()
$w(“#text79”).hide()

// This is the ANNUAL OR LIEFTIME line
$w.onReady( function (){
$w(“#dropdown6”).hide()

})
});

//next function: ITEM1 2 3 make these three items hidden above appear when radiobutton3 === YES is selected
$w(“#radioGroup3”).onChange( function () {
if ($w(“#radioGroup3”).value === “responseyes”)
$w(“#vectorImage14”).show()
$w(“#text79”).show()
$w(“#dropdown5”).show()
})
});

//next function: these two items SHOW when LIFETIME radio button is pressed
$sw(“#radioGroup6”) onChange(function() }
$sw(“#vectorimage18”).show()
$sw(“#dropdown7”).show()
}};
});

You need the semi colons in your code, as shown in the API reference for the show and hide functions and in code examples too.
https://www.wix.com/corvid/reference/$w.HiddenMixin.html
https://support.wix.com/en/article/corvid-tutorial-hiding-an-element-on-certain-pages

Some will say that they are optional and you don’t need to use them, however it is always best to do so when they are needed, have a read of these for example.
https://code.likeagirl.io/why-the-heck-do-i-need-to-use-semi-colons-in-javascript-4f8712c82329
https://flaviocopes.com/javascript-automatic-semicolon-insertion/

As for the curly brackets {} and parentheses (), well you need to make sure that you have matching pairs of them all, so basically you must have equal numbers of open { and closed } curly brackets and open ( and closed ) parentheses.

Also, you should only have the one onReady page function on your page.

Hi, H G R .

In addition to what givemeawhisky said …

In the following comment:

 //next function: ITEM1 2 3 make these three items hidden above appear when radiobutton3  

if you do, indeed, mean “hidden”, then shouldn’t “show()” in each of the three/3 following lines be replaced with “hide()”:

$w("#vectorImage14").show()
$w("#text79").show()
$w("#dropdown5").show() 

?

Also, I believe that you intended that the above three/3 lines should be surrounded by curly braces ( { and } ) since I believe you meant that they should all be run only if the condition evaluates to true.

I also recommend that you replace each generically named control with a mnemonic name (makes it much easier to read, grok and maintain your code).

1 Like

No Abergquist, although I did need to double check and re-read it again myself, they need the elements in the first onReady page function to be shown in that if Yes function, although I would be very tempted to put in a else too for each radio button, however like most things there are always more than one way to do things!

Plus after reading it again, then those first two dropdowns, vector image and text element could be just set as hidden on load in each of their properties panel and just shown when needed in the code, otherwise simply wrapped up all in the first onReady page function. (Or better still collapsed on load so that they don’t take up any room on the page until they are needed.)

Also HGR, as Abergquist says it is always better to rename your elements id names so that it reflects your pages own workings and is easier to use in your code etc., plus there is an extra ‘s’ in the last chunk of code for the lifetime radio button. $sw should be $w.

1 Like

@givemeawhisky Mucho Gratis to both your and ABERQUIST’s contributions, but alas - I have given up. Too complicated for this senor senior brain. I could’ve been a programmer years ago, but chose another occupation. My current volunteer effort as the webmaster is enough work for me without learning the intricacies of code development. This spurned some creative ways in which I ask the questions now, which leads to easier database reading. I appreciate your help anyway … it’s tough work, I’m sure. Right now I’m stuck on how to take all this info in the database and display it on another 'verification form (lightbox) so the user can be sure they entered the proper info then press SUBMIT…but I guess that will be for another day.

Here’s what the page looks like now http://www.vfwpost2485.org/join-the-vfw

Salud -

HGR