Click to See Complete Forum and Search --> : Dynamic select list - problem passing value back to calling page


modfather
02-17-2003, 10:53 AM
I'm hoping someone can help me out. Although I am using ColdFusion, it shouldn't really matter since my problem seems to be with JavaScript. Here's my situation:

I have a CF page that prompts for a part number. If the person doesn't know the part number or only the beginning of it, they can hit a 'Search' button. If that button is hit, I want to open a pop-up with a dynamic select list of all parts that begin with whatever string they've typed into the part number field. I am using JavaScript to do this, but am not a JS programmer, so I'm sure I have something wrong. Here's what I have so far:

PARTNUMBER.CFM
...
<form name="myform" method="post" action="order_submit.cfm?SupervEmail=#SupervEmail#">
<input name="partnumber" type="text" size="44" Required="yes" MESSAGE="'PartNumber' cannot be blank">
<input type="button" class="h2" onClick="searchWindow('search.cfm?pn='+document.myform.partnumber.value,'window2')" value="Search">
...

SEARCH.CFM
<cfquery name="myPart" datasource="tci">
SELECT prod
FROM validprod where prod like '#URL.pn#%'
</cfquery>
<html>
<head>
<script language="JavaScript">
function returnValue(){
top.opener.document.search.partnumber.value = document.found.chosen.options[document.found.chosen.selectedIndex].value
this.close()
}
</script>
</head>

<body>
<form name="found">
<select name="chosen" onchange="returnValue()">
<cfoutput query="myPart">
<option>#prod#</option>
</cfoutput>
</form>
</body>
</html>

I get the select list pop-up fine. I can select one of the items fine, but on selecting the desired part, nothing is passed back to my text box in my calling page and the pop-up is not closed.

If there's someone out there who can help me, I'd REALLY appreciate it. This is a real sticking point and I'm desperate!

Thanks a million.
Steve

gil davis
02-17-2003, 11:38 AM
top.opener.document.search.partnumber.value =I don't think this is right. If I understand correctly, I would think it should be:

top.opener.document.myform.partnumber.value =

modfather
02-17-2003, 11:41 AM
gil,

You're right. Thanks for the find. I changed that and I have just one small problem still: If I select the top item in my select box, it still doesn't return the value and close the window. Any idea why? My current code is now:

<cfquery name="myPart" datasource="tci">
SELECT prod
FROM validprod where prod like '#URL.pn#%'
<!--- WHERE EmpLogin='#form.UserID#' AND EmpPasswd='#form.UserPasswd#' --->
</cfquery>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
function returnValue(theSel){
top.opener.document.myform.partnumber.value = theSel.options[theSel.selectedIndex].value
window.close()
}
</script>
</head>
<body>
<form name="found">
<select name="chosen" onchange="returnValue(this)">
<cfoutput query="myPart">
<option value="#prod#">#prod#</option>
</cfoutput>
</form>
</body>
</html>

Thanks again!
Steve

gil davis
02-17-2003, 11:47 AM
"onchange" will not fire unless the selectedIndex changes. It's really a poor user interface technique because it does not give the user a chance to check himself. Give them a button to say "I've made my choice".

If you insist on using onchange, many people avoid the problem by using a dummy entry for the first option:

<option value="">-- Please selecte one --</option>

modfather
02-17-2003, 11:54 AM
for you Simpsons fans...

Gil: 'Ahhh, why did Gil have to bet the company payroll???'

For Gil...

Thanks. You're the coolest, man!