Forum Moderators: open

Message Too Old, No Replies

form tags

usage of form tags

         

swati

12:42 pm on Sep 28, 2004 (gmt 0)

10+ Year Member



Can i use a form tag inside another form tag?

StupidScript

4:25 pm on Sep 28, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Nope. Forms are distinct objects which are not to be nested.

swati

8:53 am on Sep 29, 2004 (gmt 0)

10+ Year Member



I have got another question:

I have 2 drop down lists on a page. Depending on the option selected by the user from the lists, records are displayed on the page. The user has to click on a 'submit' button which refreshes the page with the relevant records.
But when the submit button is pressed the drop down lists do not display the value the user selected, but get reset to their initial values.
Any help wud be appreciated.

BlobFisk

10:12 am on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi swati,

A very similar issue is being discussed here [webmasterworld.com].

In your case, since you are round tripping the page, you could set the selected attribute on the select list to the users choice.

HTH

swati

12:24 pm on Sep 29, 2004 (gmt 0)

10+ Year Member



Sorry for this stupid question but i dont know how i could set the user's choice as selected.
I can obtain the user's choice in a variable but how do i set that option as selected?

Thanks

BlobFisk

1:37 pm on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<select>
<option value="someValue">Text A</option>
<option value="someValue">Text B</option>
<option value="someValue" selected>Text C</option>
</select>

In this cased the third option will be selected. This is the value for HTML4.01.

HTH

swati

3:40 pm on Sep 29, 2004 (gmt 0)

10+ Year Member



Oh ok...but i have the following code

<select name="site[]" onChange="MM_jumpMenu('parent',this,0)" size="1">
<option>keanu reeves</option>
<option>tom cruise</option>
<option>johny depp</option>
<option selected>ALL</option>
</select>

after this i have a button:
<input type="submit" name="Submit" value="GO->">

the user can select something from the drop down list and click on "go" to see a list of films of the chosen actor on the same page as the drop down list.
Suppose the selected is "ALL". Now the user selects 'tom cruise' and hits GO. Then the page gets refreshed and displays list of his movies in the same page however the drop down list is still showing 'ALL'. I want it to show "tom cruise".

Its possible?
me a little confused.
Thanks a lot for all the help.

StupidScript

4:40 pm on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need to use some other code to (a) determine which entry the user selected on the first page and (b) indicated that entry as "selected" on the result page.

For this you can use Javascript, PERL, PHP, ASP, or any number of scripting/programming languages.

1) Page 1: User selects item from list
2) Page 1: User clicks "GO->" (or MM script goes automatically)
3) Request is sent to server, including selected item
4) Page is put together at the server:
You could use PHP, ASP, PERL, ColdFusion, etc. at this point to determine the selection (you are already using it to get the data/page) and write the Page 2 code with the proper item selected.
5) Page is delivered to client.
6) Page 2: Contains content re: selected item
You could use Javascript, VBScript, etc. at this point to determine the selection from the previous page by grabbing the item from the URI and dynamically modifying the default selection to the one in the URI.

What web languages do you use?

swati

5:20 pm on Sep 29, 2004 (gmt 0)

10+ Year Member



I am using PHP-MySQL and dont know javascript...

swati

5:23 pm on Sep 29, 2004 (gmt 0)

10+ Year Member



what do you mean when you say 'MM script goes automatically'?

How can I update the page without making the user click on 'GO->' button?

Thanks

StupidScript

7:27 pm on Sep 29, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



PHP ... cool! And easy to do what you want. I mentioned the MM script, because it looks like when someone changes the select menu, it automatically does SOMEthing ... often submitting the form. I modified the code, below to do the same. I am assuming you are using the form's method="post" for the purposes of this illustration:

Page 1:

<select name="site[]" onChange="this.form.submit()">
<option />keanu reeves
<option />tom cruise
<option />johny depp
<option selected />ALL
</select>
<input type="submit" name="Submit" value="GO->">

