in reply to CheckBox and Radio Button

my $checked = $cgi->param('checkboxname');
my $checked = $cgi->param('radioname') || '' eq 'radiovalue'

Replies are listed 'Best First'.
Re^2: CheckBox and Radio Button
by mld (Acolyte) on Apr 15, 2009 at 07:35 UTC

    For the tag"<input type="radio" name="ticketType" value="iticket" iTkt >"

    I used the follwing code to retrive the radio button value.

    $cgi=CGI::new(); $IE=Win32::IEAutomation->new(visible=>1, maximize=>1); $IE->gotoURL('http://www.irctc.co.in'); $IE->getTextBox('name:','userName')->SetValue('sid123'); SendKeys("~"); $IE->getTextBox('name:','password')->SetValue('sid*123'); $IE->getButton('name:','submit')->Click(); if ($cgi->param('ticketType') eq 'iticket') { print "Iticket"; } else { print "None" }

    On execution of above code the following error message is displayed "Use of uninitialized value in string eq at D:\Perl\Sample\check.pl line 12."

      You didn't specify that you wanted the state of inputs in a browser controlled using Win32::IEAutomation. I assumed you were checking inputs sent to you using CGI.

      Seeing if a checkbox is checked can be done using:

      $checkbox->getProperty('checked');

      For radio, you'll have to iterate through all the elements with the name in which you are interested and use ->getProperty('checked') until you find one that's checked. Unfortunately, there doesn't seem to be a clean way of getting all the radio elements with a given name, so you might have to iterate through all the radio elements and filter out those that don't have the name in which you are interested.