Page 1 of 1
history saved on select menu?....uhh
Posted: Thu Jun 14, 2007 12:50 pm
by revocause
Hi,
I have a javascript drop-down (select menu) and when user selects all 8 product defining options , then it grabs variables, does the php math functions, blah blah. All of this part works great , but.. when the page reloads the $total value appears within an <input > text box. That part also works great.
Problem is = when page reloads, and spits out the total as it should , ALL the select menu choices are defaulted to "Please Select" on all 8 select menus.
How can i reload the page onChange .. and have the history of what the user selected, still showing.
THANK ya very much

..alrighty then
Posted: Thu Jun 14, 2007 6:25 pm
by feyd
You will have to select them for the user.
This will require the use of echo.
re- js history
Posted: Fri Jun 15, 2007 7:52 am
by revocause
echo the users selection , sounds logical kirk.. but where would i put this?
if(isset ) ?
too bad computers arent more intelligent , then i could enter = echo $wtf_user_just_did_prior_to_you_reading_this ;
can you give me an idea what this would look like, echoing the user selects, or a webpage i could read more about it?
thanks
Posted: Fri Jun 15, 2007 8:03 am
by feyd
When an option is preselected it will have the following in it.
ah
Posted: Fri Jun 15, 2007 8:55 am
by revocause
feyd | Please use 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]
I figured out one way , but it seems over complicated and mass code that i havent even put in my db fetches etc .
this way works, but it sucks.
Code: Select all
<?php
function makeSelectMenu1($menuName1, $options1, $chosen1) {
$list1 = '';
foreach ($options1 as $option1 => $text1) {
$selected1 = ($chosen1 == $option1) ? ' selected="selected"' : '';
$list1 .= " <option value=\"$option1\"$selected1>$text1</option>\n";
}
return "\n<select name=\"$menuName1\" id=\"$menuName1\">\n$list1</select>\n";
}
session_start();
$options1 = array(
'' => 'Choose Your Favorite Color',
'red' => 'I like Red',
'blue' => 'I like Blue',
'green' => 'I like Green'
);
$menuName1 = 'favoriteColor';
$chosen1 = '';
if (isSet($_POST[$menuName1])) $_SESSION[$menuName1] = $_POST[$menuName1];
if (isSet($_SESSION[$menuName1])) $chosen1 = $_SESSION[$menuName1];
$selectMenu1 = makeSelectMenu1($menuName1, $options1, $chosen1);
?>
<html>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo $selectMenu1; ?>
<br><br>
<form2 method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<?php echo $selectMenu2; ?>
<input type="submit" />
</body>
</html>
yeah that works but , imagine if i put in the calls to the database for the values etc ,that code will be like 2 gigbytes lol
is there a simple way to echo that back , like say something as in : selected="<?php echo selected ?>" ??
obviously thst doesnt work there but i mean it as an example for what would be more programmer friendly .
Thanks
feyd | Please use 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: Fri Jun 15, 2007 9:05 am
by feyd
Your code snippet is how it is done, generally.
Avoid PHP_SELF at all costs.
this is the problem though
Posted: Fri Jun 15, 2007 11:02 am
by revocause
ahh , but the whole problem I'm having is that I need a select menu where each <option> saves its history , AND
calls more than one value from database.
so example:
option1: 500
option2: 1000
option3: 1500
etc to 10,000
when user selects say option 2 . i need the value to be: baseweight, baseprice, quantity
because the option text for "1,000" is a representation of a quantity of a product.
when the user selects that they want "1,000"
I need php to get the 'baseweight' , 'quantity' (which would be 1,000 for option2) , and 'baseprice'.
and im tyring to figure out how to make option value call more than one value. and at the same time , keep that history refresh of the users
selections . Its a product calculator so thats the jist of it anyway.
so my question im stuck on is = how to call more than one value from database from one option in select menu.
and how to fit that code nicely in with the 'save history' of the selections.
Thanks for any help