Check if radio button is selected or not

Discussions and Tech Support related to the iMacros Firefox Add-on, including the built-in Javascript scripting interface for playing .js files.

Moderators: Community Moderators, iMacros Moderators

Forum rules
Before asking a question or reporting an issue:
1. Please review the list of FAQ's.
2. Use the Google search box (at the top of each forum page) to see if a similar problem or question has already been addressed. This will search the entire contents of the forums as well as the iMacros Wiki.
3. We can respond much faster to your posts if you include the following information:

CLICK HERE FOR IMPORTANT INFORMATION TO INCLUDE IN YOUR POST

Answering your own posts (e.g. attempting to "bump" your topic) drops your topic from the list of unanswered threads, so it may actually receive less views.

Check if radio button is selected or not

by techimac on Mon Jan 22, 2018 5:21 pm

how to check if any radio button from a group is selected or not?

example code
Code: Select all
<form>
   <p><input type="radio" name="R1" value="V1" ></p>
   <p><input type="radio" name="R1" value="V2"></p>
</form>


Firefox 47
iMacros 8.9.7
Windows 8.1
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by chivracq on Mon Jan 22, 2018 8:03 pm

techimac wrote:how to check if any radio button from a group is selected or not?

example code
Code: Select all
<form>
   <p><input type="radio" name="R1" value="V1" ></p>
   <p><input type="radio" name="R1" value="V2"></p>
</form>


Firefox 47
iMacros 8.9.7
Windows 8.1

Post a Site with some RB for me to do any Testing... :idea:
Hum..., and it shouldn't be very difficult to check/test...?, what is the Pb...?, what have you tried...? You are not a Newbie...! (Hum, I don't help Newbies who don't try anything either, ah-ah...!) :twisted:

Your 'Example" sucks a bit (like any "Fake" Example without real URL btw...), because of the extra Space for 'V1' and you don't mention if any Option is already selected or not...
I think I use that Functionality "somewhere" in one of my Scripts, but I think that's in some Script of mine about 8000 Lines long, I don't know where exactly anymore, is quicker if you can find a Site with some RB...

Hum/Grrr...!, and your Thread has nothing specific to iMacros for FF :roll: , correct Sub-Forum was the 'General' one..., hum or the 'Data Extraction' one... (No need to duplicate now of course...!)
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Check if radio button is selected or not

by techimac on Mon Jan 22, 2018 11:51 pm

I got the solution for checking particular radio button
need a way to find if any radio button is selected or not in a group

I tried ATTR=CHECKED:CHECKED EXTRACT=TXT
but it didn't worked.
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by chivracq on Tue Jan 23, 2018 12:19 pm

techimac wrote:I got the solution for checking particular radio button
need a way to find if any radio button is selected or not in a group

I tried ATTR=CHECKED:CHECKED EXTRACT=TXT
but it didn't worked.

Yeah, I don't know, you didn't post a "concrete" URL, so I had a look at the Page on the Forum when posting a Reply or a Quote, with the 'Post icon' RB's, the first one (= "None") is automatically selected when the Page is loaded for the first time, and it has indeed some "checked="checked"" Attribute, but even after changing the RB Selection to another Icon, and the Selection remains after a Refresh of the Page, but it's always (and only) the 'None' Icon that still has this 'checked' Attribute while it is actually a different Icon which is selected... :?

I don't remember encountering any "heavy" Difficulty when I implemented some similar Functionality in one of my Scripts (but hum, several years ago), so I'm not sure what's the Difference, or maybe it was about Checkbox Elements, I don't know...

I hope you'll post the/your Solution if you manage to solve it, I'll be interested...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Check if radio button is selected or not

by techimac on Tue Jan 23, 2018 1:47 pm

ATTR=CHECKED:CHECKED EXTRACT=TXT
element was not available
once I have the solution or found proper HTML code to find solution, I will share
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by techimac on Tue Jan 23, 2018 1:48 pm

I can give you code for checking single radio button state
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by chivracq on Tue Jan 23, 2018 2:20 pm

techimac wrote:ATTR=CHECKED:CHECKED EXTRACT=TXT
element was not available
once I have the solution or found proper HTML code to find solution, I will share

OK...

techimac wrote:I can give you code for checking single radio button state

Yeah, sure..., that can always be useful for other Users and that might give me some "Ideas", ah-ah...! :wink:
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Check if radio button is selected or not

by techimac on Tue Jan 23, 2018 2:49 pm

TAG POS=1 TYPE=............ EXTRACT=CHECKED

"YES" if checked and "NO" if not checked
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by techimac on Tue Jan 23, 2018 2:51 pm

Got it from here

viewtopic.php?f=7&t=7280
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by chivracq on Tue Jan 23, 2018 4:22 pm

techimac wrote:TAG POS=1 TYPE=............ EXTRACT=CHECKED

"YES" if checked and "NO" if not checked

techimac wrote:Got it from here

viewtopic.php?f=7&t=7280

Oh..., yes of course, "EXTRACT=CHECKED"...!!

OK, then I remember my own Script, that's exactly what I was using as well indeed, as it is documented in the Wiki for 'TAG' + 'EXTRACT', and I remember thinking there was a mistake in the Wiki about the "true"/"false" instead of "YES"/"NO", ah-ah...!

Well, then, if you don't know in advance which RB is checked, you simply need to extract them all and using 'EVAL()' + 'if/else' or 'CASE' to find out which one is selected, that's not very complicated...
Or you store all YES/NO Values in a String or Array and using 'split()' x2, first on "YES" and then on "NO", then the Length of the 2nd Array gives you the Position of which RB is selected...
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)

Re: Check if radio button is selected or not

by techimac on Tue Jan 23, 2018 4:27 pm

chivracq wrote:
techimac wrote:TAG POS=1 TYPE=............ EXTRACT=CHECKED

Well, then, if you don't know in advance which RB is checked, you simply need to extract them all and using 'EVAL()' + 'if/else' or 'CASE' to find out which one is selected, that's not very complicated...
Or you store all YES/NO Values in a String or Array and using 'split()' x2, first on "YES" and then on "NO", then the Length of the 2nd Array gives you the Position of which RB is selected...


I have written javascript code for that
its very simple
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by techimac on Tue Jan 23, 2018 4:29 pm

I was hoping for some HTML tag value for checked radio button in a group
then it will be just one line instead of looping through radio buttons
techimac
 
Posts: 207
Joined: Fri Feb 20, 2015 2:27 pm

Re: Check if radio button is selected or not

by chivracq on Tue Jan 23, 2018 4:47 pm

Well, then share your Code if you've already written it, that can always be useful for other Users... (And your Solution sounds simpler anyway then all 3 or 4 I have in mind...)

I didn't see indeed anything in the HTML Source Code telling "directly" which RB is selected, I don't really understand how the 'EXTRACT=CHECKED' is able to return if a RB is selected or not, but it works indeed, ah-ah...!
- (F)CIM = (Full) Config Info Missing: iMacros + Browser + OS with all 3 Versions...
- I usually don't even read the Question if that (required) Info is not mentioned...
- Script & URL usually help a lot for a more "educated" Help...
chivracq
 
Posts: 6687
Joined: Sat Apr 13, 2013 6:07 am
Location: Amsterdam (NL)


Return to iMacros for Firefox

Who is online

Users browsing this forum: No registered users and 9 guests

-->