CodeCharge Studio
search Register Login  

Visual Web Reporting

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> PHP

 need quick data lookup within PHP without a database

Print topic Send  topic

Author Message
bigtoe

Posts: 115
Posted: 09/03/2004, 4:41 PM


I have 2 rows of radio buttons.

The 1st row is pounds (lbs).
It contains the values 4, 5, 6 ... 13

The 2nd row is ounces (oz).
It contains the values 0.0, 0.5, 1.0, ... 15.5

The user should click one value from each row.
The I need to put the equivalent weight in grams in a text box.
I have the whole equivalent table on hand.

I am not a PHP expert, how can I
populate the text box with 1814 gms
if 4 is selected from the 1st row
and 0.0 is selected from the 2nd row

I don't mind putting the whole lookup table in the PHP code.
It is not a big table and will be faster than a database lookup.







View profile  Send private message
bigtoe

Posts: 115
Posted: 09/03/2004, 4:45 PM

I thought I might insert the PHP code in the "On Click" event for each radio button.

Would this be the right way to go?
View profile  Send private message
Karsten


Posts: 57
Posted: 09/03/2004, 8:16 PM

hi bigtoe,


put your calculation in the textbox , to do this use the
control source type -> code expression. you have to deal with the function CCGetFromGet("varname") because you have to refresh the page for calculation. you could also use a customcode action.

dont put code in one or both radiobutton on click events, why?
because the page would refresh on each klick on a radiobutton, this looks unproffesional and you confuse the user for sure, better make an OK button to refresh the page.

however: im from germany i dont know the calculation of pounds/oz/grams if you write me how many oz 1 pound and how many grams 1 oz is i could write you the calculationstring

look in helpfile for CCGetFromGet function(you can get the radiobutton values with it after a refresh).and with this data you have to do your calculation in the textbox controlsource codeexpression or customcode.
(event before show, and use function SetValue)
if you want i could show you via remotedesktop from MSN Messenger how i mean to do such a functionality add me in MSN messenger if you want ->
entwicklung@fivea.de

Regards

Karsten






_________________
If one gives up, he told himself he failed.
View profile  Send private message
Karsten


Posts: 57
Posted: 09/03/2004, 8:26 PM

of cause you could also use the action -> Retrieve value for Control(in an event)
but in the end it dont really matters (there are many events you could use for do the calculation within) but NOT the events of the radiobuttons please!! :-)
the mainpart is the CCGetFromGet thing and the calculation of grams/oz/pounds

as i said, im glad if you invite me to help



_________________
If one gives up, he told himself he failed.
View profile  Send private message
Karsten


Posts: 57
Posted: 09/03/2004, 8:32 PM

to be absolute correct:the on click event of the radio is a Clientside event, there you cannot execute php directly without refresh the page, and as i said, dont use this event, its mainly thought for javascript or a pagerefresh...

damn i would develop this for you :-D

_________________
If one gives up, he told himself he failed.
View profile  Send private message
bigtoe

Posts: 115
Posted: 09/03/2004, 10:22 PM


Karsten,

Here is part of the table:
4 lbs 0.0 oz = 1814 gms
4 lbs 0.5 oz = 1829 gms
4 lbs 1.0 oz = 1843 gms
5 lbs 0.0 oz = 2268 gms
5 lbs 0.5 oz = 2282 gms
5 lbs 1.0 oz = 2296 gms

This means:
if radiobutton1 = 4 and radiobutton2 = 0.0 then textbox3 gets 1814 gms
if radiobutton1 = 4 and radiobutton2 = 0.5 then textbox3 gets 1829 gms
if radiobutton1 = 4 and radiobutton2 = 1.0 then textbox3 gets 1843 gms
if radiobutton1 = 5 and radiobutton2 = 0.0 then textbox3 gets 2268 gms
if radiobutton1 = 5 and radiobutton2 = 0.5 then textbox3 gets 2282 gms
if radiobutton1 = 5 and radiobutton2 = 1.0 then textbox3 gets 2296 gms

If you can help me with these 6 conditions in PHP, I can do the rest.
I agree, I want to avoid a page refresh.

Thanks.

View profile  Send private message
bigtoe

Posts: 115
Posted: 09/03/2004, 10:32 PM

Sorry, I was not thinking.
I understand that I cannot use PHP for client side.

But I still want to avoid a page refresh.
View profile  Send private message
Karsten


Posts: 57
Posted: 09/04/2004, 1:02 AM

ok we have to clear up things:

1. if you dont want any page refresh we have to use javascript

2. if you accept 1 page refresh it can be done completely in php

BUT when i should tell you how to do this in java, i want to show you
by MSN Messenger because thats more to write down.even with php its not trivial.

