php ajax - two drop down list with a submit button


Posted on 16th Feb 2014 07:03 pm by admin

i have created a form with 2 drop-down list and a submit button. I would like to know how to pass the selected values from the two drop down list to external javascript file and only will pass it after i clicked the submit button? Below is the example of my code:

<html>

<head>
<script type="text/javascript" src="selecttidmth.js"></script>

<title>Report</title>
</head>

<body>
<form action="getID.php" method="get">
Magazines:
<select name="tid" onchange="showTid(this.value)">
<option value="">---Select---</option>
<option value="1">Magazine A</option>
<option value="2">Magazine B</option>
</select>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;

Month:
<select name="mth" onchange="showMonth(this.value)">
<option value="">---Select---</option>
<option value="Jan">January</option>
<option value="Feb">February</option>
<option value="Mar">March</option>
<option value="Apr">April</option>
<option value="May">May</option>
<option value="Jun">June</option>
<option value="Jul">July</option>
<option value="Aug">August</option>
<option value="Sept">September</option>
<option value="Oct">October</option>
<option value="Nov">November</option>
<option value="Dec">December</option>
</select> &nbsp; &nbsp;

<input type="submit" name="submit" Value="Submit">
</form>

<div id="txtHint"></div>
</body>
</html>

//javascript code

var xmlhttp;

function showTid(str)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}

function showMonth(str2)
{
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Browser does not support HTTP Request");
return;
}

var url="getID.php";
url=url+"?q="+str+"?m="+str2;
url=url+"&sid="+Math.random();
xmlhttp.onreadystatechange=stateChanged;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}

Hope someone here can help me out. Thanks in advance.

No comments posted yet

Your Answer:

Login to answer
164 Like 23 Dislike
Previous forums Next forums
Other forums

Need help with simple code, back and forward buttons.
Basically, I have a set of pages in a folder, which have the title somephrasehere_09.php, somephrase

Not connecting to DB using ruby, error:env.c:257:in oci8lib.so: ORA-12154:
Hi All,

I am trying to connect to the database server from the client server using ruby and f

Passing variables with pagination - iterating through unique id per link
Hi everyone,
I have seen a few topics like this one. Still cant find the specific thing, so I am

Multiple while loops
I have several DB queries that I know should be returning results and aren't. I have a feeling it ha

problems with search form numerical "between" sending by php
I am trying to display the results of a search, on a sql database, on a web page. I set up html &quo

Parse Error
Hi Guys,

I have a function in my class which returns a string link variable. The problem is i

single page with referrer to show correct page
I have a simple website with a couple of different pages. I would like to be able to in a div tag w

Help with search.php
Hello All

I need the search engine on a site I am building at the moment to display the searc

distinct rows
Hi
version 10.2.0.3

I have a query output something like the following

ID

list files from folder, only one for each date
I have many files in a folder and wish to only list one of each date

these are the file names

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash