Check is a radio button is checked after post back in ASP.NET - asp.net

I am looping through all the posted data on my website and grabbing the values, this will then be used later on. The user is going to put 2 radio buttons on the page, one with a correct answer and one with an incorrect answer. I need to know how to see if a Radio Button is checked or not based on the posted data. Is this possible?
Thanks.

If the radio button is checked, there will be an entry in the posted data, keyed with its UniqueID:
if (Request.Form[yourRadioButton.UniqueID] != null) {
// Radio button is checked, do something.
}

If you insist on reading directly from the request collection, read Request.Form["radiobuttonname"] and it will contain the value of the selected button.
However, it's much better to check the radio button control itself - why can't you do that?

Related

Google Tag Manager- is there a way to track when a checkbox is selected and then the user hits the Checkout button on that same page?

Sorry if this is a dumb question. I'm a GTM noob and from googling I see tutorials on tracking the clicks (checkbox element and Checkout button) separately but was wondering if there's any way this can be one Event in Google Analytics.
For example, on our store's cart page a checkbox to add a product's accessory is selected by default. I want to know how many people are hitting the Checkout button and leaving this "add an accessory" checkbox checked.
Is there a way to push an Event as something like "Checkout click - Add On Checkbox - Selected"?
Thanks in advance!
Yes, you can detect if a checkbox is checked on any event, using a Custom Javascript variable, value of which you then can use in the trigger, or in your tag. Or in a different variable, of course.
If you provide the html of your checkbox, we can give you code for the variable to return the checkbox state if you're not comfortable with JS.
//Upd
In your code, you have a few errors. First, no need to name the function in the CJS variable. Also, you write a bit too much code and rely on JQuery with no need. It can be solved simpler with pure JS like so:
function(){
return document.querySelector("input#add-subscription").checked;
}
Now, about the rest of what you're saying. Having this checkbox action. You have a wrong understanding. This is not a checkbox action. This code only gets the state of the checkbox whenever the value of this variable is being used.
So if you're gonna use the value of this variable when a person clicks on the form submission CTA, then this code will run on that click, assessing the value of the checkbox.
Your amazon example works. But you don't need to assume that the checkbox is checked by default. The default doesn't mean anything here. The state of the checkbox is assessed on the trigger where the value of the CJS var is used, that's it.
We're proceeding with your question: I'm confused about having the multiple criteria (checkbox is checked and user hits Checkout button) and if including both as triggers would work You're making another mistake here. They're not both triggers. One of them is a trigger indeed, which is a click trigger. The other, however, is a condition for the trigger to fire. You know how in the trigger, you click the checkbox that says "some events"? This fella:
Once you have that, you can add conditions. Like, only use this trigger when... when what? Anything really. In our case it would be when the checkbox is true.
Finally, for the checkout click, you don't typically need more than just the click trigger with the CSS selector criteria.
Anyhow, to be short, this is about how your trigger should look like:
Thanks! In this case the checkbox element for my cart page is:
<input id="add-subscription" type="checkbox" checked="checked" class="form-checkbox js-product-subscribe-newux mt-10 sm:mt-0" name="sub" value="remove">
I was thinking the variable could be:
function checked() {
var check = jQuery('form-checkbox js-product-subscribe-newux mt-10 sm:mt-0').attr("checked");
if(check === "checked") {
return true;
} else {
return false;
}
}
However where I get confused is having this checkbox action (checkbox is checked) only count as an event when the user hits the Checkout button. Using this Amazon cart page as an example, assuming the "This is a gift" checkbox is clicked by default, "This is a gift" checkbox would I just then add the Trigger as having two criteria, roughly: {{Checkbox Variable}} = "true" & Click Text = "Proceed to Checkout? I'm confused about having the multiple criteria (checkbox is checked and user hits Checkout button) and if including both as triggers would work in this case so I can see how many times users click to checkout from the cart while leaving that box checked. Or would the Click on the Checkout button need to be it's own separate variable rather than just specifying the Checkout button name in the trigger criteria?

How to peoplecode with radio button

