Board index   FAQ   Search  
Register  Login
Board index php forum :: HTML JavaScript

populate from drop down menu to textfield

Javascript coding ..

Moderators: macek, egami, gesf

populate from drop down menu to textfield

Postby syudZack83 » Tue Jun 03, 2008 5:10 pm

hi all...

i have a problem..i want to display the detail that i selected from drop down menu into textfield..

let say, in the drop down menu i select rider_name "Alex"..so the next field which is textfield, will display the phone number of the name selected..

i have tried before, but it won't works..

here part of my coding..

entryform.php
<script language="javascript" type="text/javascript">
function getXMLHTTP() { //fuction to return the xml http object
var xmlhttp=false;
try{
xmlhttp=new XMLHttpRequest();
}
catch(e) {
try{
xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){
try{
req = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e1){
xmlhttp=false;
}
}
}

return xmlhttp;
}

function getRider(club_name){

var strURL="findRider2.php?club="+club_name;
var req = getXMLHTTP();

if (req) {

req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('riderdiv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}

function getRiderPhone(club_name,rider_name){

var strURL="findRiderPhoneNumber.php?club="+club_name+"&rider="+rider_name;

var req = getXMLHTTP();

if (req) {

req.onreadystatechange = function() {
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
document.getElementById('riderPhonediv').innerHTML=req.responseText;
} else {
alert("There was a problem while using XMLHTTP:\n" + req.statusText);
}
}
}
req.open("GET", strURL, true);
req.send(null);
}
}
<td height="449"><form id="form1" name="form1" method="post" action="entryFormProcess1.php">
<table width="600" border="1" align="center" cellpadding="6" cellspacing="0" bordercolor="#C6BF93">
<tr>
<td width="205" bgcolor="#FFFFFF"><div align="right" class="style10 style25"><span class="style7">CLUB/COUNTRY</span></div></td>
<td width="379" bgcolor="#BDD56A"><select name="club" onChange="getRider(this.value)">
<option value="">Select Club</option>
<?
mysql_select_db($database_link, $link);
$query_club = "SELECT * FROM club order by club_name ASC";
$club = mysql_query($query_club, $link) or die(mysql_error());
$row_club = mysql_fetch_assoc($club);
$totalRows_club = mysql_num_rows($club);

?>
<?php
do {
?>
<option value="<?php echo $row_club['club_name']?>"><?php echo $row_club['club_name']?></option>
<?php
} while ($row_club = mysql_fetch_assoc($club));
$rows = mysql_num_rows($club);
if($rows > 0) {
mysql_data_seek($club, 0);
$row_club = mysql_fetch_assoc($club);
}
?>
</select>
<a href="add_club1.php">Add New Club</a></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><div align="right" class="style26"><span class="style7">NAME OF RIDER</span></div></td>
<td bgcolor="#C2F1BC"><div id="riderdiv"><select name="rider" id="rider">
<option>Select Club First</option>
</select>
<a href="add_rider1.php">Add New Rider </a>&nbsp;</div></td>
</tr>
<tr>
<td bgcolor="#FFFFFF"><div align="right" class="style26"><span class="style7">RIDER CONTACT NO.</span></div></td>
<td bgcolor="#BDD56A"><div id="riderPhonediv"><input name="riderPhone" type="text" id="riderPhone" /></div></td>
</tr>

php process..

findrider.php

<?
$club=$_GET['club'];

include 'db_connect.php';

$query="SELECT rider_name FROM riders WHERE club_name='".$club."' order by rider_name ASC";

$result=mysql_query($query);

?>

<tr>
<td>
<select name="rider" onchange="getRiderPhone(<?=$club?>,this.value)">
<option>Select Rider</option>
<? while($row=mysql_fetch_array($result)) { ?>
<option value=<?=$row['rider_name']?>><?=$row['rider_name']?></option>
<? } ?>
</select>
<a href="add_rider1.php">Add New Rider </a>&nbsp;</div></td>
</tr>

so..where the mistake??
syudZack83
New php-forum User
New php-forum User
 
Posts: 4
Joined: Mon May 19, 2008 9:08 pm

Return to JavaScript

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.