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.

164 Like 23 Dislike
Previous php-forum Next php-forum
Other php-forum

How to return to a previous page after running a PHP script
I'm having a bit of a melt down here because I think this should be really easy but can't work it ou

Progress bar tracking file downloads
Hey guys, was wondering if there was a way to track how far a file has been downloaded. I know there

DateObject and Nulls
Hi all,

I have an array mapped to a value object. One of the items in the array is a PHP Date

puting for loop in 1 value
hi ,

how do i put this code in 1 value:
Code: <?php
for ($i=1; $i<=5; $i

Calander Basic Spript help
hi, just starting out with PHP and have the following script:

<?php
//This gets t

Secure pages Sessions vs. Cookies & session_destroy() help
Im new here and new to PHP, I hope you can help me with some questions.

Im writing my web ap

Why do I get this error?
Error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or

want to add a break after a certain amount of characters
i was wondering how to add a break in a blog post after a certain amount of characters... any idea o

search function
HI guys,

if anyone could point us in the right direction of how to do this, or provide some t

Check before inserting in DB ???
This is my code
---------------
if ( $_POST ['Submit'])
{{
$username = $_POST ['usernm

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