Anyone of you who knows how to peoplecode with the value choosen with radio button?
I have this page with radio button of academic programs and when a user select from one of the programs, I want to print a report basing on that program chosen in the radio button.
Any idea where to start and how to do this?
Thanks so much for the help.
Open the page in Application Designer and check the properties of the radio button fields.
They will look something like this:
All the related radio buttons will have the same record and field, but a different value.
To execute code, based on the selected radio button, you would evaluate the value:
Evaluate RECORD.FIELD.Value
When "VAL1"
RunReport1();
When "VAL2"
RunReport2();
When-Other
/* Error */
End-Evaluate;
Note: Fields used for radio buttons have to have XLAT validation IIRC

ax 2012 - checking and unchecking of checkbox on form

I came across a problem with checking and unchecking the same record on form.
I have a form with list of records, depending on status on record you can see an active/inactive button. Logic for this is included in active method on data source. When i click checkbox first time for some record it is Ok, button acts as required, but when i click this same checkbox second time to uncheck this record, the button does not work ok. For example if a record is checked the button Accept is active, but if a record is unchecked the button Accept should be inactive. I tried to solve this issue also with selectionChanged method but it didn't help. Could you give me some guidance how to handle with this problem?
Below I updated my post with pictures - it is specifically about Confirm button.
Thanks for add you code.
Ok, this is the button ComplaintConfirm?? if this is the botton in one part you compare Complaints.ComplaintConfirmed == Complaints_ComplaintConfirmed.checked(false)
Complaints.ComplaintConfirmed if a enum NoYesId?? if a NoYesId perhaps here is the error.
Can you try this?
ComplaintConfirm.enabled((Complaints.ComplStatus == ComplStatus::Accepted || Complaints.ComplStatus == ComplStatus::Rejected) && Complaints.ComplaintConfirmed == NoYes::No);

Zoho global variables or workaround for that

I'm new to Zoho CRM. I need to show a warning on button press but only once for the first button press. This sounds really simple but yet I can't figure out how to do it in Zoho Creator as all variables seems to have local scope so I can't determine if the button was pressed before. I've been searching if there are global variables in Zoho but found only workarounds with creating another applications for that case.
I've also tried creating a field on my form and hiding it to pass some value there if the button was pressed so next time I can check this field but is not working for some reason.
In validation part I'm assigning new value to a field
warning_shown=true;
But on a form this checkbox remains unchecked and next time I press the button warning_shown equals false.
Any suggestions will be appreciated!
In case someone interested, here is a reply I got on another forum that might help. Here is a link for that topic
It's not going to be possible to use the validation code section to display the message.
I was thinking you could have your hidden decision box field, and in the "On User Input" of the last field in the form you could use something like:
//remember to change field names accordingly
if !input.warning_shown
{
alert "Message here!";
input.warning_shown = true;
}
This would show the message after the last field is filled but before the button is clicked.

Semantic markup to achieve last row editable effect?

I'm looking to have a table that can be added to by just typing into the last row and clicking on the "Add" button at the end of the row. All other rows in the table can be deleted by clicking on a button in their rightmost column.
My problem is that forms can't wrap only one row and validate as XHTML. If I make the form wrap the entire table, it'll include the rows which have a form as their last cell too. And forms within forms are definitely not valid.
Suggestions?
Thanks for clarifying the situation. The way I see it you have a few options here:
Are you using (can you use) JavaScript? If so, you can easily modify the submission URI based on which button was pressed. You can thus get rid of all forms except for table-wrapping one.
Alternatively, depending on your requirements, you may be able to replace your "delete" buttons with links (possibly styled like buttons) in which case you won't need forms to wrap them. Note that this approach does not require javascript UNLESS you need to handle a situation when someone begins to fill last row and then clicks on "delete" on some other row and you want to preserve incomplete changes made to last row inputs. In this case you'd still need to use javascript to submit the form so #1 above would probably be better.
Bite the bullet and submit to the same URI. Distinguish what button was pressed by button name. You can always redirect to appropriate URI at that point.
Make your peace with non-validating html :-)

Resources