PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
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]
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]
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.
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.
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.
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.
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