xajax and radio buttons

Categories: html, ajax

Tags: radio, xajax

to display a group of choices to select-only-one as radio buttons, the name and id parameters must be the same for all <input>.

the html code:

Code:

<input type="radio" name="option" id="option" value="1" onclick="xajax_click(this.value);" checked />option 1<br />
<input type="radio" name="option" id="option" value="2" onclick="xajax_click(this.value);" />option 2<br />
<input type="radio" name="option" id="option" value="3" onclick="xajax_click(this.value);"/>option 3<br />

to pass the value of radio button to xajax function, use this.value. not this.checked, as the value is always true when it’s clicked.

the xajax function:

PHP:

function click($value) {
    $x = new xajaxResponse();
    switch ($value) {
    case 1:
        //do something
        break;
    case 2:
        //do something
        break;
    case 3:
        //do something
        break;
    }
}

tinymce: clear field

Categories: javascript, ajax, tinymce

Tags: clear, tinymce, xajax

the normal way to clear <textarea> field:

Code:

document.formname.textareaid.value = '';

for <textarea> converted into tinymce editor, the above javascript call does not work. you need to call tinyMCE.setContent()

Code:

tinyMCE.getInstanceById('textareaid').setContent('');

to call from xajax function:

Code:

$xajax->script("tinyMCE.getInstanceById('textareaid').setContent('');");

xajax and checkbox

Categories: javascript, php, ajax

Tags: checkbox, xajax

in one of the forms i work on, i need to set other form fields based on the value of a checkbox. the value this.checked was passwd a parameter to xajax function.

Code:

<input type="checkbox" name="checkbox1" id="checkbox1" value="Y" onClick="xajax_function(this.checked);" />

in xajax function, the value of the parameter is either true or empty value.

PHP:

function xajax_function($data) {
    $obj = new xajaxResponse();
    $obj->assign("field1""value"$data "true value" "false value");
    return $obj;
}

the problem is, the value in field1 always display “true value” whether the box is checked or not!

it turns out that the true passed is a string! not boolean! you need to compare $data and “true” (with quotes).

replace line 3 of above php code:

PHP:

$obj->assign("field1""value", ($data == "true") ? "true value" "false value");

now it works as intended.

alternatively check with isset($data) to see if checkbox is checked.

to check the opposite value, ie checkbox is not checked, use !isset($data).

note: do not use / pass this.value as parameter. the value will always be the value assigned to checkbox, in this case, always “Y".


xajax: submitting disabled fields

Categories: javascript, ajax

Tags: form, xajax

by default xajax.getFormValues does not pass values from disabled fields. as noted here, it is browser standard not to submit disabled fields.

with xajax.getFormValues(), disable field can still be submitted. by setting 2nd optional parameter to true or 1.

Code:

xajax_function(xajax.getFormValues('form_id', 1));

read related post here.


xajax: getting form values

Categories: html, php, ajax

Tags: xajax

this happened to one of my forms - the form value is not submitted. you get empty array. this is on firefox. on IE, it worked.

after spending hours of investigation, it turns out there are 2 identical id’s in the page. :-/ changed one of the ids, it worked! it was hard to locate in the almost 10k lines of php code.

things to note for the html form

assign id attribute to <form>. without this, you get empty data.

make sure all fields in the form have name and id attributes. without name attribute, the field value is not submitted. without the id attribute, you cannot manipulate the field in php xajax function.

for the html page

make sure all values assigned to id attribute are unique!


1 2 »

Affliates

Spreadfirefox Affiliate Button