Skip to main content
October 24, 2008
Question

Passing text field value in url

  • October 24, 2008
  • 3 replies
  • 2361 views
I have a page with several list boxes referencing variable recordsets (bond types, bond purposes, etc.). I have "EDIT" links beside each going to the respective pages that perform those duties. I have named the list boxes (ex. id="Purposes") and I want to pass the value selected in the list boxes to the EDIT pages. When I try to use the link editPurpose.cfm?Purpose_ID=<cfoutput>#Purposes#</cfoutput>, I get the error "Variable PURPOSES is undefined". How do I reference a text field that is not in a form?
This topic has been closed for replies.

3 replies

Inspiring
October 24, 2008

Hi,

Since the value from the listbox gets selected on client-side (after CF has processed the page on server-side, and sent it to the client), CF will not know which value is currently selected in the listbox.

What you can use on client side, to take the currently selected value and open some page with the value in the URL is to use Javascript.

Have a look at the function below, and google for more info if necessary.

cheers,
fober

<div onclick="window.open('page.cfm?ID='+ document.getElementById('x').value ,'', '');">edit</div>

<select id="x" name="somelistbox">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
October 27, 2008
I'm still having no luck. Here's my function in the header:

<script type="text/javascript">
function GetValue()
{
var Purpose = document.getElementById("Purposes").value;
return (Purpose);
}
</script>

and here's my code in the link:

<td><div align="center"><a href="purposeEdit.cfm?Purpose_ID=getValue()">EDIT</a></div></td>

But I'm getting an error "Invalid data getValue() for CFSQLTYPE CF_SQL_INTEGER". Do I need to surround the function with javascript brackets or something?
Inspiring
October 27, 2008
window.location.href='sale_1.cfm?Page=1&Shopping='+this.value;

this is the code I used in my list box...+this.value get whatever the value the user pick on the list box and use it in the url.

Hope it helps you
Inspiring
October 24, 2008
use whatever logic you used to name and give values to your check boxes to produce that variable.
October 24, 2008
I tried that first. I tried referencing the recordset that fills in the box, but no matter which value I selected from the list box, it would only pass the first value of the list. That's why I thought I should reference the list box by ID instead of the recordset that fills it out.
October 24, 2008
Sorry, I meant "Passing List Box Value in URL". doh!