Solved

passing the different form variables

Posted on 2000-04-11
5
213 Views
Last Modified: 2006-11-17
dear experts,

I have to design a form having drop down list of cities and various links to different categories.

Now I want if someone selects one city and clicks on the link of category another script should be invojed pasing the values of city and link on whichit was clicked.

I am briefly giving the two codes below.

-----------
<html><head><title>
Trying It! </title></head>
<body>
<form>
<select name=city>
<option selected>Ludhiana
<option>Delhi
<option>Calcutta
</select><p>
<a href="result.php3?city=$city&mcat=rest>Restaurant</a><p>
<a href="result.php3?city=$city&mcat=cloth>Cloth</a><p>
</form>
</body></html>


-----------------
#result.php3

<html><head><title>
Trying It! </title></head>
<body>
<?
echo "$city";
print "<p>";
echo "$mcat";
?>
</body></html>
0
Comment
Question by:tripat
  • 2
  • 2
5 Comments
 
LVL 8

Accepted Solution

by:
us111 earned 50 total points
ID: 2703635
<html>
<head>
Sure, it doesn't work, when you have an href your param is sent by the method GET, so the form is not sent.
I've added some javascript on your link in order to submit the form and to get the variables.

<title> Trying It! </title>
</head>
<body>
<form name="myform" action="result.php3" method="post">
  <select name="city">
    <option value="Ludhiana"  selected>Ludhiana</option>
    <option value="Delhi">Delhi</option>
    <option>Calcutta</option>
  </select>
  <input type="hidden" name="mcat">
  <p><a href="javascript:document.myform.mcat.value='rest';document.myform.submit();">Restaurant</a>
  <br><a href="javascript:document.myform.mcat.value='cloth';document.myform.submit();">Cloth</a>
  <p>
</form>
</body>
</html>


but as for me, the better solution will be

<title> Trying It! </title>
</head>
<body>
<form name="myform" action="result.php3" method="post">
  <select name="city">
    <option value="Ludhiana"  selected>Ludhiana</option>
    <option value="Delhi">Delhi</option>
    <option>Calcutta</option>
  </select>
 
  <input type="radio" name="mcat" value="rest"> Restaurant
  <br>
  <input type="radio" name="mcat" value="cloth"> Cloth

</form>
</body>
</html>
0
 
LVL 1

Expert Comment

by:mafweb
ID: 2703642
this will not work :-)

try the following:

<select> as above,

then

<input type=submit name=mcat value=Restaurant>
<input type=submit name=mcat value=Cloth>
0
 
LVL 8

Expert Comment

by:us111
ID: 2703733
hmm the first version works :))
I've tried it :)) I never post a comment without testing :)))

except my second version, I've forgotten
<input type=submit name="Send" value="Send">  in the form
0
 
LVL 1

Expert Comment

by:mafweb
ID: 2703775
sorry us111,

this referred to the initial posting :)
0
 
LVL 1

Author Comment

by:tripat
ID: 2714796
thanks to both, but according to my need javascript has worked fine.

0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question