Link to home
Start Free TrialLog in
Avatar of Panos
PanosFlag for Germany

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="<cfoutput>#url.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?
SOLUTION
Avatar of hielo
hielo
Flag of Wallis and Futuna image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

ASKER

hello hielo.
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" />
Avatar of Panos

ASKER

Hi again.
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.
Avatar of Panos

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)
Avatar of Panos

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.
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.
Avatar of Panos

ASKER

Ok Zvonko.
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....
You call the function like this:
<input name="ClearForm" type="button" class="buttonsearch" value="Clear Form" onClick="clearForm(this.form)" />

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>

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Panos

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?
Avatar of Panos

ASKER

Zvonko now i get all the checkboxes checked!
Avatar of Panos

ASKER

I changed the line 9 to false and it is working.Is this OK?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
>>I changed the line 9 to false and it is working.Is this OK?
That is a MUST for your purposes.
Avatar of Panos

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.
Avatar of Panos

ASKER

Thank you both for your great help!
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).toLowerCase() ){

it would be more appropriate to clear  based on field name:
switch( String(elem[i].nameLowerCase() ){

I think the code is now straight forward for customization purposes.