Page 2 (where the form's "action" points to):

<select name="site[]" onChange="this.form.submit()">
<?php
switch ($_POST["site[]"]) {
case "1":
print "<option selected />keanu reeves\n";
print "<option />tom cruise\n";
print "<option />johny depp\n";
print "<option />ALL\n";
break;
case "2":
print "<option />keanu reeves\n";
print "<option selected />tom cruise\n";
print "<option />johny depp\n";
print "<option />ALL\n";
break;
case "3":
print "<option />keanu reeves\n";
print "<option />tom cruise\n";
print "<option selected />johny depp\n";
print "<option />ALL\n";
break;
case "4":
print "<option />keanu reeves\n";
print "<option />tom cruise\n";
print "<option />johny depp\n";
print "<option selected />ALL\n";
break;
}
?>
</select>

That ought to do it!

swati

7:19 am on Sep 30, 2004 (gmt 0)

10+ Year Member



in my case the form points to itself so wat should i do?
sorry to be bugging u so much

swati

8:36 am on Sep 30, 2004 (gmt 0)

10+ Year Member



Hello!
me again..
I tried putting just 'this.form.submit()' in the onChange property.
Let me explain what happens.
Actually i have 2 drop down lists (i told u about one to simplify matters).
1. contains names of actors
2. contains years

So the user can view records filtered by criteria of names of actors as well as the year.

The 2 lists have options as shown below.
Keanu Reeves
Tom Cruise
Johny Depp

1990-1995
1996-1998
1999-2003

Since i have put this.form.submit() the change is immediate without the need for a submit button.
But the issue is that when u select johny depp (and the default is keanu reeves) the page immediately gets refreshed and the value in the drop down list becomes keanu again.
So this doesnt allow me to select johny depp for a particular year.
It has immediately changed to its default value.
My code looks as follows.
<td>Site:
<select name="site[]" onChange="this.form.submit()" size="1">
<option />FMDC
<option />PMDC
<option />ERDC
<option selected />ALL
</select>
</td>
<td>Year:
<select name="year[]" onChange="this.form.submit()" size="1">
<option>1990-1995</option>
<option>1996-1998</option>
<option>1999-2003</option>
</select>
</td>

And yes its all inside a form with method="POST"

wheres the problem?

StupidScript

4:35 pm on Sep 30, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hallo,

Not a big problem, although without seeing the rest of the form code it's a little tough to figure out why the drop down menus are being treated as arrays. I'm electing NOT to treat them as arrays. Also, the default "size" of a SELECT menu is "1" ... no need to put that in there.

Here are more code changes, taking out the auto-submit function, which means the user must click the submit button. I'm only printing a few lines of code, here, so you'll need to put them in the appropriate place(s) in your actual page:

===snipsnip===
<form action="<?=$PHP_SELF?>" method="post">
<table><tr><td>Site:
<select name="site">
<?
# Check for the "site" parameter in the URI
switch ($_POST["site"]) {
# If "site=ALL", do this:
case "ALL":
?>
<option selected />ALL
<option />FMDC
<option />PMDC
<option />ERDC
<?
break;
# If "site=FMDC" do this:
case "FMDC":
?>
<option />ALL
<option selected />FMDC
<option />PMDC
<option />ERDC
<?
break;
# etc ...
case "PMDC":
?>
<option />ALL
<option />FMDC
<option selected />PMDC
<option />ERDC
<?
break;
case "ERDC":
?>
<option />ALL
<option />FMDC
<option />PMDC
<option selected />ERDC
<?
break;
# If there is NO "site" parameter in the URI, do this:
default:
?>
<option selected />ALL
<option />FMDC
<option />PMDC
<option />ERDC
<?
}
# End of what to do with "site" in the URI
?>
</select>
</td>
<td>Year:
<select name="year">
<?
# Check for the "year" parameter in the URI
switch ($_POST["year"]) {
# If "year=1990-1995" do this:
case "1990-1995":
?>
<option selected />1990-1995
<option />1996-1998
<option />1999-2003
<?
break;
# If "year=1996-1998" do this:
case "1996-1998":
?>
<option />1990-1995
<option selected />1996-1998
<option />1999-2003
<?
break;
# etc ...
case "1999-2003":
?>
<option />1990-1995
<option />1996-1998
<option selected />1999-2003
<?
break;
# If there is NO "year" parameter in the URI, do this:
default:
?>
<option selected />1990-1995
<option />1996-1998
<option />1999-2003
<?
}
# End of what to do with "year" in the URI
?>
</select>
</td>
<td>
<input type="submit" value="GO->">
</td>
</tr></table>
===snipsnip===

(To test this, copy everything between the "===snipsnip==="s and paste it into a new file. Save it and upload it to your server, then check the page in your browser.)