Expand my Community achievements bar.

Problem with stopping a submission with incorrectly selected drop down box item

Avatar

Former Community Member
Hi all, I'm wrestling with some JavaScript at the moment and I wonder if you guys can help me out. I've got a drop down box element on my html rendered form (working with an XDP file) and I've been asked to put a dotted line separator between the top 7 accounts at the top of the drop down and the rest of the accounts which are in alphabetical order. I am trying to make it so if the dotted line is selected that the customer cannot submit the form.



I've created a script that should give an error message saying to select an account and then set the focus to the drop down until it's selected correctly, but it doesn't quite work, and I've tried a number of events now to sit it in. Here's the code:



// Stop Submitting if drop down has the line selected



var account = xfa.resolveNode("SmartForm.page1.sBody.sAccountDetails.dAccountType").rawValue;



if (account == "--------------------------------------------------------"){

xfa.host.messageBox ("You must select an Account Type");

xfa.host.setFocus("SmartForm.page1.sBody.sAccountDetails.dAccountType");

}



Now if I set this on a mouseUp event it works beautifully in Firefox ( gives the error, sets the focus to the drop down and clears the drop down to select an account again), but it appears that the mouseUp event doesn't work too well in IE (does nothing).



If I try it on something like an exit event (would also be good there) it gives the error message but allows the user to continue filling the form and they can submit to the banking page. Now maybe I need a line of code that will stop the submit from going through (i.e. if the user clicks on submit it pops up the error and goes back to the drop down), but I don't know what to write.



Any assistance would be greatly appreciated! :-)
1 Reply