View Full Version : button / onclick / multi fucntion call problem

07-19-2007, 08:03 PM
Hey all -

So I'm totlly stuck on this and can't figure it out.

I've got a button on a form and it's supposed to call two functions.
1) A form validation
2) A function to call dojo to load the next page and do some other stuff.

<input type="button" value="Save" onclick="GROUPS_validate_data_onsubmit(); return true; updateGroup(37);">

Now I'm pretty sure the 'return true' is out of place..?? It works if I take the second function (updateGroup) out all together...

What's happening now (if I leave 'return true' out), is that the validation function will fire, but then when I correct the error, none of the funtions seem to fire.. or at least the updateGroups doesn't..

So any ideas on what I'm doing wrong?

Code below:

<form name="GROUP_EDIT_FORM" method="post">
<input type="Text" name="GROUP_NAME" value="">
<OPTION value="">
<OPTION value="1">Team
<input type="button" value="Save" onclick="GROUPS_validate_data_onsubmit(); return true; updateGroup(37);">

<script type="text/javascript">
function GROUPS_validate_data_onsubmit()
var msg;
var empty_fields = "";
var errors = "";
while (document.GROUP_EDIT_FORM.GROUP_NAME.value.substring(0,1) == " ")
document.GROUP_EDIT_FORM.GROUP_NAME.value = document.GROUP_EDIT_FORM.GROUP_NAME.value.substring(1);

if (document.GROUP_EDIT_FORM.GROUP_NAME.value == "")
empty_fields += "\n Group Name";

if (document.GROUP_EDIT_FORM.GROUP_NAME.value.length > 200)
errors += "The Group Name field cannot exceed 200 characters\n"
document.GROUP_EDIT_FORM.GROUP_NAME.value = document.GROUP_EDIT_FORM.GROUP_NAME.value.substring(0,199);

if (document.GROUP_EDIT_FORM.TEAM_ID.options[document.GROUP_EDIT_FORM.TEAM_ID.selectedIndex].value == "")
empty_fields += "\n Team";

if (!empty_fields && !errors)
return true;

msg = "__________________________________________________\n\n";
msg += "The form was not submitted because of the following errors.\n";
msg += "Please correct these errors and re-submit.\n";
msg += "__________________________________________________\n\n";

if (empty_fields)
msg += "- The following required fields are empty:"
+ empty_fields + "\n";
msg += errors + "\n";
msg += "__________________________________________________\n\n";
alert (msg);
return false;

function updateGroup(groupSeq){
var docPane = dojo.widget.byId("workingDIV");
docPane.bindArgs = {preventCache: true};

var localGroupName = document.GROUP_EDIT_FORM.GROUP_NAME.value;
var localGroupTeam = document.GROUP_EDIT_FORM.TEAM_ID.options[document.GROUP_EDIT_FORM.TEAM_ID.selectedIndex].value;

if ((!groupSeq) && (!localGroupName)){
docPane.setContent("Data missing");


07-19-2007, 09:49 PM
I haven't waded through your code, but I can tell you that once you return, that's it, period. The script parser will not execute anything after that. So, at the very least, you want:

<input type="button" value="Save" onclick="GROUPS_validate_data_onsubmit(); updateGroup(37);">

Now, the return statement in an element's event is really only useful if the element itself has some kind of default action for that event in HTML - say, like a link does onclick. If it were a link, return true would tell the browser to also execute the link, return false would tell it to ignore the link and to only carry out the event. A button of this type has no default action. So, if you want to return true, or false for that matter, it wouldn't be in relation to the button. This means that your return value (if it is needed at all) should be set elsewhere.

07-19-2007, 10:49 PM
John -

Thanks for the reply. I understand not wanting to wade through the ocean of code..

I ended up making a work around for it that seems to work a bit better.. maybe... we'll see... now it just calls one funtion and many functions, along with logic to control them are contained in there. I'm not sure if you'd call that a cludge or not, but it does keep all the js in one place.