473,327 Members | 2,094 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

Programmatically setting a radio buttones

I am trying to programmatically set a radio button in a table of radio
buttons. I have two problems with the code below:

1 - I can not prepare the <Formstatement to be printed by php.
(syntax of the hyphens, quotes) my fault!

2 - If I delete the <Formand </Formstatements I can build the table
of radio buttons correctly, HTML wise. The fifth radio button has
'checked=True'. The problem is even though I set radio button 5 to be
checked only the last radio button is checked when it is displayed on
the screen. But viewing the page code says it should be the fifth radio
button.

Anybody have some ideas, I'm lost.

<?php
/**
Http://localhost/quotes/scrap.php?XD...RT=tswebeditor
*/
if(isset($_POST['abbr_letter']) ) {
$selectedNum = $_POST['abbr_letter'];
}
else {
$selectedNum = 1;
}

$value = 0;
$checked = 'false';
$selectedNum = 5;
$ColumBrake = 13;

print '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
print '<html xmlns="http://www.w3.org/1999/xhtml">';
print '<HTML>';
print '<HEAD>';
print '<title>Testiing radio Buttons</title>';
print '<link href="quotes.css" rel="stylesheet" type="text/css">';
print '<SCRIPT language=JavaScript src="quotesCss.js"
type="text/javascript"></SCRIPT>';
// print '<b><FORM NAME="author_abbrv" method="POST" action="'.<?php
echo $_SERVER['PHP_SELF'];?>.'"></b>';
print '</HEAD>';
print '<table><tbody><tr>';

foreach (range('A', 'Z') as $letter)
{
if( $value == $ColumBrake) {
print '</tr><tr>';
}
if( $value == $selectedNum) {
$checked = 'true';
print '<td><input type="radio" name="abbr_letter" value="'.
$value .'" checked="'. $checked .
'" onclick="submit()" />'.$letter.'</td>';
} else {
$checked = 'false';
print '<td><input type="radio" name="abbr_letter" value="'.
$value .'" checked="'. $checked .
'" onclick="submit()" />'.$letter.'</td>';
}
$value = $value +1;
}
print '</tr></tbody></table>';
// print '</FORM>';
print '</HTML>';
?>

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Nov 21 '06 #1
7 3270
Message-ID: <x_********************@ptd.netfrom IchBin contained the
following:
>I am trying to programmatically set a radio button in a table of radio
buttons. I have two problems with the code below:

1 - I can not prepare the <Formstatement to be printed by php.
(syntax of the hyphens, quotes) my fault!
>// print '<b><FORM NAME="author_abbrv" method="POST" action="'.<?php
echo $_SERVER['PHP_SELF'];?>.'"></b>';

print '<b><FORM NAME="author_abbrv" method="POST" action="'.
$_SERVER['PHP_SELF'].'"></b>';
--
Geoff Berrow (put thecat out to email)
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Nov 21 '06 #2
"IchBin" <we******@ptd.netwrote in message
news:x_********************@ptd.net...
>I am trying to programmatically set a radio button in a table of radio
buttons. I have two problems with the code below:

1 - I can not prepare the <Formstatement to be printed by php. (syntax
of the hyphens, quotes) my fault!

2 - If I delete the <Formand </Formstatements I can build the table
of radio buttons correctly, HTML wise. The fifth radio button has
'checked=True'. The problem is even though I set radio button 5 to be
checked only the last radio button is checked when it is displayed on the
screen. But viewing the page code says it should be the fifth radio
button.

Anybody have some ideas, I'm lost.


You're not using the checked attribute correctly. It has no value true or
false. If you wish to assign a value to it (in xhtml you MUST assign a value
to it) the value is "checked". However the value is not evaluated ever, it's
just a dummy placeholder. Just the presence of the checked attribute means
that the button should be checked, weather it's value is set to "true",
"false" or "barbara streisand". When you have a zillion buttons that all are
checked, the last one remains checked. This is what you are experiecing

right:
<input type="radio" name="foo" checked="checked" />
<input type="radio" name="foo" />
<input type="radio" name="foo" />

wrong:
<input type="radio" name="foo" checked="true" />
<input type="radio" name="foo" checked="false" />
<input type="radio" name="foo" checked="donald duck" />
(All are checked)

Only set the checked attiribute to the element you want checked, and it's
value should be "checked", and not set it to any of the other elements.

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Nov 21 '06 #3

"Kimmo Laine" <sp**@outolempi.netwrote in message
news:Cm*******************@reader1.news.jippii.net ...
right:
<input type="radio" name="foo" checked="checked" />
<input type="radio" name="foo" />
<input type="radio" name="foo" />
I do it this way:

<input type="radio" name="foo" <?php if (some_condition_is_met) echo "
checked"; ?/>

I don't put in checked="checked", I simply put in checked.

Shelly
Nov 21 '06 #4
"Shelly" <sh************@asap-consult.comwrote in message
news:Yk*****************@newsread3.news.pas.earthl ink.net...
>
"Kimmo Laine" <sp**@outolempi.netwrote in message
news:Cm*******************@reader1.news.jippii.net ...
>right:
<input type="radio" name="foo" checked="checked" />
<input type="radio" name="foo" />
<input type="radio" name="foo" />

I do it this way:

<input type="radio" name="foo" <?php if (some_condition_is_met) echo "
checked"; ?/>

I don't put in checked="checked", I simply put in checked.

That works perfectly if you're using an html 4.01 doctype, there's nothing
wrong with that. But as I mentioned, in xhtml an attribute is required to
have a value, and that's why one must use checked="checked" when working
with xhtml doctype. This is explained briefly in the w3c xhtml
documentation: http://www.w3.org/TR/xhtml1/#h-4.5

