Hi,
VS.NET 2003 on WinXPPro, both with all the latest patches and updates,
etc...
I've got a very simple WebForm which is used either to add a new record to a
SQL Server database or edit a record. Depending on whether I'm adding or
editing, I need to do slightly different validation, so I'm trying to set
the form's Save button's onclick property dynamically at run-time
client-side with JavaScript, as follows:
document.frmCalendar.cmdSave.onClick = "javascript:validateForm('Add');";
or
document.frmCalendar.cmdSave.onClick = "javascript:validateForm('Edit');";
function validateForm(pstrMode)
{
switch (pstrMode)
{
case "Add" :
{
//validate the form and add the record
break;
}
case "Edit" :
{
//validate the form and edit the record
}
}
}
Problem is that the button does not respond to the onClick event. If I
create another button and set its onClick to
"javascript:alert(document.frmCalendar.cmdSave.onC lick);" it shows the
correct string in the first button's onClick property. It's almost like the
first button doesn't know to respond to the click event.
I have found at least five ways to achieve the same effect using different
functionality. I'm just interested to know if the above is possible, more
from an intellectual exercise and for my own interest.
Thanks,
Mark Rae