Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 12th, 2003, 01:01 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default Radio Button Problem

I have three radio buttons and on text box.
if user click on Purchase type company or client then text box field should be disable (inactive)
and if user insert value in text box then company and client radio button should be disable (inactive)
how do it ?

tables field and data
-----------------------
ptype varchar
------------------------
company
client
1202
…….


insert coding like this.

<P><INPUT id=radio1 type=radio name=radio1 value="parson">company</P>
<P><INPUT id=radio1 type=radio name=radio1 value="client">client</P>
<P><INPUT id=radio1 type=radio name=radio1 value="">Client contractor No<INPUT id=radio1 type=text name=radio1 ></P>


same like when I update purchase type records. When I retrieve the ptype value from the database (sql server)
if ptype company then company radio button should be checked and remaining two radio button and one text box should be disable.
If ptype client then client radio button should be checked and remain two radio button and one text box should be disable.
If ptype client contractno then client contractno radio button checked and text box should be active and remaining two radio button should be disable.
How can do it.


update coding like this.

rec_id=Request.QueryString("rec_id")

ssql="select ptype from softwarelist where rec_id='"& rec_id &"'"

set rs=cn.Execute(ssql)
if rs.eof=false then

<TR>
    <TD>Purchase Type</TD>
    <TD><%Response.Write("<INPUT id=ptype type=radio name=ptype value='" & rs("ptype") &"'>")%>company
        <%Response.Write("<INPUT id=ptype type=radio name=ptype value='" & rs("ptype") & "'>")%>Client
       <%Response.Write("<INPUT id=ptype type=radio name=ptype value='" & rs("ptype") & "'>")%>Client Contract no<%Response.Write("<INPUT type=text id=ptype
                  name=ptype value='"& rs("ptype") &"'>")%>
    </TD></TR>


Please help, how user can insert one value by three radio button one text box in the asp form, and how can retrieve, so the one radio button should be active remain two radio button and one text box
should be disable ?

Mateen
 
Old November 18th, 2003, 07:25 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

First, I want to point out that you shouldn't have a textbox with the same name as the radio buttons.

Let's look at the ASP side of this...

When you draw your radio buttons, you can check the database value for the purchase type and fill in the right checkbox "checked" property to check it. Here's how the radio buttons would look...

<% purchaseType = <value from database> %>

<INPUT id=radio1 type=radio name=radio1 value="parson" <%if purchaseType="parson" then response.write("checked")%> >company
<INPUT id=radio1 type=radio name=radio1 value="client" <%if purchaseType="client" then response.write("checked")%> >client
<INPUT id=radio1 type=radio name=radio1 value="" <%if purchaseType="" then response.write("checked")%> >Client contractor No

That's what you can use to select the right radio button.

To disable a radio button, you need to modify the enabled property. For example:
<INPUT id=radio1 type=radio name=radio1 value="" enabled="false">

This disables the radiobutton. The same applies to a textbox. If you need to do this based on some value from the ASP code, you can wrap those inside of an ASP If just as shown above for "checked".


As far as the user interaction is concerned, you'll need to check the values and checked status of the various controls in JavaScript when the user clicks or types.

To disable the textbox when the radio buttons are clicked, you can use the radio button "onclick" event handler. For your example, I'd doing something like this:

<INPUT id=radio1 type=radio name=radio1 value="parson" onclick="this.form.theTextBox.enabled=false;">comp any
<INPUT id=radio1 type=radio name=radio1 value="client" onclick="this.form.theTextBox.enabled=false;">clie nt
<INPUT id=radio1 type=radio name=radio1 value="" onclick="this.form.theTextBox.enabled=true;">

If you want to disable the non-applicable radio buttons when someone enters a value into the text box (for the third radio button), you could do something like this (note that this handles the case where the user deletes the whole value, thus re-enabling the other checkboxes as well as selecting the correct checkbox):

<input type="text" name="theTextBox" onclick="this.form.radio1[2].checked=true;" onKeyUp="this.form.radio1[0].enabled=(this.value=='');this.form.radio1[1].enabled=(this.value=='');">

What this is doing is first selected the third radio button when you click in the textbox, and then testing the textbox value to see if it's blank when you press a key to enter a value. That test evaluates to a true or false, and this sets the enabled state of the two first radio buttons. Radio buttons of the same name get put into an array in the browser document object so you have to refer to them by an array index of the control name (radio1[x]).

Hopefully this helps.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 19th, 2003, 03:42 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks for your details response.

following coding will use at the time of data insert.
same like this, if we have to update the same records.
how can update the record by radio button.

if purchase type company radio button should checked
if purchase type client radio button should checked
if purchase type contractno text box should active and retrieve the
value in text box

<%
rec_id=Request.QueryString("rec_id")

ssql="select rec_id,software,sftwr_key,version,sofcd,manuf,vend or,ptype,pdate,sno,nlice,location,maint,madate,lsn ame,note from softwarelist3 where rec_id='"& rec_id &"'"

set rs=cn.Execute(ssql)

if rs.eof=false then
%>

<INPUT id=radio1 type=radio name=radio1 value="<%Response.Write(rs("purchasetype"))%>" <%if purchaseType="parson" then response.write("checked")%> >company
<INPUT id=radio1 type=radio name=radio1 value="<%Response.Write(rs("purchasetype"))%>" <%if purchaseType="client" then response.write("checked")%> >client
<INPUT id=radio1 type=radio name=radio1 value="" <%if purchaseType="" then response.write("checked")%> >Client contractor No<input type=text id=text1 name=radio1 value="<%Response.Write(rs("ptype"))%>"


<%
end if
%>

it always retrieve value in text box and contractno radio button checked

if purchasetype company it don’t check company radio button checked
if purchasetype client it don’t check client radio button checked



regards.




Quote:
quote:Originally posted by planoie
 First, I want to point out that you shouldn't have a textbox with the same name as the radio buttons.

Let's look at the ASP side of this...

When you draw your radio buttons, you can check the database value for the purchase type and fill in the right checkbox "checked" property to check it. Here's how the radio buttons would look...

<% purchaseType = <value from database> %>

<INPUT id=radio1 type=radio name=radio1 value="parson" <%if purchaseType="parson" then response.write("checked")%> >company
<INPUT id=radio1 type=radio name=radio1 value="client" <%if purchaseType="client" then response.write("checked")%> >client
<INPUT id=radio1 type=radio name=radio1 value="" <%if purchaseType="" then response.write("checked")%> >Client contractor No

That's what you can use to select the right radio button.

To disable a radio button, you need to modify the enabled property. For example:
<INPUT id=radio1 type=radio name=radio1 value="" enabled="false">

This disables the radiobutton. The same applies to a textbox. If you need to do this based on some value from the ASP code, you can wrap those inside of an ASP If just as shown above for "checked".


As far as the user interaction is concerned, you'll need to check the values and checked status of the various controls in JavaScript when the user clicks or types.

To disable the textbox when the radio buttons are clicked, you can use the radio button "onclick" event handler. For your example, I'd doing something like this:

<INPUT id=radio1 type=radio name=radio1 value="parson" onclick="this.form.theTextBox.enabled=false;">comp any
<INPUT id=radio1 type=radio name=radio1 value="client" onclick="this.form.theTextBox.enabled=false;">clie nt
<INPUT id=radio1 type=radio name=radio1 value="" onclick="this.form.theTextBox.enabled=true;">

If you want to disable the non-applicable radio buttons when someone enters a value into the text box (for the third radio button), you could do something like this (note that this handles the case where the user deletes the whole value, thus re-enabling the other checkboxes as well as selecting the correct checkbox):

<input type="text" name="theTextBox" onclick="this.form.radio1[2].checked=true;" onKeyUp="this.form.radio1[0].enabled=(this.value=='');this.form.radio1[1].enabled=(this.value=='');">

What this is doing is first selected the third radio button when you click in the textbox, and then testing the textbox value to see if it's blank when you press a key to enter a value. That test evaluates to a true or false, and this sets the enabled state of the two first radio buttons. Radio buttons of the same name get put into an array in the browser document object so you have to refer to them by an array index of the control name (radio1[x]).

Hopefully this helps.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 19th, 2003, 08:30 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Quote:
quote:Originally posted by planoie
<% purchaseType = <value from database> %>
You need to save the purchase type value from the database. That value is not being set in your code, so "purchaseType" is always blank, thus passing the last radio button checked test.

Peter
------------------------------------------------------
Work smarter, not harder.
 
Old November 29th, 2003, 12:14 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 518
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks.

Quote:
quote:Originally posted by planoie
 
Quote:
quote:Originally posted by planoie
Quote:
<% purchaseType = <value from database> %>
You need to save the purchase type value from the database. That value is not being set in your code, so "purchaseType" is always blank, thus passing the last radio button checked test.

Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Radio button Jolley_tolson Javascript 2 July 15th, 2007 05:50 AM
VBExpress 2005 : Radio Button Problem mague Visual Basic 2005 Basics 0 July 4th, 2007 02:13 AM
Radio button problem rkid VBScript 1 May 21st, 2007 02:08 PM
Radio button problem rkid BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 1 April 24th, 2007 12:42 AM
Button acts depending on radio button values janise Access 4 March 10th, 2004 12:53 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.