jQuery - radiobutton (part of is done)

Camillia used Ask the Experts™
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

2. Choose, for example, "Once" from the dropdown. You see "CSV" is selected. It has "checked"
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.
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($('#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;

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



Open in new window

Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2018
Distinguished Expert 2018
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.
Let me see, Chris. I'll post back.
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 :))
Most Valuable Expert 2018
Distinguished Expert 2018

No worries Camillia,

And as for radios and dropdowns - they sometimes just take a little getting used to :)
Got it working :) thanks again.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial