Topic: assigning values to more than 1 form fields is not working

Can you check the code below and answer why the value for id1 is not displayed?

<?php

//echo base64_encode(random_string());

require_once("./xajax/xajax_core/xajax.inc.php");

function addFields() {
   
    $objResponse=new xajaxResponse();
    $objResponse->append( 'myform', "innerHTML", '<div id="mydiv1"></div>' );   
    $objResponse->createInput("mydiv1", "text", "field[]", "id1" );
    $objResponse->assign( "id1", "value", "val1" );
$objResponse->append( 'myform', "innerHTML", '<div id="mydiv2"></div>' );
    $objResponse->createInput("mydiv2", "text", "field[]", "id2" );
    $objResponse->assign( "id2", "value", "val2" );

    return $objResponse;
}

$xajax = new xajax();
$xajax->configure('debug',true);
$xajax->configure('verboseDebug',true);
$xajax->configure('javascript URI','/kbdev/xajax/');
$xajax->configure( 'errorHandler', true );
$xajax->configure( 'logFile', './kb_error_log.log' );
$xajax->register(XAJAX_FUNCTION, "addFields");
$xajax->processRequest();
$xajax->printJavascript();

?>
<form id = "myform" onSubmit="return false;">
<button onclick="xajax_addFields(xajax.getFormValues('myform')); return false;">Add new Fields</button>
</form>

2 (edited by cebasso 2012-03-26 8:15:49 PM)

Re: assigning values to more than 1 form fields is not working

try

function addFields()
{
  $objResponse=new xajaxResponse();
 
  //why not create your elements directly, (html)? like...
  $html = "
  <form name='myform' id='myform'>
  <div id="mydiv1">
  <input type='text' name='id1' id='id1' value='val1' size='20' maxlength='10'>
  <input type='text' name='id2' id='id2' value='val2' size='20' maxlength='10'>
  <select size='1' name='myselect' id='myselect'>
  <option value='1'>One</option>
  <option value='2'>Two</option>
  <option value='3'>Three</option>
  </select>
  </div>
  </form>
  </div>
  ";
 
  $objResponse->Assign('mydiv', 'innerHTML', $html); //or utf8_encode($html);
  return $objResponse;
}

<body>
<div id='mydiv' name='mydiv'><button onclick="xajax_addFields();">Add new Fields</button></div>
</body>