radio buttons not addressed in answer.
Job Miller, March 20, 2002 - 3:04 pm UTC
I thank you for this service. It is truly invaluable to me.
Your solution addresses elements that can be named the same in a form. sets of radio buttons can only be named the same for that one set, unlike text fields/checkboxes/etc..
Imagine you want a yes/maybe/no radio button set for every row returned. How do you name them so that your procedure can handle them without knowing ahead of time how_many there are going to be?
Any thoughts or suggestions would be tremendously appreciated. I am hoping that since the original question asked specifically for you to address radio buttons, you can re-address the original question or point to another resource that does.
The solution presented also relies on the browser to submit the values in the form in the order in which they appear in the form. Last I heard most browsers handle it this way, although you cannot be guaranteed of this by the specification. (I have never seen the spec, just read the Perl CGI docs which make this claim as well)
Thanks Tom!
March 20, 2002 - 3:33 pm UTC
You cannot use radio buttons like that for the very reasons you point out -- the browser won't POST any data for a radio button that is not on. The arrays get "messed" up.
I use a drop down list with the words YES/MAYBE/NO in it. The user toggles this list. The list always has value -- hence the indexes into the array correspond to the rows themselves.
I can only address that which can be done. Since radio buttons explicitly CANNOT be passed when set null (see below), you cannot use them in this generic fashion.
The browsers post the data in that order, if they did not -- virtually 100% of web based apps would break.
See
</code>
http://www.w3.org/MarkUp/html-spec/html-spec_8.html#SEC8.2 <code>
...
The fields are listed in the order they appear in the document with the name separated from the value by `=' and the pairs separated from each other by `&'. Fields with null values may be omitted. In particular, unselected radio buttons and checkboxes should not appear in the encoded data, but hidden fields with VALUE attributes present should. (26)
...
that is from
Hypertext Markup Language - 2.0
September 22, 1995
T. Berners-Lee (1)
D. Connolly (1)
(1) MIT/W3C
Thanks again
Job Miller, March 21, 2002 - 3:06 pm UTC
Initially I wasn't referring to the fact that NULLs screw up the order. Even if the radios are all set, you still can not use radio buttons.
Each set would have to have a unique form element name, otherwise they would function as one set of radios. In most other web languages(perl/php) this would be ok because you could name each set something different dynamically, but not in pl/sql where the parameters to the procedure have to be defined ahead of time. An array won't work, because the form will only give you one value for 300 radio elements all named the same thing (100 DB rows with 3 radio choices each)
I overlooked the obvious. Thank you for pointing it out.
Job
Great!
Job Miller, March 22, 2002 - 7:54 am UTC
Thank you for your additional response. That was exactly what I was looking for.
RADIO Buttons
mo, March 01, 2004 - 12:39 pm UTC
Tom:
I have a requirement to create a web page that displays a list of books and a radio button with 3 values for each "Found, Not Found, Other". The default value will always be "Found".
1. When I created the form and I named the radio button element with "p_radio", only the last record displayed showed the value defaulted to "Found". All others were not checked. I think this is the nature of radio buttons in HTML. To get around this problem I changed the name of the radio element for each record by using a variable. So my elements were names like "p_radio_1", "p_radio_2" etc.
I know you can't pass radio values as array in HTML. What I do set a hidden text field and when the user checks the radio I set the hidden value to whatever the button value is and then I submit it with the form.
Now my problem is that I am displaying one page for all records in the query. There can be 100 books. If I create the element names dynamically I have to input these names in the "Save Procedure" I submit to. I guess there is no way to build those input paraemters dynamically into the save procedure. SO I have to create manually 100 parameters and set them to null. This way I can handle whatever gets submitted:
1a. Is there a limit on how many input parameters you can have in a procedure?
1b. Is there a way to build input parameters dynamically in a procedure based on how may records are displayed in previous procedure?
1c. Do you know of a better way to resolve the above problem other than using a drop doen list?
1d. Is there a way to not submit the radio button value to the next form? Just the hidden value.
Thank you,
March 01, 2004 - 1:40 pm UTC
1) that is the nature of radio groups period -- everywhere. Only one "button" in a named group can be pushed (like old fashioned radio buttons in car radios)
this is why you don't really see very many radio buttons out there. I use drop down lists personally.
1a) nope, just practical ones (like how many variables do you want to code for?)
1b) don't know what you mean
1c) you could use flexible parameter passing, you'll get two arrays basically. it is documented
1d) thats a javascript question, not sure.
checkbox
mo, June 30, 2004 - 4:33 pm UTC
Tom:
I have an HTML application form with 3 questions that have six checkboxes each.
I want to build the "Edit form" and set the checkboxes to their values based on the table. Is there a better way to do this than:
Select count(*) into l_cnt from table where test_no= 100 code = 1;
IF (l_cnt > 0) THEN
v_q1_check = 'CHECKED';
END IF;
Select count(*) into l_cnt from table where test_no= 100 code = 2;
IF (l_cnt > 0) THEN
v_q2_check = 'CHECKED';
END IF;
I do that for all 18 checkboxes. I thought of using decode but it did not work because I will have v_q1_check hardcoded in the HTML line for the check box.
Any suggestions?
June 30, 2004 - 7:59 pm UTC
select max( decode(code,1,'CHECKED') ),
max( deocde(code,2,'CHECKED') ),
.....
into v_q1_check, v_q2_check, ....
from t
where test_no = 100;
checkboxes
mo, June 30, 2004 - 5:38 pm UTC
Tom:
AS a followup to previous question I did this: Thanks to your techniques:
TYPE Q1Array is table of varchar2(8);
Q1_Check Q1Array := Q1Array(null,null,null,null,null,null);
SELECT count(*),
decode(count(case when method_code=1 then 1 end),1,'CHECKED',null) Q1_Ck1,
decode(count(case when method_code=2 then 1 end),1,'CHECKED',null) Q1_Ck2,
decode(count(case when method_code=3 then 1 end),1,'CHECKED',null) Q1_Ck3,
decode(count(case when method_code=4 then 1 end),1,'CHECKED',null) Q1_Ck4,
decode(count(case when method_code=5 then 1 end),1,'CHECKED',null) Q1_Ck5,
decode(count(case when method_code=6 then 1 end),1,'CHECKED',null) Q1_Ck6
into
q1_cnt,Q1_Check(1),Q1_Check(2),Q1_Check(3),Q1_Check(4),Q1_Check(5),Q1_Check(6)
from test_method
where test_no=i_test_no;
htp.print(' <td><input name="i_description_code" type="checkbox" id="i_description_code" tabindex="39" value="1" '||Q1_Check(1)||' > ');
Is this the best way?
June 30, 2004 - 8:06 pm UTC
looks just fine.
checkbox
mo, July 01, 2004 - 5:45 pm UTC
Tom:
Is there an easier way in pl/sql to select a record if it exists.
My application record is stored in several tables. When I build the HTML form and let us say user never checked any checkbox for questions, I Always have to check the count before selectng record like:
select count(*) from table into l_Cnt where
test_no = i_test_no;
If (l_cnt > 0) THEN
select * into l_rec from table where test_no = i_test_no;
END IF;
I am doing that for several tables.
July 01, 2004 - 8:09 pm UTC
hmm, why not:
begin
select * into l_rec from table where test_no = i_test_no;
exception
when no_date_found then
setup l_rec the way you want it in this case
end;
checkbox
mo, July 01, 2004 - 10:22 pm UTC
Tom:
Would not this make it messier.
For every select i need (begin,end,exception). Program would be hard to read!
July 02, 2004 - 8:46 am UTC
how so? are you saying my code is ugly? ;)
Umm, how is:
begin
select * into l_rec from t where...
exception
when no_data_found then null;
end;
"uglier" than
select count(*) into l_cnt from t where ...
if ( l_cnt = 1 )
then
select * into l_rec from t where...
end if;
as i count them, same number of lines of code, just one of them demonstrates knowledge of PLSQL features and the desire to have performant code.....
Of course, you could do it "poorly" in a single line if you like:
select max(c1), max(c2), max(c3), ..... into l_rec
from t
where ....
having count(*) = 1;
but now you have to put a comment in front of each -- to explain to future generations of programmers that will inherit your code some day "why" you have the max and why you have the having clause.
checkbox
mo, July 02, 2004 - 9:53 am UTC
Tom:
No it is not ugly. AS you said it is almost same no of lines. I guess this how it will look. Correct?
BEGIN
begin
select * into l_rec from table1 where...
exception
when no_data_found then null;
end;
begin
select * into l_rec from table2 where...
exception
when no_data_found then null;
end;
begin
select * into l_rec from table3 where...
exception
when no_data_found then null;
end;
.....Main Code Statments
END;
July 02, 2004 - 10:53 am UTC
if you have to query up three records from three different tables. Of course, if they all have the same structure:
select * bulk collect into ..
from (select 't1', t1.* from t1 where ...
union all
select 't2', t2.* from t2 where ...
.....
);
Radio Buttons
Tom, July 21, 2004 - 9:25 am UTC
Hi Tom,
I was trying to do the same thing that one of the reviewer Job Miller did. Submitting an array of radio button groups. Each group will have 2 radio choices yes/no. You post a link which I assume it was an example. That link took me to a no page found error. Can you repost the link with correct/updated address to the documentation in regards to this subject?
Thank you.
Tom Chiou
July 21, 2004 - 9:43 am UTC
radio button array
Tom, July 21, 2004 - 12:59 pm UTC
Thank you, it's very helpful