also i still have to clear up:
if i look above, i calculate that 1 lb is 453,5 grams and so 1 oz is 29 grams

ok we got the factors.

so let us write a function wich calculates lb->oz and oz-> grams
therefore the mathematics are the following

if lb->oz lb*453,5/29

if oz->grams oz*29

ok so may you add me to MS netmeeting we can
program the function together and implemet it in your project?
its a bit to write and to explain, would be better you see it live because i think you could run to trouble if you dont familar with javascript.

i dont know how urgent you need that solution but it needs a bit time because of the much radiobuttons, maybe we should do a trick so we dont need to catch all the onclick events of a radio, maybe just those of the table row they are in. you see its not so trivial
i know how but you cant use it if i write it down here bacause i know nothing more about your project than the calculation factors and names of radiobuttons.
i would need much more info for a complete solution, especialy i need to see the html source.

in short i need to see your project to help you fast and sure,and correct. add me in microsoft netmeeting(windows messenger) click extras->add contact so we can chat and remotely work ->entwicklung@fivea.de

i dont want to spy your passwords or anything!!! i dont want to steal your ideas or anything i just help ppl in this forum i done this before and i do that in future.
-> read my post "offering remote help"

hope to hearing from you soon!!

Karsten from germany


_________________
If one gives up, he told himself he failed.
View profile  Send private message
DonB
Posted: 09/04/2004, 9:55 AM

Assuming you have two sets of radio buttons named "r1" and "r2", and a
textbox named "answer" contained within a form named "theform":

add the this event

onclick='recalc(document.theform);'

to both radio buttons

and put the following two javascript functions into the <head> of your page:

function getval(frm,ctl) {

var retval = 0;
for (var i=0;i<ctl.length;i++) {
if (ctl.checked=="1") {
retval = parseInt(ctl.value)
}
}
return retval
}
function recalc(frm) {
document.getElementById("answer").value = getval(frm,frm.r1) +
getval(frm,frm.r2);
}

Kind of sloppy coding, but it illustrates the concept. Each time you click
on either set of radio buttons, the selected values from both are extracted,
summed, and stored in the textbox. Of course, your "recalc" is going to do
a bit more arithmetic to calculate the number of grams.
--
DonB

http://www.gotodon.com/ccbth


"bigtoe" <bigtoe@forum.codecharge> wrote in message
news:54139011e99ba8@news.codecharge.com...
>
> I have 2 rows of radio buttons.
>
> The 1st row is pounds (lbs).
> It contains the values 4, 5, 6 ... 13
>
> The 2nd row is ounces (oz).
> It contains the values 0.0, 0.5, 1.0, ... 15.5
>
> The user should click one value from each row.
> The I need to put the equivalent weight in grams in a text box.
> I have the whole equivalent table on hand.
>
> I am not a PHP expert, how can I
> populate the text box with 1814 gms
> if 4 is selected from the 1st row
> and 0.0 is selected from the 2nd row
>
> I don't mind putting the whole lookup table in the PHP code.
> It is not a big table and will be faster than a database lookup.
>
>
>
>
>
>
>
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

bigtoe

Posts: 115
Posted: 09/05/2004, 3:58 AM

Hi DonB,

I did this but I get an Error in my browser.

A Runtime Error has occurred.
Do you wish to Debug?
Line 33
Error: 'document.getElementById(...)' is not an object

What do I do?

View profile  Send private message
DonB
Posted: 09/05/2004, 7:31 AM

Make sure you have id='answer' in the <input> element where the value is to
be written.

--
DonB

http://www.gotodon.com/ccbth


"bigtoe" <bigtoe@forum.codecharge> wrote in message
news:5413af166c5b46@news.codecharge.com...
> Hi DonB,
>
> I did this but I get an Error in my browser.
>
> A Runtime Error has occurred.
> Do you wish to Debug?
> Line 33
> Error: 'document.getElementById(...)' is not an object
>
> What do I do?
>
>
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

bigtoe

Posts: 115
Posted: 09/05/2004, 5:46 PM

I did that and the Error message is gone.
That's good.
But the answer is not being updated.

Here is the input element after I appended the id
<input
name="{F_nbkx_Weight_gms_Name}"
value="{F_nbkx_Weight_gms}"
id="F_nbkx_Weight_gms">

I set the default value to "none" in CCS.
If I click on the radio buttons,
the "none" value does not get replaced.

Also, I inserted alert("messages");
in the javascript functions to trace the flow.
Specially in the for loop:

for (var i=0;i<ctl.length;i++) {
alert(i);
if (ctl.checked=="1") {
alert("checked");
retval = parseInt(ctl.value);
}
}

I can see the loop goes from 0 to 10 (via the alert
function) because of the 11 radio buttions.
Which means the onclick is working and the function is being called.

