xajax and radio buttons
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; | |
} | |
} |
2008-10-24 10:28:53 • Link • Comments • Trackbacks
tinymce: clear field
Categories: javascript, ajax, tinymce
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('');"); |
2008-09-22 16:22:57 • Link • Comments • Trackbacks
xajax and checkbox
Categories: javascript, php, ajax
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".
2008-07-03 12:16:33 • Link • Comments • Trackbacks
xajax: submitting disabled fields
Categories: javascript, ajax
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.
2008-06-30 14:15:50 • Link • Comments • Trackbacks
tinymce and xajax: data in the editor is not submitted
Categories: javascript, html, ajax, tinymce
i just downloaded and installed tinymce which magically converted the <textarea> element into a nice little editor, which supposely transform the input into html output. nice! no more educating non-programmers about html tags.
if you submit the form via normal post, the value for <textarea> form element is submitted. but when submitting the form via xajax, the data for the <textarea> element is empty!
after some research around the internet, found out that the solution is easy. before submitting the form, call tinyMCE.triggerSave().
more about tinymce and xajax here.
2008-06-23 15:44:11 • Link • Comments • Trackbacks
