Page 2 of 4

Reposting original question

Posted: Tue May 29, 2007 10:59 am
by revocause
Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Original Question
****************


hi, i cant figure out what the correct syntax or commands are for this. I made an HTML page , i would like the variables selected form drop down menus to then be sent to a PHP processing script, to do math and then send the resulting new variable back to the same HTML page and appear within an <input> text box . 


i made this stripped down version to show you. 
Here is the HTML page code: 


[syntax="html"]<HTML> 
<HEAD></HEAD> 
<body> 
<center> 
<FORM name="formx" method="POST" action="dropdown_handler.php"> 

<select name="a" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="0">1</option> 
                <option value=".10">2</option> 
                 </select> 

<br><br> 
<select name="b" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 


<br><br> 
<select name="c" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 

<br><br> 
<select name="d" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 

<br><br> 
<select name="f" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 

<br><br> 

<select name="g" STYLE="width: 110 px" onChange="submit(this.formx)"> 
                <option selected="selected" value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                  </select> 

<br><br> 

<input name="ans" type="text" size="5" readonly="readonly" value="0"> 

</form> 
</body> 
</html>



and here is the php processing script (i know this part is wrong, and possibly the HTML , the way im calling it .[/syntax]

Code: Select all

<?php 

$a = $_REQUEST('a[]'); 
$b = $_REQUEST('b[]'); 
$c = $_REQUEST('c[]'); 
$d = $_REQUEST('d[]'); 
$f = $_REQUEST('f[]'); 
$g = $_REQUEST('g[]'); 

function a_times_b () { 
   $e = ($a*$b) + ($a*$c) + ($a*$d) + ($a*$f) + $g; 
   $e = number_format ($total, 2); 
   return array ($e); 
} 
?>

Everah | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Tue May 29, 2007 11:01 am
by RobertGonzalez
I just answered your question. Posting it a second, again without using the correct bbCode tags, does not help anyone.

Re: response super

Posted: Tue May 29, 2007 11:02 am
by superdezign
We can scroll, you know. Rewording isn't reposting.

You have two choices. Sessions, or posting to the same page. Either way, your page will include PHP code.

Posted: Tue May 29, 2007 11:07 am
by revocause
I know theHTML page will require extra code, that isnt an issue.

I'm trying to work out how i can do that with php.

i had the HTML doing all those calculations in javascript.

but i was asking about how to do that in PHP , and i would like !! for that to be where either:
javascript calls php script.
form calls javascript that includes a php function
etc ..

because if i put anything else on that page, like say populating drop downs with states, or user input zip codes,
I dont want to have to include ALL that crap on the HTML page within the scripts.

Posted: Tue May 29, 2007 11:09 am
by RobertGonzalez
AJAX

response to angry responders

Posted: Tue May 29, 2007 11:09 am
by revocause
Uhh.. i just joined this forum today, Im a beginner in php.

instead of attacking and trying to annihilate people to get a leg up, it would be nice if this forum actually helped.

sorry about the 'code' tags not being there, Im still reading the rules and how to post.
.
overwhelming gang jump lol sheeeeeesh

Posted: Tue May 29, 2007 11:14 am
by RobertGonzalez
We usually help others that have tried to help themselves. We do actually want to help developers. It is why we are here.

Your initial question didn't make all that much sense, so you got a lot of feedback from members offering ways to achieve what you wanted to achieve. It was not exactly what you wanted to hear, but they were valid suggestions.

As for putting the processing code in a separate file, you could always do that and include() it in the header of the HTML page (similar in style to what I posted without all the code staring at you in the face). But ultimately you are going to need to have PHP or an AJAX/PHP solution in your form page.

response to everah

Posted: Tue May 29, 2007 11:19 am
by revocause
okay, but i looked over that example site i posted, and i dont see their site with include.headers , etc
otherwise i wouldve 'helped myself' by checking that.

Ive been looking for a solution to this problem for a week. I've tried many ways, and all i am asking for is how to pass the calculated
NEW variable (as a result of the php math script) .. and have it appear in the HTML page .

so that an onChange in the last <select> drop down , will trigger that page refresh ,with the new variable in the proper <input >text box.

I can make the php function work and echo it to a new page example = 'hello, world' ..lol

but i want the new variable passed into the <input> text box.

I've searched google, tried many variations. I wouldnt be here if i didnt try myself. I prefer working things out on my own first.

Posted: Tue May 29, 2007 11:23 am
by superdezign
The site you posted uses asp.

Code: Select all

<input type="text" value="<?php echo $yourCalculatedValue;?>"/>
PHP, my friend. :-p
It's the way life should be.

re super

Posted: Tue May 29, 2007 11:25 am
by revocause
I've tried that superdezign, and i didnt like that <?php etc.. actually appears in the input text box.

I prefer .php over .asp
mainly because the languages i know are javascript and php . :)

i just cant figure this darn thing out.

it has to be able to be done in php, to hell with .asp.

Re: re super

Posted: Tue May 29, 2007 11:27 am
by RobertGonzalez
revocause wrote:I've tried that superdezign, and i didnt like that <?php etc.. actually appears in the input text box.
Then set this value in a javascript function and use javascript to populate the input field.

For the record, I still fail to see why you do not want PHP code in the markup. At some point, you will always need PHP code in the mark up.

example site

Posted: Tue May 29, 2007 11:29 am
by revocause
Im making something that is very similar to that example site. Except, different <input options> not to do with printing (aka= different products)

do you know where i might look to see example code for that exact type of thing?

thanks

Posted: Tue May 29, 2007 11:35 am
by RobertGonzalez
That site is going to have been built very similar in nature to how we are suggesting you do it. The only difference is that it is built in .NET and is probably using the DataSet or DataGrid objects to fill their output instead of using PHP variable like we would do.

As for what you are trying to accomplish, if you look at that site, it is posting the form data back to itself (which we have suggested) and it is using that data in the form elements (as we have suggested). The only Javascript that site uses is to control the menus and handle a few form validation routines. So basically they do exactly what we have been suggesting you do.

so i tried what you say

Posted: Tue May 29, 2007 12:04 pm
by revocause
ok, I try what you said, I dont know if this includes everything you were referring to but here goes:
If not, could you explain.
and i hope i did the 'code' tags right for this post , if not forgive me, I'll get it.
thanks

Code: Select all

<HTML> 
<HEAD>

<?php 
$input_value = ''; 

if (!empty($_POST['field_to_calculate'])) 
{ 
    // Calculate 
    $input_value = $calculation; // This would have been handled by the math 
} 
?> 

</HEAD> 
<body> 
<center> 
<form method="post" action="<?php echo basename(__FILE__); ?>">  

<select name="a" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="0">1</option> 
                <option value=".10">2</option> 
                 </select> 

<br><br> 
<select name="b" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 


<br><br> 
<select name="c" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 

<br><br> 
<select name="d" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 

<br><br> 
<select name="f" STYLE="width: 110 px"> 
                <option value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                 </select> 

<br><br> 

<select name="g" STYLE="width: 110 px" onChange="submit"> 
                <option selected="selected" value="">Please Select</option> 
                <option value="1">1</option> 
                <option value="2">2</option> 
                  </select> 

<br><br> 

<input type="text" name="field_to_calculate" value="<?php echo $input_value; ?>" />

</form> 
</body> 
</html>

Posted: Tue May 29, 2007 12:17 pm
by revocause
finally got the '

Code: Select all

' thing. 

 simple tiny pop-up window could cure that for us 'stupid' people. 
in my opinion