Khalid,

Below is a suggestion on how to fix your form onChange/ submit issue.  I'm also 
copy'ing this back to the list in case my ideas spark better ones on the list, as you 
received few (none?) replies from your previous posts on this top.

1. Set a hidden form field within the page named lastId (null or 0 if no vehicle was 
entered (i.e. we're on car #1).

2. Use javascript validation in the page but set the form to do:
onsubmit="return MyValidationFunction(this)" 
instead of the regular validation framework call which may be:
onsubmit="return validateMyAction(this)"

Here is a very rough example in JavaScript, including documentation, of what I'm 
thinking might work:

<script language="javascript">
// Set this in the jsp so it puts the number (id, etc.) 
// of the vehicle you are sending to the client so we
// can key off it later (to you can revert that field to it
// if there are validation errors as you described)

var initialVehicle = <bean:write ... etc.../>

function MyValidationFunction(myForm) {
  // if no validation errors, continue
  if ( validateMyAction(myForm) ) {
     // We validated properly? Good, now let's submit
     myForm.submit();

  // Any validation errors? Reset the form fields as
  // necessary.  You suggested that only the vehicle
  // pulldown changed, so the code below (should be okay
  // Javascript code, but I pulled it from memory) assumes 
  // a single choice select box. You can, however, reset 
  // as many more fields in the else clause as you want 
  // since you won't be submitting the form in validation
  // failures.
  } else {
     var l = myForm.vehicleField.length;
     for ( var i = 0; i < l ; i++ ) {
         // found the selection that we started with? 
         // make that one true (shown) again so we're
         // back to, say, vehicle #1 when validation
         // failed after the onchange but without submitting
         if ( myForm.vehicleField.options[i].value == initialVehicle ) {
              myForm.vehicleField.selectedIndex = i;
              // might be just return, not return false, 
              // I always get that wrong in my JavaScript
              return false; 
         };
    }
}
</script>

That way, your onchange is still there, it still tries to submit but validates first.  
On validation failure, you can reset your vehicleNo field or change any other data.  
On validation succeed, you can submit it.  You can even set a hidden field that 
indicates you updated the vehicle number stored in the JavaScript variable 
initialVehicle.

Regards,
David

-------Original Message-------
From: "Khalid K." <[EMAIL PROTECTED]>
Sent: 08/07/03 01:33 AM
To: "'David G. Friedman'" <[EMAIL PROTECTED]>
Subject: RE: sorry to bother you

This is my problem:

Order of execution:

Menu link (onclick) --> Dispatch Action(display method) --> forward to jsp (show 
vehicle 1..series of text boxes w/ prefilled data, or empty) --> client change or 
enter new data --> client change selection by selecting 2nd vehicle, --> 
onChange="this.form.submit" --> which submits the Form to the same dispatch action 
(display method)

Problem occurs when submitting after changing data via the drop down and there is a 
validation error, by this time, the drop down value Has changed to 2nd vehicle, but 
the html:/errors on the same jsp are for vehicle 1.

Confusing ?? :)  if you haven't come across this problem 
no problem...

Thanks

Khalid


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to