[SOLVED] Problem with event or bug??

Greetings fellow scriptcase users :slight_smile:

I have a slight problem when using the form events and have no idea why the incorrect event is firing when not needed, soooo am hoping somebody can help…
I have two events one onclick and one onchange and also hiding specific fields on scriptinit.

AJAX onclick event:


{mbrDatePaid} = date('Y-m-d');

// Check for record
$check_sql = "SELECT mbrTypeDuration"
   . " FROM mbrType"
   . " WHERE mbrtypeID = '" . {mbrType} . "'";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]}))     // Row found
{
 $dur = {rs[0][0]};
 $newdate = date('Y-m-d', strtotime("+".$dur." days"));
 {mbrDateValid} = $newdate;
}
		else     // No row found
{
 
}

AJAX onchange event:


if ({mbrType} == '')     // Display field
{
    sc_field_display({mbrPaid}, 'off');
	sc_field_display({mbrDatePaid}, 'off');
	sc_field_display({mbrDateValid}, 'off');
	sc_field_display({payment_amount}, 'off');
}
else      // Hide field
{
    sc_field_display({mbrPaid}, 'on');
	sc_field_display({mbrDatePaid}, 'on');
	sc_field_display({mbrDateValid}, 'on');
	sc_field_display({payment_amount}, 'on');
}

// Check for record
$check_sql = "SELECT mbrTypePrice"
   . " FROM mbrType"
   . " WHERE mbrtypeID = '" . {mbrType} . "'";
sc_lookup(rs, $check_sql);

if (isset({rs[0][0]}))     // Row found
{

 {payment_amount} = {rs[0][0]};

}
		else     // No row found
{
 {payment_amount} = '0';
}

if ({mbrType} == '')     // Display field
{
	{mbrDatePaid} = '00/00/000';
	{mbrDateValid} = '00/00/000';
	{mbrPaid} = '0';
}
else      // Hide field
{

}

onscript init I am hiding the following fields:

sc_field_display({mbrPaid}, ‘off’);
sc_field_display({mbrDatePaid}, ‘off’);
sc_field_display({mbrDateValid}, ‘off’);
sc_field_display({payment_amount}, ‘off’);

now the problem I am having is that when I make a selection the onchange event fires correctly and displays the hidden fields,
but when I click the mbrPaid field and the onclick event fires it also hides the fields specified in the onscriptinit…
which in short it shouldnt, its not added to the onclick event yet it is still hiding the fields.

Any ideas if this is a problem with my above coding or is this a bug?

Thanks in advance

Well, I have some form with a lot of events too and had trouble getting it right. Does it work if you move your scriptinit procedure to the onload?

solved… thx Albert!

Was weird because when I placed the hide fields into onload intitialy it didnt hide the fields, so I moved them to the onscriptinit, and then started adding the event triggers.
Weird but now its fine :slight_smile:

Thanx again Albert!

I think that your browser cache was fooling you. But it’s great that it works now.