Click to See Complete Forum and Search --> : About SELECT drop down


gnanesh
05-01-2003, 06:02 AM
Hi

I have two fields

<input type=text name="text1" value=""> -- which is an Date field

<select name="select1">
<option value="connected">connected
<option value="not selected">not selected
<option value="open">open
</select>

Now if i enter the date in the text(text1) field the drop down should be set to "connected" option, and i also need to show all other options in the select drop down, but default should be "connected"

Then if there is no value in the text(text1) field , the user should not able to change the option to "connected", but they can select other options like "not selected" , " open"

If any one knows about this, i appreciate if you could post the code here

thanks
gnanesh

gnanesh
05-01-2003, 07:24 AM
Thanks for the code by the way i am confused about this "/^\s*$/" in

(/^\s*$/.test(this.value))

another i don't want to have a function in the SELECT option ,

I am building this SELECT list from the database, this is an JSP application ,

thanks

gnanesh

gnanesh
05-01-2003, 07:52 AM
Hi Dave

Thanks again...by the way how will i know the index of the SELECT option when i am getting all those list from the backend ,

then how would i make the "connected" option selected when the TEXT box has the value ?

And i should not be able to change it to "connected" option when the TEXT field is blank

Help me out , as i need to submit this in a hour or so, post any easy code

thanks
gnanesh

pyro
05-01-2003, 09:01 AM
Regarding you PM....

Try this:

<html>
<head>
<script language="javascript" type="text/javascript">
function testtext(frm) {
if (frm.text1.value != "") {
frm.select1.selectedIndex = 1;
}
else {
frm.select1.selectedIndex = 0;
}
return true;
}

function testselect(frm) {
if (document.myform.text1.value == "" && frm.options[frm.selectedIndex].value == "connected") {
frm.selectedIndex = 0;
}
return true;
}
</script>
</head>
<body>
<form name="myform">
<input type=text name="text1" value="" onkeyup="testtext(this.form);">
<select name="select1" onChange="return testselect(this);">
<option value="not selected">not selected
<option value="connected">connected
<option value="open">open
</select>
</form>
</body>
</html>

Also, if you know what format the date will be in, you could test via a RegExp to be sure it is entered correctly...