jQuery - radiobutton (part of is done)

This can't be that hard but I spent all day on it and still can't get this right.

I really , seriously, know I should create a JSFiddle but I have the code here. I promise I'll learn how to do JSFiddle :)

Julian and LeakIM helped me with this...

1. Code is here. Click on page.html
https://drive.google.com/file/d/16gxJi-mbi3q4o19Y7HTmw4pWMUkasN2h/view

2. Choose, for example, "Once" from the dropdown. You see "CSV" is selected. It has "checked"
r1.png
3. Now, I choose "Excel". I click "Update". But, it doesn't get "checked". It's always "CSV" that's selected. This causes "CSV" selection to be always saved in the database.
r2.png
4. You can add more items by clicking "Add Report Delivery"

5. I did this to loop thru all the checkboxes. It looks like I get the correct radiobutton selected. But, how can I say
Schedules[' + i + '].IsExcelExport is selected and set it to true. I need the property "ISExcelExport" to to be set to true or false for radio1 and radio2

I have this. You can see it in Reporting.js
$('.schedule', '#scheduleArea').each(function (i, e) {

		console.log(i)

		console.log($('#reportBuilder .radio1:checked').val());
		console.log($('#reportBuilder .radio1:checked'));

		console.log($('#reportBuilder .radio2:checked').val());
		console.log($('#reportBuilder .radio2:checked'));

		$(e).find('.radio2')[0].name = 'Schedules[' + i + '].IsExcelExport';
		var r = $(e).find('.radio2')[0].name;
		console.log(r)

		//r = checked;
		//$('input:radio[class=radio2][id=r]').prop('checked', true);

		//});

	});

Open in new window

LVL 8
CamilliaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Chris StanyonWebDevCommented:
Hey Camillia,

Not entirely sure what you're trying to do with that code, but generally with radio buttons, you'd just have the values set to the options you need. Currently you have true/false. Would it not make more sense to have csv/excel as the values:

<input type="radio" name="Schedules[0]ExportFormat" value="CSV" checked>
<input type="radio" name="Schedules[0]ExportFormat" value="Excel">

Now when you submit your form, either CSV or Excel will be sent to the backend script, depending on which option you checked.

FYI - By selecting a different radio option, the HTML won't change. So if when your page loads, the CSV option is marked as 'checked'. Selecting Excel won't change the HTML - youll still see CSV checked. It will however send the correct value to the backend.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CamilliaAuthor Commented:
Let me see, Chris. I'll post back.
0
CamilliaAuthor Commented:
I know what you mean. I've been changing the ex-developer's code and broke this part.

I'll apply what you're saying and see if it works.

As always, thanks.

(Side note: I don't like dropdowns and radiobuttons :))
0
Chris StanyonWebDevCommented:
No worries Camillia,

And as for radios and dropdowns - they sometimes just take a little getting used to :)
0
CamilliaAuthor Commented:
Got it working :) thanks again.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.