473,379 Members | 1,170 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,379 software developers and data experts.

Filling a text box when radio button is clicked

Hi,

I am writing a PHP website. When I am taking some input from a user,
I write some static radio buttons for a category, and then also write
some more that are generated based on a query to a database. I would
like to have a text box for a description of the category. I would
like that to be able to be typed in if the user selects on of the
static options but automatically filled in by data from the database
if they select one of the radio buttons that are DB generated. I
would also like to be able to prevent the user from changing the text
box if it is filled in with DB data (if possible, not that big of a
deal if too difficult).

Thanks.

Mar 7 '07 #1
2 3372
On Mar 7, 3:16 pm, "KDawg44" <KDaw...@gmail.comwrote:
Hi,

I am writing a PHP website. When I am taking some input from a user,
I write some static radio buttons for a category, and then also write
some more that are generated based on a query to a database. I would
like to have a text box for a description of the category. I would
like that to be able to be typed in if the user selects on of the
static options but automatically filled in by data from the database
if they select one of the radio buttons that are DB generated. I
would also like to be able to prevent the user from changing the text
box if it is filled in with DB data (if possible, not that big of a
deal if too difficult).

Thanks.

I see how to set this with JavaScript. Can I pass the results of a
PHP query into a javascript? Something like this?

while ($row = mysql_fetch_row($rs) {
echo "<input type = radio name = radio1 value = '" . $row[0] . "'
onclick = 'fillTextBox(" . $row[0] . "," . $row[1] . ")'>";
}

and then have a JavaScript function something like:

function fillTextBox(var cat, var dbData) {
document.getElementById(cat).value = dbData;
}
THanks.

Mar 7 '07 #2
KDawg44 wrote:
On Mar 7, 3:16 pm, "KDawg44" <KDaw...@gmail.comwrote:
>Hi,

I am writing a PHP website. When I am taking some input from a user,
I write some static radio buttons for a category, and then also write
some more that are generated based on a query to a database. I would
like to have a text box for a description of the category. I would
like that to be able to be typed in if the user selects on of the
static options but automatically filled in by data from the database
if they select one of the radio buttons that are DB generated. I
would also like to be able to prevent the user from changing the text
box if it is filled in with DB data (if possible, not that big of a
deal if too difficult).

Thanks.


I see how to set this with JavaScript. Can I pass the results of a
PHP query into a javascript? Something like this?

while ($row = mysql_fetch_row($rs) {
echo "<input type = radio name = radio1 value = '" . $row[0] . "'
onclick = 'fillTextBox(" . $row[0] . "," . $row[1] . ")'>";
}

and then have a JavaScript function something like:

function fillTextBox(var cat, var dbData) {
document.getElementById(cat).value = dbData;
}
THanks.
Yep, you'll need to use javascript for anything happening client-side.

And sure - it doesn't matter how the JS is generated - from a page or
echoed from PHP, for instance. The browser has no idea.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================
Mar 8 '07 #3

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

Similar topics

1
by: Kwart246 | last post by:
Hello, Is it possible to use a text link to enable a radio button, just like some windows interfaces, when the text is clicked, the radio button gets selected..... This works for a checkbox:...
4
by: Jared | last post by:
Radio Button or Check Box and Event Procedures I need to insert either radio buttons or check boxes onto my form. I'm not sure which to use, or if there are other options. I am using the buttons...
3
by: Ferret Face | last post by:
Hello, I have a web page that gets the user to select items from a list of options. This list is a set of independant Radio Buttons. I did not use a Radio Button List because I wanted the...
6
by: Ian Davies | last post by:
Hi me again, sorry to be a pain. Ive been struggling with this one all day. Hope you can understand whats happening. First my script is below. Have a look and I'll explain at the bottom what it...
11
by: bill | last post by:
I dynamically create buttons and associate them with an event using AddHandler. I want all the button events to fire at one time, when the page is posted, instead of when each button is clicked....
1
by: namanhvu | last post by:
Hi everyone, I'm trying to create a form where the radio button is automatically selected when the input text field beside it is clicked. I know I need to use "onClick" somewhere but I don't...
1
by: mlarsen1982 | last post by:
Hello, I have a quick question regarding filling a list box. Basically I need some assistance for a starting point. I have a form with 4 radio buttons for the user to select, then press next....
3
by: santhosh89 | last post by:
hi guys, see i want to develop a script and developed one but it s not working. the concept is there will be three radio buttons. the user has to check one radio button and click the button next...
4
by: padmapriya | last post by:
I need to create three radio buttons and when the radio button is clicked, the corresponding text fields such as 3 different address types should get activated. If i clicked the first radio button,...
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...
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.