Solved

javascript form.reset - make it ignore a control

Posted on 2013-02-06
4
259 Views
Last Modified: 2013-02-12
I have a form with two cascading dropdowns powered by jquery.  They work well.  The values are populated via jquery after the form loads.

I have a reset button that resets the form to it's original values including blanking out the dropdowns.  I can then re-run my code to populate the dropdowns.  This works, but the dropdowns are first "reset" then set to my values.  This takes a second and doens't look good.

Is there a way to make form.reset ignore these dropdowns and I can handle them myself?
0
Comment
Question by:jackjohnson44
  • 2
4 Comments
 
LVL 1

Expert Comment

by:JamieTownsend
ID: 38860362
Do you have to use form.reset?  Can you not create a method yourself and then clear/reset any controls that you want ?
0
 

Author Comment

by:jackjohnson44
ID: 38860415
I could do that, but this will be used in more areas and that is a lot more work.  If I could just get around this one issue, it would save me hours.

I agree your solution would work, but I am looking to just ignore the dropdowns.
0
 
LVL 1

Accepted Solution

by:
JamieTownsend earned 250 total points
ID: 38860431
I am not so sure about preventing the standard reset from doing drop downs but you can override the reset method using something like

$("#form").bind("reset", function() {

    // potentially loop through all controls apart from drop downs and reset their value ?

    return false;
});
0
 
LVL 53

Assisted Solution

by:COBOLdinosaur
COBOLdinosaur earned 250 total points
ID: 38861323
You could use the onreset event of the form to fire a function that grabs the innerHTML of the controls you want to preserve into a string.  then the repopulation would just be an assignment of the string back to the innerHTML.

Cd&
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now