/    Sign up×
Community /Pin to ProfileBookmark

list / menu – how do I reload a page without loosing input data?

I am making a form.

The user have to choose between two options in a html list/menu.

Depending on what the user choose, I want the page to reload and update another list/menu with results that has with the list option the user just chose.

I have tried with this:

[code]<select name=”vehicle” id=”vehicle” onchange=”javascript:location.reload(true);”>
<option selected=”selected”>——–</option>
<option value=”cars”>Cars</option>
<option value=”mc”>MCs</option>
</select>

<select name=”manufacturer” id=”manufacturer”>
<?php
$vehicle= $_POST[‘vehicle’];
if($vehicle==”cars”)
echo “<option value=”ferrari”>Ferrari</option>”;
echo “<option svalue=”porsche”>Porsche</option>”;
if($vehicle==”mc”)
echo “<option value=”ducati”>Ducati</option>”;
echo “<option value=”suzuki”>Suzuki</option>”;
echo “<option svalue=”sawasaki”>Kawasaki</option>”;
?>
</select>
[/code]

I cannot use action=”” in the form tag because when the user is done he has to press the Next button to get to the next form, so the action tag is already in use.

How can I solve this?

to post a comment
PHP

10 Comments(s)

Copy linkTweet thisAlerts:
@micmania1Oct 04.2008 — Your not actually submitting the data, your just reloading the page. Therefore, there will be no POST data determining what the user has selected.

You need to submit the form or rethink your method of validation.
Copy linkTweet thisAlerts:
@RoxxorauthorOct 04.2008 — Ok, are there any other solutions? I really don´t know any other way.
Copy linkTweet thisAlerts:
@micmania1Oct 04.2008 — [code=php]<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="vehicle" id="vehicle" onchange="javascript:location.reload(true);">
<option selected="selected">--------</option>
<option value="cars">Cars</option>
<option value="mc">MCs</option>
</select>
</form>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<select name="manufacturer" id="manufacturer">
<?php
$vehicle= $_POST['vehicle'];
if($vehicle=="cars")
echo "<option value="ferrari">Ferrari</option>";
echo "<option svalue="porsche">Porsche</option>";
if($vehicle=="mc")
echo "<option value="ducati">Ducati</option>";
echo "<option value="suzuki">Suzuki</option>";
echo "<option svalue="sawasaki">Kawasaki</option>";
?>

</select>
</form>[/code]
Copy linkTweet thisAlerts:
@RoxxorauthorOct 04.2008 — Thanks, but I didn´t get it working.

I also changed the if statements and added "{" and "}" to surround the statements. But it didn´t help.

What else can I do?
Copy linkTweet thisAlerts:
@micmania1Oct 04.2008 — Please post your full script.
Copy linkTweet thisAlerts:
@RoxxorauthorOct 04.2008 — The full script is as follows:

&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt;
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;style type="text/css"&gt;
&lt;!--
.style20 {color: #333333; font-size: x-small; font-family: Verdana;}
--&gt;
&lt;/style&gt;
&lt;/head&gt;

&lt;body&gt;

&lt;table width="100&amp;#37;" border="0" cellpadding="0" cellspacing="0"&gt;

&lt;tr&gt;
&lt;td width="16%" height="40" class="style20"&gt;Vehicles*&lt;/td&gt;
&lt;td width="84%" class="style20"&gt;&lt;label&gt;

&lt;form action="&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;" method="POST"&gt;
&lt;select name="vehicle" id="vehicle" onchange="javascript:location.reload(true);"&gt;
&lt;option selected="selected"&gt;--------&lt;/option&gt;
&lt;option value="cars"&gt;Cars&lt;/option&gt;
&lt;option value="mc"&gt;MCs&lt;/option&gt;
&lt;/select&gt;&lt;/form&gt;
&lt;div align="left"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td height="25" class="style20"&gt;Manufacturer*&lt;br /&gt;
&lt;br /&gt;
City&lt;br /&gt;
&lt;br /&gt;
Zipcode&lt;/td&gt;
&lt;td class="style20"&gt;

&lt;form action="confirm.php" method="POST"&gt;
&lt;select name="manufacturer" id="manufacturer"&gt;
&lt;?php
$vehicle= $_POST['vehicle'];
if($vehicle=="cars")
{
echo "&lt;option value="ferrari"&gt;Ferrari&lt;/option&gt;";
echo "&lt;option svalue="porsche"&gt;Porsche&lt;/option&gt;";
}
else if($vehicle=="mc")
{
echo "&lt;option value="ducati"&gt;Ducati&lt;/option&gt;";
echo "&lt;option value="suzuki"&gt;Suzuki&lt;/option&gt;";
echo "&lt;option svalue="sawasaki"&gt;Kawasaki&lt;/option&gt;";
}
?&gt; <br/>
&lt;/select&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input class="form1" type="text" name="zipcode" id="zipcode" /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input class="form1" type="text" name="city" id="city" /&gt;
&lt;br /&gt;
&lt;input type="submit" name="next" id="next" value="Next" /&gt;
&lt;br /&gt;
&lt;/form&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td colspan="2" class="style20"&gt;&amp;nbsp;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td class="style20"&gt;&lt;label&gt;
&lt;div align="left"&gt;&lt;/div&gt;
&lt;/label&gt;&lt;/td&gt;
&lt;td class="style20"&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;/form&gt;
&lt;/body&gt;
&lt;/html&gt;
Copy linkTweet thisAlerts:
@micmania1Oct 04.2008 — Its because your reloading the page. You need to SUBMIT the form, not reload the page.
Copy linkTweet thisAlerts:
@RoxxorauthorOct 04.2008 — How do I submit the form from the select tag?
&lt;select name="vehicle" id="vehicle" onchange=?????"&gt;
Copy linkTweet thisAlerts:
@micmania1Oct 04.2008 — <form name="vForm"....

<select onchange="document.vForm.submit()"...
Copy linkTweet thisAlerts:
@RoxxorauthorOct 04.2008 — Thanks! When the form is updated, is there any way to save the input data in the other forms? Because if you start by filling in the data in the other forms and then make the selection in the list / menu, the inputs disappear. Can I get arount this problem somehow?
×

Success!

Help @Roxxor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...