473,769 Members | 6,838 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Programmaticall y setting a radio buttones

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

1 - I can not prepare the <Formstatemen t 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.dt d">';
print '<html xmlns="http://www.w3.org/1999/xhtml">';
print '<HTML>';
print '<HEAD>';
print '<title>Testiin g radio Buttons</title>';
print '<link href="quotes.cs s" rel="stylesheet " type="text/css">';
print '<SCRIPT language=JavaSc ript src="quotesCss. js"
type="text/javascript"></SCRIPT>';
// print '<b><FORM NAME="author_ab brv" 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_lett er" value="'.
$value .'" checked="'. $checked .
'" onclick="submit ()" />'.$letter.'</td>';
} else {
$checked = 'false';
print '<td><input type="radio" name="abbr_lett er" 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 3334
Message-ID: <x_************ ********@ptd.ne tfrom IchBin contained the
following:
>I am trying to programmaticall y set a radio button in a table of radio
buttons. I have two problems with the code below:

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

print '<b><FORM NAME="author_ab brv" 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.n etwrote in message
news:x_******** ************@pt d.net...
>I am trying to programmaticall y set a radio button in a table of radio
buttons. I have two problems with the code below:

1 - I can not prepare the <Formstatemen t 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="checke d" />
<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***@bhg byrzcv.arg)
Nov 21 '06 #3

"Kimmo Laine" <sp**@outolempi .netwrote in message
news:Cm******** ***********@rea der1.news.jippi i.net...
right:
<input type="radio" name="foo" checked="checke d" />
<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="checke d", I simply put in checked.

Shelly
Nov 21 '06 #4
"Shelly" <sh************ @asap-consult.comwrot e in message
news:Yk******** *********@newsr ead3.news.pas.e arthlink.net...
>
"Kimmo Laine" <sp**@outolempi .netwrote in message
news:Cm******** ***********@rea der1.news.jippi i.net...
>right:
<input type="radio" name="foo" checked="checke d" />
<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="checke d", 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="checke d" 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***@bhg byrzcv.arg)
Nov 21 '06 #5
Kimmo Laine wrote:
"Shelly" <sh************ @asap-consult.comwrot e in message
news:Yk******** *********@newsr ead3.news.pas.e arthlink.net...
>"Kimmo Laine" <sp**@outolempi .netwrote in message
news:Cm******* ************@re ader1.news.jipp ii.net...
>>right:
<input type="radio" name="foo" checked="checke d" />
<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="checke d", 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="checke d" 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.n etwrote in message
news:Og******** ************@pt d.net...
Kimmo Laine wrote:
>"Shelly" <sh************ @asap-consult.comwrot e in message
news:Yk******* **********@news read3.news.pas. earthlink.net.. .
>>"Kimmo Laine" <sp**@outolempi .netwrote in message
news:Cm****** *************@r eader1.news.jip pii.net...
right:
<input type="radio" name="foo" checked="checke d" />
<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="checke d", 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="checke d"
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.ne tfrom IchBin contained the
following:
>I am trying to programmaticall y set a radio button in a table of radio
buttons. I have two problems with the code below:

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

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


print '<b><FORM NAME="author_ab brv" 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
4326
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. I also placed two buttons on the form. One submits the form to redirect to the Crystal Web Viewer (genCREGReports.ASP). The other one executes VB code in a vbs document that spawns some more code to run a stored procedure with the values from...
13
31473
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 supposed to check all the checkboxes, which it does (that's not rocket science ;), but the 'onchange' event does not get triggered.
1
9985
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 = new SqlCommand("select * from Authors", conn); SqlDataReader dr; dr = cmdAuthors.ExecuteReader(); RadioButtonList rblAuthors = new RadioButtonList(); rblAuthors.DataSource = dr;
1
1456
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 ValidateButtons routine that I call when a button is pushed and it will set a message on the page if none of the buttons are pressed and I want to set the IsValid property of the page so that my Page.IsValid test in my submit function will know that...
4
2382
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(); .... rb.Location.X= 67; this.Controls.Add(rb); // this is the Windows Form instance
5
3569
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 buttons and set their state without having to form the complete name of each one, something like this: public static void SetButtonState(Form frm, int ButtonCount) {
1
3231
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 button with this link of code: echo 'SCRIPT language=JavaScript setCheckedValue("'.$_SESSION.'");</SCRIPT>'; //? <snip of code>
0
1651
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 -- fans, radio station personnel, owners of clubs, other musicians, etc. Ideally, I'd like to create a form that asks basic questions for everyone (name, phone number, etc.) No problem. But then, there will be different kinds of information,...
5
23634
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" DataField="QuestionID" HeaderText="QuestionID"></asp:BoundField> <asp:BoundField DataField="QuestionDesc" HeaderText="Question" ItemStyle-HorizontalAlign="Left"></ asp:BoundField>
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10050
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9999
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9866
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7413
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5310
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5448
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3967
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.