assign value of form field as URL parameter
I need to take a user-entered value from a form-field and append it as a URL parameter when the user hits {ENTER} or clicks the submit button. I'm new to DreamWeaver CS5, and I hav开发者_如何学Ce a project that I'm getting pressure to complete.
I can think of three four ways to do it, and only one is two are a ColdFusion solution.
If you use method="get"
in the FORM tag, all of the form fields and their values will be appended to the action URL in typical key=value
pairs.
The second involves using JavaScript to change the value of the action attribute of the FORM tag in response to an onclick
event (or perhaps onsubmit
).
A ColdFusion method would to use CFLOCATION to redirect to the desired location. In other words, you want to end up on page2.html, so have the form action be page1.cfm and have in that CF template <cflocation url="page2.html?urlvar=#form.formvar#">
.
Updated (courtesy of Ben Doom): On the form's action page, you could use the StructAppend()
function to add the URL scope to the FORM scope.
Can you expand on your question a bit? Maybe we can get you a more complete answer.
Like @Al Everett said,
Only need to change method = "get" instead of "post" in form attribute.
Your simple HTML code should look like:
<html>
<head></head>
<body>
<cfif structKeyExists(form,"submit")> <!--- To ckeck if form is submiited --->
<cfoutput>Value = #url.mytextbox#</cfoutput>
</cfif>
<form name="myform" method="get" action=""> <!--- action is blank to submit on same page --->
<input type="text" name="mytextbox" />
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>
精彩评论