File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes HTML, CSS and JavaScript and the fly likes how to prevent javascript func from resetting values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of JavaScript Promises Essentials this week in the JavaScript forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "how to prevent javascript func from resetting values" Watch "how to prevent javascript func from resetting values" New topic
Author

how to prevent javascript func from resetting values

Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 85
Hi,
I have a sample form below. The issue I'm having is with a function to validate the form. I have some select tags, and the validate function checks to see if the default values are populated. If they are, it instructs the user to select another value. But when I hit submit, one of the values is changed back to the default value, causing the function to return false. Any idea how to address this?



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

Have you used a JavaScript debugger to see at what point things go awry?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 85
I tried firebug in firefox and the google chrome debugger, nothing. I actually think the function is doing what it's supposed to. Maybe onSubmit isn't the way to go? The thing is, I use this same basic pattern for other forms with no problem. I'm thinking maybe if I change it to a radio selection group that will give me the desired result.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

If the function is doing what it's supposed to do, what is the actual problem?
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 85
sorry, not clear with my meaning. I meant that maybe the function is doing what it is instructed to do, but I may be instructing it to do the wrong thing. What I want it to do is leave the select values alone when the validateForm func is called.

Is it possible that when submit is hit, it attempts to send the data and resets the select values? The thing is...it's only the first one that changes. The second is left alone. Any combination I try in terms of the order of the select pulldowns has the same result, the 2nd is left alone and the first goes back to the default value. This behavior is the same in chrome, safari and firefox

thanks,
ec
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

Look carefully at line 15.
Edmund Castermund
Ranch Hand

Joined: May 09, 2007
Posts: 85
ugggghhhh.....

one of those moments I want to truly punch myself in the face....



should be




thanks,
ec
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61598
    
  67

I didn't see it on first glance either. So forgo the punching.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to prevent javascript func from resetting values