Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Form Refresh with select boxes

Status
Not open for further replies.

AIX5L

Technical User
Joined
Jul 27, 2001
Messages
228
Location
CH
Hi

My Problem is i have a form with some Adressinformation.
In the Middle of the Form i have a select box with a onchange Javascript Function, which takes the Zip code and put the Cityname in the next Select box. The Problem is when i select the ZIP Select Box all data in my input boxes above.
The Selection is in the Same PHP Script as the Form.
How can i write a Script how keeps my entered Data ?

thanks
 
If the other fields are a part of the same form as your zipcode field, when that form is submitted, the other fields' data will but available to your PHP script as well as the zipcode.

Your script should conditionally supply the "value" attributes for the other fields.

Assuming you have a field called "name" and that you are using a POST-method form, something like:

Code:
print '<input type=&quot;text&quot; name=&quot;name&quot; value=&quot;';

if (isset($_POST['name'])
{
   print $_POST['name'];
}

print '&quot;>&quot;;

This way, if a form value has been submitted, the value will be preserved.

Want the best answers? Ask the best questions: TANSTAAFL!!
 
perhaps the solution at thread434-743971 give you an idea.

@sleipnir214 , if you use onchange for reload is the form then submitted also ??
 
Hi

I have still the same Problem, but i dont know whats wrong:
The Value Firma is selected in the Database:
plz_iz ist also selected in the database:
however the plz, or ort box is changed the value in Name will be cleared:

&lt;input type=&quot;TEXT&quot; NAME=&quot;NAME&quot; value=&lt;? echo $FIRMA; ?&gt;

&lt;select name=&quot;PLZ&quot; onchange=&quot;window.location.replace('&lt;? $PHP_SELF; ?&gt;?plz_id='+window.document.kunde.PLZ.value)&quot;&gt;

&lt;select name=&quot;ORT&quot; onchange=&quot;window.location.replace('&lt;? $PHP_SELF; ?&gt;?plz_id='+window.document.kunde.ORT.value)&quot;&gt;

How i can store the value in the Input Form Name ?

Thanks
 
Look at the following line:
Code:
&lt;input type=&quot;TEXT&quot; NAME=&quot;NAME&quot; value=&lt;? echo $FIRMA; ?&gt;
One thing you need is to double quote the Firma.

Also, what do you mean by however the plz, or ort box is changed the value in Name will be cleared:
You mean it should be cleared?

Altogether, I would change the approach to what sleipnir214 suggests:
Instead of changing the window.location submit the form. You can do that with client side scripting e.g. JavaScript.

Maybe you can explain your problem in more detail. If need, write in German.
 
Hi thanks for your reply
 
I do not exactly understand if your refreshing the page or not. If your not reloading the page and the form is being cleared this might be avoided by using return false clause
Code:
<select..... onchange="someJavaScriptFunction();return false;">

At least in my experience multiple event handles sometimes wipes out the form.

-Pete
Do you get a little guilty pleasure when a celebrity has a bad day?
Well then The Dead Pool is for you!
 
Hi

My form is refreshed by the function:
onchange="window.location.replace('<? $PHP_SELF; ?>?plz_id='+window.document.kunde.ORT.value)">

( But why, i don't know )

The return false; doesn't work.

If i need to submit the form, to reload the values, how i can replace the window.location and submit together ?
 
Some of the posts made yesterday vanished!

What you call 'refresh' is actually submitting the form with GET variables to the script. The page is redrawn.

The vars available in the new page are just the ones you pass as GET parameters - since you have no FIRMA in there it will be gone on the next page.

You can continue using the model you have. What you need to do is attach the other values also as GET parameters:
Code:
onchange="window.location.replace('<? $PHP_SELF; ?>?plz_id='+window.document.kunde.ORT.value)+'&firma='window.document.kunde.FIRMA.value">

However, I'd recommend to do it a little different.
You can send me an e-mail by sending a comment to faq434-3850 (click the send a comment link). I can help you in German.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top