Solved

passing the different form variables

Posted on 2000-04-11
5
190 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
Comment Utility
<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
Comment Utility
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
Comment Utility
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
Comment Utility
sorry us111,

this referred to the initial posting :)
0
 
LVL 1

Author Comment

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

0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to count occurrences of each item in an array.

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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now