/    Sign up×
Community /Pin to ProfileBookmark

cant get post value for second dropdown list..

[CODE]index.php
<!DOCTYPE html>
<!–
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
–>
<html>
<head>
<title>Main Page</title>
<meta charset=”UTF-8″>
<meta name=”viewport” content=”width=device-width, initial-scale=1.0″>
<script>
function getddl1v()
{
var a=document.getElementById(“dbase”).value;
// alert(a);
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”getddl2v.php?q=”+a,true);
xmlhttp.send();
}

function showtables()
{
var a=document.getElementById(“dbase”).value;
// alert(a);
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject(“Microsoft.XMLHTTP”);
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById(“txtHint”).innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open(“GET”,”getddl2v.php?q=”+a,true);
xmlhttp.send();
}

</script>
</head>
<body onload=”getddl1v()”>
<form name=”f1″ action=”wel.php” method=”post” target=”_blank”>
<select id=”dbase” name=”dbase” onchange=”showtables()”>
<?php
$link = mysqli_connect(‘localhost’, ‘root’, ‘cutiepie_100′,’people’)
or die(“Could not connect database”);
$result=mysqli_query($link, “show databases”);
while($row= mysqli_fetch_array($result))
{
echo “<option value='”. $row[‘Database’]. “‘/>” . $row[‘Database’] . “</option>”;

}
?>

</select>
<div id=”txtHint”></div>

<textarea name=”skills” placeholder=”skill or item or spec”>java</textarea>
<textarea name=”city” placeholder=”city”></textarea>
<textarea name=”region” placeholder=”region”></textarea>
<textarea name=”country” placeholder=”country”></textarea>
<input type=”text” name=”lat” placeholder=”Latitude in degrees”>
<input type=”text” name=”long” placeholder=”Longitude in degrees”>
<input type=”text” name=”dist” placeholder=”Distance”><br>
<input type=”text” name=”file” placeholder=”Genearted filename”>
<input type=”submit” value=”(1) Show Results” name=”results”>
<input type=”submit” value=”(2) Update Table” name=”update”>
<input type=”submit” value=”(3) Make E-mail CSV” name=”csv”>
<input type=”submit” value=”(3) Make Phone Number CSV” name=”phone”>

<input type=”submit” value=”Get person Info with Deposit<Bid” name=”less”>

</form>
<form action=”wel.php” target=”_blank” method=”post”>
<input type=”text” placeholder=”Database” name=”db1″ value=”people”>
<input type=”text” name=”table1″ placeholder=”Table containing person data”>
<input type=”text” placeholder=”Sno” name=”sno”>
<input type=”text” name=”amount” placeholder=”Deposit amount”>
<input type=”submit” value=”Make Deposit” name=”deposit”>
</form>

</body>
</html>

[/CODE]

[CODE]getddl2v.php
<?php

$q=$_GET[‘q’];

//echo $q;

$con=mysqli_connect(“localhost”,”root”,”cutiepie_100″,$q);
if (mysqli_connect_errno())
{
echo “Failed to connect to MySQL: ” . mysqli_connect_error();
}

$abc=mysqli_query($con,”use $q”) or die(‘cannot show tables’);

$result=mysqli_query($con,”show tables”);
echo “<select>”;
while($row= mysqli_fetch_array($result))
{
echo “<option value='”. $row[0]. “‘/>” . $row[0] . “</option>”;

}
echo “</select>”;

?>
[/CODE]

i have these codes……the selection from select “dbase” changes value of div select using ajax…

but now i want to post both selected values to someother php script…first “dbase” is within form tags but difficult to get second dropdown list in div because name attribute of div tag doesnot exist..please tell how can i get both values

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@deathshadowSep 14.2014 — You would probably also want to return the OPTION's value, not the SELECT's.

var

e = document.getElementById('dbase');

a = e.options[e.selectedIndex].value;

That's probably what you were doing wrong. You don't use the SELECT's value, that doesn't exist. OPTION have values so you use the [i]selectedIndex[/i] attribute to point into the [i].options[/i] attribute, which is a list of the OPTION inside the SELECT.

Hope this helps.

Would probably also help if you got rid of the TARGET attribute which is accessibility trash (why it was deprecated in the first place) and had a proper block level container (like a FIELDSET) inside your form around the elements -- even if the HTML5-tards have dialed the clock back to 1997 on that.
Copy linkTweet thisAlerts:
@ankit1122authorSep 15.2014 — no i want to get value of selected item in second dropdown created in getddl2v.php....that selected item i wil use in index.php to post to some other php script
Copy linkTweet thisAlerts:
@deathshadowSep 15.2014 — so give it an ID and target it!

Though really you're kind-of wasting time sending markup client side. I'd send JUST the data and build the select and its options client-side using the DOM.
Copy linkTweet thisAlerts:
@ankit1122authorSep 15.2014 — can u give hint how can i do this?
×

Success!

Help @ankit1122 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...