Hi guys, I have a problem and I think it's a rather easy answer, but I'm new to javascript so it's hard for me.
Here is what I'm asking.
I have a dynamic dropdown that's populated from a mysql database. Next to the dropdown there are 2 empty fields. I need to populate those 2 fields with the "id" and "description" of the item you selected from the dropdown before I submit the form. So I need it to refresh those fields or the whole form.
Right now, I can only make the actual item populate in a text box, and the ID and DESCRIPTION are empty.
Here is my code.
Thanks in Advance.
<script type="text/javascript">
function myName(){
var input = document.getElementById('userinput').value;
document.getElementById('oldname').innerHTML = input;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Welcome to my site, <b id='oldname'>enter your name?</b></br>
<input type='text' id='oldname' />
<input type='text' id='id' value='<?php echo $row_test['id']; ?>'/>
<input type='text' id='description' value='<?php echo $row_test['description']; ?>'/>
<input type='button' value='Click'/>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<form id="form1" name="form1" method="post" action="" >
<label>
<select name="userinput" onchange="myName()">
<?php
do {
?>
<option value="<?php echo $row_test['user_name']?>"<?php if (!(strcmp($row_test['user_name'], $row_test['user_name']))) {echo "selected=\"selected\"";} ?>><?php echo $row_test['user_name']?></option>
<?php
} while ($row_test = mysql_fetch_assoc($test));
$rows = mysql_num_rows($test);
if($rows > 0) {
mysql_data_seek($test, 0);
$row_test = mysql_fetch_assoc($test);
}
?>
</select>
</label>
</form>
Here is what I'm asking.
I have a dynamic dropdown that's populated from a mysql database. Next to the dropdown there are 2 empty fields. I need to populate those 2 fields with the "id" and "description" of the item you selected from the dropdown before I submit the form. So I need it to refresh those fields or the whole form.
Right now, I can only make the actual item populate in a text box, and the ID and DESCRIPTION are empty.
Here is my code.
Thanks in Advance.
<script type="text/javascript">
function myName(){
var input = document.getElementById('userinput').value;
document.getElementById('oldname').innerHTML = input;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
Welcome to my site, <b id='oldname'>enter your name?</b></br>
<input type='text' id='oldname' />
<input type='text' id='id' value='<?php echo $row_test['id']; ?>'/>
<input type='text' id='description' value='<?php echo $row_test['description']; ?>'/>
<input type='button' value='Click'/>
<p></p>
<p></p>
<p></p>
<p></p>
<p></p>
<form id="form1" name="form1" method="post" action="" >
<label>
<select name="userinput" onchange="myName()">
<?php
do {
?>
<option value="<?php echo $row_test['user_name']?>"<?php if (!(strcmp($row_test['user_name'], $row_test['user_name']))) {echo "selected=\"selected\"";} ?>><?php echo $row_test['user_name']?></option>
<?php
} while ($row_test = mysql_fetch_assoc($test));
$rows = mysql_num_rows($test);
if($rows > 0) {
mysql_data_seek($test, 0);
$row_test = mysql_fetch_assoc($test);
}
?>
</select>
</label>
</form>