0

I am making a very simple YouTube downloader for personal use. As it's a small simple project, I'm simply using the power of ElectronJS and Node-YTDL-Core to make it.

One of the things I'm adding, for obvious reasons, is an MP3/MP4 toggle using Radio Buttons. If it wasn't obvious, the code checks if MP3 was checked, runs a code if so, then checks if mp4 was checked if mp3 wasn't, runs code.

However, when I run the code and selected "MP4", it pops the radio to 'MP3' and the console is logged with "Downloaded MP3." instead of "Downloaded MP4."

As both codes are long: I've provided in-depth snippets hosted via GitHub Gist to store the source.

https://gist.github.com/Incrested/78acf34644525632ad8825d518535bd2

Chris Li
  • 2,628
  • 1
  • 8
  • 23
  • The first thing I see is in your comparrisons like "if(document.getElementById('1').checked = true)", you need to use a double-equals for comparison. That line should be "if(document.getElementById('1').checked == true)" The way your code is now you are just assigning the value "true" to the control, then executing the loop because the assignment is succeeding. – Matt Runion Sep 14 '18 at 01:52
  • @mrunion Alrighty, I'll test it out and if it works I'll put an answer up referencing your comment and accept it. –  Sep 14 '18 at 02:15

2 Answers2

2

As mentioned by @mrunion:

"- you need to use a double-equals for comparison. - The way your code is now[, ] you are just assigning the value "true" to the [radio button]"

Thanks to @mrunion for reminding me of such a simple mistake as the whole thing is functional now.

A brief preview of the before and after code would be as follows: if(document.getElementById('1').checked = true) before and if(document.getElementById('1').checked == true) { after.

0

You'll want to write a function that reads the value of the checked button and updates the type variable.

look here for some inspiration How to get the selected radio button value using js

Vidro3
  • 192
  • 2
  • 11
  • I guess I may not have been clear. I do have a system to read if a radio button is checked or not. –  Sep 14 '18 at 02:14