Click to See Complete Forum and Search --> : select value
daed17
08-18-2003, 05:21 PM
How can I take the select value and check it and if value = x then replace the select box with a text input line?
I have been told by pyro in the php group that javascript will do this.
I am sure it is easy, I am just new to php and brain dead today.
Khalid Ali
08-18-2003, 06:02 PM
var val = document.formName.listboxName.options[document.formName.listboxName.selectedIndex].value;
the above will get you the selected value from the list box
now you need to compare it
if(val==x){
//here you want to replace select tag with input
//you can either use CSS to hide the listbox or DOM to remove the select from the form hierarchy and insert a new element
}
daed17
08-18-2003, 07:40 PM
I am totally clueless to javascript... do I just place this after the select?
Khalid Ali
08-18-2003, 10:02 PM
I'll take a look at it tonight and create another file and upload it..
daed17
08-18-2003, 10:11 PM
Thank you and if this helps here is what I am doing...
<td width="27%"><font color="#000000"> <b>System</b></font><font color="#FF0000">
</font></td>
<td width="73%">
<select name=system size="1\" id="system">
<?php
$db3 = mysql_connect("localhost", "root", "r00t");
mysql_select_db("dssdatabase",$db3);
$query3 = "select projname from projects";
$result3 = mysql_query($query3);
mysql_close($db3);
if ($myrow = mysql_fetch_array($result3)) {
do {
$proj = $myrow["projname"];
?>
<option value="<?php echo "$proj"; ?>"><?php echo "$proj"; ?></option>
<?php
} while ($myrow = mysql_fetch_array($result3));
} else {
echo "Sorry, no records were found!";
}
?>
<option value="other">OTHER</option>
</select>
Khalid Ali
08-19-2003, 10:30 AM
code your html as below( only the select box and the input field)
<select id="listbox" onchange="validate(this.options[this.selectedIndex].value)" style="display:block;">
<option value="-1">Select one</option>
<option value="1">one</option>
<option value="2">two</option>
</select>
<input id="tfield" type="text" style="display:none;">
now in the javascript create a function name validate
function validate(val){
//lets say if user selects one display the text field
if(val=="1"){
//hide the list box
document.getElementById("listbox").style.display="none";
//show text field hide select box
document.getElementById("tfield").style.display="block";
}
}
thats about it..
there may be some erros but in essence it should work,since I have not tested it..
daed17
08-21-2003, 04:32 PM
It works, but I can't seem to pass the value to php? I have it checking for $tfield when the submit button is selected...
Any hints?
And thank you for alll your help :)