--
"Ohjelmoija on organismi joka muuttaa kofeiinia koodiksi" - lpk
http://outolempi.net/ahdistus/ - Satunnaisesti päivittyvä nettisarjis
sp**@outolempi.net | rot13(xv***@bhgbyrzcv.arg)
Nov 21 '06 #5
Kimmo Laine wrote:
"Shelly" <sh************@asap-consult.comwrote in message
news:Yk*****************@newsread3.news.pas.earthl ink.net...
>"Kimmo Laine" <sp**@outolempi.netwrote in message
news:Cm*******************@reader1.news.jippii.ne t...
>>right:
<input type="radio" name="foo" checked="checked" />
<input type="radio" name="foo" />
<input type="radio" name="foo" />
I do it this way:

<input type="radio" name="foo" <?php if (some_condition_is_met) echo "
checked"; ?/>

I don't put in checked="checked", I simply put in checked.


That works perfectly if you're using an html 4.01 doctype, there's nothing
wrong with that. But as I mentioned, in xhtml an attribute is required to
have a value, and that's why one must use checked="checked" when working
with xhtml doctype. This is explained briefly in the w3c xhtml
documentation: http://www.w3.org/TR/xhtml1/#h-4.5
Thank you Kimmo and Shelly for your help. Not sure where I got the idea
of true or false but then again I am very new to this type of coding. So
anything is possible on my side of the house.

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Nov 21 '06 #6

"IchBin" <we******@ptd.netwrote in message
news:Og********************@ptd.net...
Kimmo Laine wrote:
>"Shelly" <sh************@asap-consult.comwrote in message
news:Yk*****************@newsread3.news.pas.earth link.net...
>>"Kimmo Laine" <sp**@outolempi.netwrote in message
news:Cm*******************@reader1.news.jippii.n et...
right:
<input type="radio" name="foo" checked="checked" />
<input type="radio" name="foo" />
<input type="radio" name="foo" />
I do it this way:

<input type="radio" name="foo" <?php if (some_condition_is_met) echo "
checked"; ?/>

I don't put in checked="checked", I simply put in checked.


That works perfectly if you're using an html 4.01 doctype, there's
nothing wrong with that. But as I mentioned, in xhtml an attribute is
required to have a value, and that's why one must use checked="checked"
when working with xhtml doctype. This is explained briefly in the w3c
xhtml documentation: http://www.w3.org/TR/xhtml1/#h-4.5
Thanks Kimmo. I wasn't aware there might be a problem as this has always
worked for me.

Shelly
Nov 21 '06 #7
Geoff Berrow wrote:
Message-ID: <x_********************@ptd.netfrom IchBin contained the
following:
>I am trying to programmatically set a radio button in a table of radio
buttons. I have two problems with the code below:

1 - I can not prepare the <Formstatement to be printed by php.
(syntax of the hyphens, quotes) my fault!

>// print '<b><FORM NAME="author_abbrv" method="POST" action="'.<?php
echo $_SERVER['PHP_SELF'];?>.'"></b>';


print '<b><FORM NAME="author_abbrv" method="POST" action="'.
$_SERVER['PHP_SELF'].'"></b>';
Thanks Geoff, sorry I missed your response. I did look at the code again
and realized what I was doing wrong. Not used to these scripting languages.

--
Thanks in Advance... http://ichbin.9999mb.com
IchBin, Pocono Lake, Pa, USA http://weconsultants.phpnet.us
__________________________________________________ ____________________
'If there is one, Knowledge is the "Fountain of Youth"'
-William E. Taylor, Regular Guy (1952-)
Nov 21 '06 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Jim Quast | last post by:
I have an ASP page and a CREGReports002.vbs file coded to export data to excel. I do this by building variables in a stored procedure. The ASP page has text boxes, list boxes, and radio buttons. ...
13
by: aundro | last post by:
Hello, I've been looking on the web for a solution to this problem: I create a set of checkboxes, and 2 buttons: - one is labeled "All" - the other is labeled "None" Clicking "All" is...
1
by: John Criswell | last post by:
I have created a radio button list programmatically. C# SqlConnection conn = new SqlConnection("data source=localhost; integrated security=true; initial catalog=pubs"); SqlCommand cmdAuthors =...
1
by: tshad | last post by:
How do you set the Page.IsValid property manually? I need to check if a bunch of radio buttons are set and if none are I want to display a message that you need to select one. I just have a...
4
by: johnmmcparland | last post by:
am trying to add controls (e.g. radio buttons, group boxes) to a windows form in a method which I call from the constructor. However, when I do things like; RadioButton rb= new RadioButton();...
5
by: Jan Smith | last post by:
I have a C# project that has a tab control with four tab pages. On each tab page is a set of three radio buttons (named radioButton1 through radioButton12). I would like to loop through the radio...
1
by: IchBin | last post by:
I am trying to set the state of a radio button. I do not see what I am doing wrong. Sorry, I am new at this.. I need another set of eyes to look at this snip of code. I am trying to set the radio...
0
by: Robert J. Bonn | last post by:
I am setting up a contact list for a musician, who is about to release her first CD. She would like a contact list that can track all the people she meets, who will be in various categories --...
5
by: NKaufman | last post by:
<asp:GridView ID="Basic" runat="server" DataKeyNames="QuestionID,isHeading" AutoGenerateColumns="false" AllowPaging="true" PageSize="100"> <Columns> <asp:BoundField Visible="false"...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.