history saved on select menu?....uhh

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

history saved on select menu?....uhh

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You will have to select them for the user.

This will require the use of echo.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

re- js history

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

When an option is preselected it will have the following in it.

Code: Select all

selected="selected"
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

ah

Post by revocause »

feyd | 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]


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

,

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]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your code snippet is how it is done, generally.

Avoid PHP_SELF at all costs.
revocause
Forum Commoner
Posts: 94
Joined: Tue May 29, 2007 9:37 am

this is the problem though

Post 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
Post Reply