I can't find a simple tutorial to help me do this task. Basically I need to assign the value of radio button and pass it to the next page through session. This is my code for the radio button input.
<input type="radio" name="statReqYN" id="statReqYN-0" value="Yes" checked="checked"> Yes
<input type="radio" name="statReqYN" id="statReqYN-1" value="No"> No
After that, I will set the value of button:
<cfif isdefined("form.newProdYN") and form.newProdYN is "No">
<cfset form.newProdNY = "No">
</cfif>
Lastly, I will pass it to the next page of the same session through the submit button:
<cfif not arrayLen(errors)>
<cfset session.checkout.input = {
newProdNY=form.newProdNY}>
<cflocation url="formcomplete.cfm" addToken="false">
</cfif>
But when I try to get the value with #session.checkout.input.newProdYN# in html, the result is undefined. Can anyone help me solve this problem?
Your question isn't very clear as there are variables that are not being shown in your code.
Generally, with radio and checkbox fields, your receiving form should have a default value set. I do this by doing something along the lines of:
<cfparam name="FORM.statReqYN" default="no">
This way you can always use the variable. So in your case, I would have this as the whole template:
<cfparam name="form.statReqYN" default="No">
<cfparam name="form.newProdYN" default="Yes">
<form action="" method="post">
<input type="radio" name="statReqYN" id="statReqYN-0" value="Yes" checked="checked"> Yes
<input type="radio" name="statReqYN" id="statReqYN-1" value="No"> No
<button type="submit" name="newProdYN" value="Yes">Submit</button>
</form>
<cfif form.newProdYN IS 'Yes'>
<cfset session.checkout.input.newProduNY = form.newProdYN >
<cfset session.checkout.input.statReqYN = form.statReqYN >
<cflocation url="formcomplete.cfm" addToken="false">
</cfif>
I hope this makes a bit more sense?
Related
Maybe is better to explain with an example.
I have a form with a radio button with YES/NO items.
When a user select NO the fields below the radio button are disabled, while when he click on YES, the fields are enabled.
<form id="myForm">
<h3>Test Form</h3>
<input type="radio" name="radiobutton" id="needabikesino0" onclick="enableDisableAll();" /> Yes
<input type="radio" name="radiobutton" id="needabikesino1" onclick="enableDisableAll();" /> No
<p><input type="text" id="numerobiciclette" name="mybikes" placeholder="bike numbers" disabled /></p>
<p><input type="text" id="altezza" name="myheight" placeholder="my height" disabled /></p>
<p><input type="text" id="numerocaschi" name="myhelmets" placeholder="my helmets" disabled /></p>
</form>
function enableDisableAll() {
cb1 = document.getElementById('needabikesino0').checked;
document.getElementById('numerobiciclette').disabled = !cb1;
document.getElementById('altezza').disabled = !cb1;
document.getElementById('numerocaschi').disabled = !cb1;
}
See here: http://jsfiddle.net/dforce/0u13z7md/
The PROBLEM is:
When the user choose NO on the radio button, is not possible to send the form because the fields are compulsory.
I need the form to be sent even when the user choose NO.
How can I solve this issue?
Thanks for your help!
You could try making the field readOnly?
http://www.w3schools.com/jsref/prop_text_readonly.asp
Here's what I have, below, trying to use bits from similar answers here, plus items from the parsley site.. Nothing happens..User is not alerted that at least 1 box must be checked. Do I have this all wrong? Thank you in advance for any clues!
<form action="success.html" id="contact-form" data-parsley-validate>
<label for="language">Please Choose your Language:<br>
<input type="checkbox" class="checkbox" name="language" value="english" parsley-group="language" parsley-mincheck="1">English<br>
<input type="checkbox" class="checkbox" name="language" value="spanish" parsley-group="language" >Spanish<br>
<input type="checkbox" class="checkbox" name="language" value="french" parsley-group="language" >French
</label>
You have some problems with your code:
parsley-group doesn't exist. There is a data-parsley-group and is applicable if you want to validate a portion of your form.
parsley-mincheck="1" doesn't exist. There is a data-parsley-mincheck="1".
Assuming that you require at least one language, but can accept more, this code should do the trick:
<form action="success.html" id="contact-form" data-parsley-validate>
<label for="language">Please Choose your Language:<br>
<input type="checkbox" class="checkbox" name="language[]"
value="english" required>English<br>
<input type="checkbox" class="checkbox" name="language[]"
value="spanish" required>Spanish<br>
<input type="checkbox" class="checkbox" name="language[]"
value="french" required >French</label>
<button type="submit" id="submit-button">Submit form</button>
</form>
$(document).ready(function() {
// bind parsley to the form
$("#contact-form").parsley();
// on form submit, validate form and, if valid, show valid in the console
$("#contact-form").submit(function() {
$(this).parsley("validate");
if ($(this).parsley("isValid")) {
console.log('valid');
}
event.preventDefault();
});
});
If you want the user to select one and only one option, I advice you to use radio buttons.
I have to create a form with a submit bottom following a link
<form action="http://domain/**(((MY TEXT INPUT VALUE)))**.htm">
<input type="text" name="verb">
<input type="submit" value="Conjugate">
</form>
something like this.
please note that every link should be different.
I also want that the new page be opened in a new tab/window
could you please help me, and also make changes to the form code if there is sth under newer standards. Thank you!
You need to use javascript to get the TEXTBOX value and then place it into the form action.
You can create the submit button with an onclickevent.
Or you can use jQuery
$('#btnSubmit').click(function(){
var sTextValue = $("#MyText").val();
$('#MyForm').attr('action', 'htttp://domain/' + sTextValue + '.htm');
$('#MyForm').submit();
});
And the HTML
<form id="MyForm" action="">
<input id="MyText" type="text" name="verb">
<input id="btnSubmit" type="button" value="Conjugate">
</form>
There are many ways to accomplish this. That's just one of them.
<form action="http://domain/**(((MY TEXT INPUT VALUE)))**.htm" id="btnForm">
<input type="text" name="verb" onchange='javascript:document.getElementById("btnForm").action = "http://domain/"+ this.value +".htm"'>
<input type="submit" value="Conjugate" >
</form
This would update as soon you type the text. It wouldn't require jquery. it makes use of onchange event handler of input type text
<form action="http://domain/**(((MY TEXT INPUT VALUE)))**.htm" id="btnForm">
<input type="text" name="verb" onchange='updateFormAction(this.value)'>
<input type="submit" value="Conjugate" >
</form>
<script type="text/javascript">
function updateFormAction(value){
var btnForm = document.getElementById("btnForm");
btnForm.action = "http://domain/"+ value +".htm";
}
</script>
This is more explanatory form. Its based on onchange event handler for text types.
I'm currently creating a form that is very similar to the following code.
<form name="test" action="/go/test" method="post">
<input type=hidden name="hotspot_url" value="http://www.test.com/">
<input name="cky" value="<%write(cky);%>" type="hidden">
<input name="accept" value="Accept" type="hidden">
<input name="saccept" size="20" value="I Accept" onClick="hotspot.accept.value='Accept'" type="submit">
<input name="sdisconnect" size="20" value="I Decline" onClick="hotspot.accept.value='Decline'" type="submit">
</form>
However, the new form has a text input field. What I want to achieve is that the value entered in that text field is placed, upon send, after the test.com value (location marked with xxx)
<input type=hidden name="hotspot_url" value="http://www.test.com/xxx">
I've looked around - but i can't seem to find a solution.
What would be the best way to get this done?
You can use a buttons onclick event, which is not of type submit. When onclick occurs, you can first change the value of hidden field and then submit the form.
Or if you use JQuery, you can use the following jQuery code to do something before the form is submitted:
$(function() {
$('#form').submit(function() {
// DO STUFF
return true; // return false to cancel form action
});
});
You can give both inputs an id, and do something like this:
give the form an "onsumbit= doThis()"
function doThis(){
var hiddeninput= $('#hiddeninput').val();
var input = $('#input').val();
$('#hiddeninput').val(hiddeninput+input);
return true;
}
this is very simple nothing fancy.
Basically, I have stored information in a database field and I want to display it again through a form.
The original form has the same checkboxes but they are always empty. The user can check the boxes off and the values are put into the database.
Graduate Courses: Fall? Spring? Summer? Stored as a list in a column named grad. (F, M, S)
They have the option to save this lovely form as a draft. When they come back to the draft I need to display what they might have already checked.
<cfif listContains(#grad#, "F") is not 0>
<input type="checkbox" name="grad" id="grad" value = "F" checked />
<cfelse>
<input type="checkbox" name="grad" id="grad" value = "F" />
</cfif>
<cfif listContains(#grad#, "S") is not 0>
<input name="grad" type="checkbox" id="grad" value = "S" checked />
<cfelse>
<input name="grad" type="checkbox" id="grad" value = "S" />
</cfif>
<cfif listContains(#grad#, "M") is not 0>
<input name="grad" type="checkbox" id="grad" value = "M" checked />
<cfelse>
<input name="grad" type="checkbox" id="grad" value = "M" />
</cfif>
Is there an easier method to doing this with cfform code?
Just curious. :)
I do it like this, as I don't really use <cfform>:
<cfloop list="F,S,M" index="g">
<input type="checkbox" name="grad" id="grad_#g#" value="#g#" #CheckedIf(ListFind(grad, g) gt 0)# />
</cfloop>
<!--- ... --->
<cfscript>
function CheckedIf(expression) {
if (arguments.expression) return 'checked="checked"';
return "";
}
</cfscript>
But the ColdFusion docs state:
[since] ColdFusion MX: Changed the cfform tag
preserveData attribute behavior: if it
is set to True, ColdFusion checks
radio and check box values only if
their value matches the posted value
for the control.
So yes, <cfform> can help you with this. Use <cfparam name="FORM.xyz" default="foobar"> to emulate the "posted value" for normal requests.