Topic: Change data-set?

Hi,

   Is there way to change a value of data-set directly by Xajax? I tried using assign function but noting happen.

   I'm using xjax 0.5.

   When I want change a data-set using javascript I normally use .setAttribute('data-nameset',new_value); 

  Should I use script function?

Best Regards,
Guilherme Filho

Re: Change data-set?

Hi Guilherme,

I would like to help but I do not understand your question. Perhaps you could explain some more.

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Change data-set?

Hi,
 
   It's possible to define some data on html tags as DIV. You can write <div data-name="Guilherme" data-age="29">Some text</div>,
   Using javascript you can read and write these values (name/age).
   I would like to use xajax to write directly some values for these data-info items.

Best Regards,
Guilherme Filho

Re: Change data-set?

Guilherme,

I haven't messed with the html data- attribute in the past. It took me a while to get it...

You can use the assign method. You assign to the name portion of the data attribute. i.e. If the attribute is "data-name"
you assign the name attribute only.

Example:

<?php
/*
    Setting the data-* properties of an element
    9/9/2016

        This script demonstrates using xajax to change a 
        data value of an element.

*/    
require 'xajax-master/xajax_core/xajax.inc.php';
$xajax = new Xajax();
$xajax->configure('javascript URI', 'xajax-master/xajax_js/');
$xajax->register(XAJAX_FUNCTION,'setData');
$xajax->processRequest();

function setData()
{
    $resp = new xajaxResponse();
    $resp->assign('mydiv','name', 'D. Jones'); //'name' references 'data-name' in the html
    $resp->assign('mydiv','age','45'); //'age' references data-age
    return $resp;
}
?>
<!doctype html>
<html>
<head>
<title>Xajax Data Property Manipulation</title>
<?php $xajax->printJavascript(); ?>
<script>
 function showdata()
 {
    elem = xajax.$('mydiv');
    data = elem.name;
    alert(data);
    data= elem.age;
    alert(data);
 }
</script>
</head>
<body>
<div id='mydiv' data-name='xx' '></div>
<input type="button" onclick="xajax_setData()" value="set Data"/> 
<input type="button" value="Show Data" onclick="showdata()"/>
</body>
</html>

Notice that the attributre does not need to be defined before hand - see the data-age assignment in the example.

Learn something new every day...

Ed

If you ever stop learning you may as well dig a hole, crawl in and pull the top over yourself.

Re: Change data-set?

Dear Ed.
 
    Thank you for you help!
    Using the assign I could write
$resp->assign('ID_HTML_ITEM','dataset.NAME_DATASET_WANTED',$value);
     I got the dataset .(dot) name here:
https://developer.mozilla.org/en/docs/W … nt/dataset

Best Regards,
Guilherme Filho