Panos
asked on
Reset Button -delete Url variables
Hello experts.
I have a form like:
<form action="Results.cfm" method="get" name="SearchForm" id="SearchForm">
..........
.......<input name="S_Name" type="text" id="S_Name" <cfif (isdefined("url.S_Name"))> value="<cf output>#ur l.S_Name#< /cfoutput> "</cfif> size="22" />
........
<input name="Reset" type="reset" class="buttonsearch" value="Reset" />
.....
</form>
The problem i have is when there is a value in Url.S_Name ,i can't delete the text field value (and select,checkboxes.......) with the reset button.
Any help?
I have a form like:
<form action="Results.cfm" method="get" name="SearchForm" id="SearchForm">
..........
.......<input name="S_Name" type="text" id="S_Name" <cfif (isdefined("url.S_Name"))>
........
<input name="Reset" type="reset" class="buttonsearch" value="Reset" />
.....
</form>
The problem i have is when there is a value in Url.S_Name ,i can't delete the text field value (and select,checkboxes.......) with the reset button.
Any help?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi again.
And a second question.
Can i have the values ([S_Name,S_Email])..... in the script file?
And a second question.
Can i have the values ([S_Name,S_Email])..... in the script file?
To set the checkbox checked you have to compare the Value like this:
<input id="S_test10" type="checkbox" name="S_test10" checked="checked" value="10" />
And the second question is a Second question.
Please open a New question and ask there how to set form fields by JavaScript and use for that JavaScript values composed by ColdFusion. The setValue function could also mimic the resetValue function to set to desired state.
<input id="S_test10" type="checkbox" name="S_test10" checked="checked" value="10" />
And the second question is a Second question.
Please open a New question and ask there how to set form fields by JavaScript and use for that JavaScript values composed by ColdFusion. The setValue function could also mimic the resetValue function to set to desired state.
ASKER
Hi Zvonko.
Thats is not the question (set the checkbox checked).I want to uncheck when i click the reset button (with the code from hielo).When i finished with this i will make a second question as you told me.(i think that it is part of the same question but another way)
Thats is not the question (set the checkbox checked).I want to uncheck when i click the reset button (with the code from hielo).When i finished with this i will make a second question as you told me.(i think that it is part of the same question but another way)
ASKER
Hi again.
I noticed that when i have checked one checkbox and hit the new reset button the checkbox remains as checked but when i click the sumbit button the values don't pass to the URL.
I noticed that when i have checked one checkbox and hit the new reset button the checkbox remains as checked but when i click the sumbit button the values don't pass to the URL.
So you get the checkbox checked when page is loaded, right?
The Reset button rests the checkbox to it state at page load time.
If you need a clearForm() functionality in this question then there are realy two aproaches: load empty form in browser and set all form elemenents by script. That way does your Reset button need no script and does all resets to empty by defaulz bahavior. The other way is to load the values into fields as default values and clear the values by a Clear button.
The Reset button rests the checkbox to it state at page load time.
If you need a clearForm() functionality in this question then there are realy two aproaches: load empty form in browser and set all form elemenents by script. That way does your Reset button need no script and does all resets to empty by defaulz bahavior. The other way is to load the values into fields as default values and clear the values by a Clear button.
ASKER
Ok Zvonko.
Can you give one example with my code?
Can you give one example with my code?
Here an old answer: http:Q_22105578.html#18211240
It can be reduced but it takes a minute....
It can be reduced but it takes a minute....
You call the function like this:
<input name="ClearForm" type="button" class="buttonsearch" value="Clear Form" onClick="clearForm(this.fo rm)" />
And the streamlined function looks like this:
<input name="ClearForm" type="button" class="buttonsearch" value="Clear Form" onClick="clearForm(this.fo
And the streamlined function looks like this:
<script>
function clearForm(theForm){
var elem = theForm.elements;
for(var i=0;i<elem.length;i++){
if(elem[i].type.match("text")){
elem[i].value="";
} else
if(elem[i].type.match(/(select|radio|check)/i)){
elem[i].selectedIndex=-1; // or zero for the first option
}
}
}
</script>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
OK Zvonko.
Here is your code:
<input type='button' name='ClearSearch' value='Reset' onClick="reSet(this)" >
And the function looks then like this:
<script>
function reSet(theBtn){
var theForm = theBtn.form;
var elem = theForm.elements;
for(var i=0;i
My formname is :Searchform.
What changes should i make?
Here is your code:
<input type='button' name='ClearSearch' value='Reset' onClick="reSet(this)" >
And the function looks then like this:
<script>
function reSet(theBtn){
var theForm = theBtn.form;
var elem = theForm.elements;
for(var i=0;i
My formname is :Searchform.
What changes should i make?
ASKER
Zvonko now i get all the checkboxes checked!
ASKER
I changed the line 9 to false and it is working.Is this OK?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
>>I changed the line 9 to false and it is working.Is this OK?
That is a MUST for your purposes.
That is a MUST for your purposes.
ASKER
Hi again hielo.
The new code is working fine and is easier than the first you posted.I have so many checkboxes and it would be very busy for me but it is a usefull code if i don't want to clear all the fields.
The new code is working fine and is easier than the first you posted.I have so many checkboxes and it would be very busy for me but it is a usefull code if i don't want to clear all the fields.
ASKER
Thank you both for your great help!
regards
Panos
regards
Panos
>>and is easier than the first you posted
Orinally I thought you wanted to specify exactly which fields to clear. Hence the "complexity" of the original post.
>>...usefull code if i don't want to clear all the fields.
In that case, rather than clearing based on field type
switch( String(elem[i].type).toLow erCase() ){
it would be more appropriate to clear based on field name:
switch( String(elem[i].nameLowerCa se() ){
I think the code is now straight forward for customization purposes.
Orinally I thought you wanted to specify exactly which fields to clear. Hence the "complexity" of the original post.
>>...usefull code if i don't want to clear all the fields.
In that case, rather than clearing based on field type
switch( String(elem[i].type).toLow
it would be more appropriate to clear based on field name:
switch( String(elem[i].nameLowerCa
I think the code is now straight forward for customization purposes.
ASKER
It is working with the text and select fields but i can't get it work with the checkboxes like:
<input id="S_test10" type="checkbox" name="S_test10" checked="checked" value="10" />