But I never see the alert("checked"); being executed.
What did I miss?

View profile  Send private message
bigtoe

Posts: 115
Posted: 09/05/2004, 6:41 PM

Ok, I figured it out.
The index "i" was not specified correctly.
With the following change:

  
  
    if (ctl[ i ].checked) {  
                                                                   alert("checked");  
  
          retval = parseInt(the_control[ i ].value);  
  
                                                                   alert(retval);  
         break;  
    }  
  


I can now see the alert("checked"); message.
But the alert(retval); returns the checked value.
And the "none" value still does not get replaced.
View profile  Send private message
DonB
Posted: 09/05/2004, 7:56 PM

You must have something coded wrong, or your browser doesn't behave like
mine. Here's the entire page that works for me:

<html>
<head>
<title>
radiotest
</title>
<script language="JavaScript">

function getval(frm,ctl) {

var retval = 0;
for (var i=0;i<ctl.length;i++) {
if (ctl.checked=="1") {
retval = parseInt(ctl.value)
}
}
return retval
}
function recalc(frm) {
document.getElementById("answer").value = getval(frm,frm.r1) +
getval(frm,frm.r2);
}
</script>
</head>
<body>
<!-- BEGIN Record testform -->
<form name="{HTMLFormName}" action="{Action}" method="post">
testform
<table>
<!-- BEGIN Error -->
<tr>
<td colspan="2">
{Error}
</td>

</tr>

<!-- END Error -->
<tr>
<th>
Lbs
</th>

<td>
<!-- BEGIN RadioButton r1 -->
<input type="radio" value="{Value}" id="r1"
onclick="recalc(document.testform);" name="{r1_Name}" {Check}>{Description}
<!-- END RadioButton r1 -->
 
</td>

</tr>

<tr>
<th>
Oz
</th>

<td>
<!-- BEGIN RadioButton r2 -->
<input type="radio" value="{Value}" id="r2"
onclick="recalc(document.testform);" name="{r2_Name}" {Check}>{Description}
<!-- END RadioButton r2 -->
</td>

</tr>

<tr>
<td>
</td>

<td>
<input value="{answer}" id="answer" name="{answer_Name}">
</td>

</tr>

<tr>
<td align="right" colspan="2">
<!-- BEGIN Button Button_Insert -->
<input type="submit" value="Add" name="{Button_Name}">
<!-- END Button Button_Insert -->
<!-- BEGIN Button Button_Update -->
<input type="submit" value="Submit" name="{Button_Name}">
<!-- END Button Button_Update -->
<!-- BEGIN Button Button_Delete -->
<input type="submit" value="Delete" name="{Button_Name}">
<!-- END Button Button_Delete -->
 
</td>

</tr>

</table>
</form>
<!-- END Record testform -->
</body>
</html>

--
DonB

http://www.gotodon.com/ccbth


"bigtoe" <bigtoe@forum.codecharge> wrote in message
news:5413bc032297bd@news.codecharge.com...
> Ok, I figured it out.
> The index "i" was not specified correctly.
> With the following change:
>
>
  
>  
>     if (ctl[ i ].checked) {  
>  
> alert("checked");  
>  
>           retval = parseInt(the_control[ i ].value);  
>  
>  
> alert(retval);  
>          break;  
>     }  
>  
> 
>
>
> I can now see the alert("checked"); message.
> But the alert(retval); returns the checked value.
> And the "none" value still does not get replaced.
> ---------------------------------------
> Sent from YesSoftware forum
> http://forums.codecharge.com/
>

bigtoe

Posts: 115
Posted: 09/05/2004, 7:58 PM

ok, i figured it out
it was a javascript assignment issue
here is the full code of the onclick


  
  
function get_radio_value(the_form,radiobutton_control) {  
  
   var return_the_checked_value = 0;  
  
   // check each radio button  
   for (var i=0;i<radiobutton_control.length;i++) {  
  
      if (radiobutton_control[ i ].checked) {  
  
         // if the a radio button is checked then get the value and stop  
         return_the_checked_value = parseInt(radiobutton_control[ i ].value);  
         break;  
      }  
   }  
  
   return return_the_checked_value  
}  
  
  
function calculate_grams(the_form) {  
  
   the_form.F_nbkx_Weight_gms.value = get_radio_value(the_form,the_form.F_nbkx_Weight_lbs);  
  
}  
  
  


Thanks for all the help.
View profile  Send private message
bigtoe

Posts: 115
Posted: 09/05/2004, 8:01 PM

Of course, I did not do the lbs and oz to grm conversion.
But that is easy now that this is working.

The main challenge was to get the onclick and assignments to work.
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

PHP Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.