Login Retreive lost passwordRegister
Search

Forum Index / Feedback / Add extra values

[ This topic is solved ]

  ferdinant 05 March 05 / 21:13  
Frequently, I have the need to add some values to a ListField. I know that I can add values to the array.
But that's not my point. It seems pretty handy to me, that the FH could be expanded with an extra textfield to add values.

For example, I have this listField


Brands :  On        Off
         |---------|---------|
         | Nike    | Puma    |
         | Adidas  |         |
         |         |         |
         ---------------------

But what if I dynamically would like to add the Brand 'Reebok' or 'Converse'. Because, those are the brands I need.

I should modify the array or put new values in the table from where the array has been made of.

Is there no way to make this more simple?

  Mels van Kooten 06 March 05 / 16:41  
Changed at 06 March 05 / 16:50
It is possible to create this with javascript.
Have you tried it?

  ferdinant 06 March 05 / 18:49  
Changed at 06 March 05 / 18:51
I am not that good @ javascript.

Maybe you have some example script for me?

And I think it should be usefull when you put this on this site, because there might be other users who think this might be extremely handy.

  Teye Heimans (Founder) 07 March 05 / 09:26  
 Quote: ferdinant
 
I am not that good @ javascript.

Maybe you have some example script for me?

And I think it should be usefull when you put this on this site, because there might be other users who think this might be extremely handy.


Here is an example:


<?php

echo 
"<script language='javascript'>\n".
"function addOption(fld, value, text) {\n".
"    var doc = fld.ownerDocument;\n".
"    if (!doc)\n".
"        doc = fld.document;\n".
"    var index = fld.options.length;\n".
"    var opt   = doc.createElement('OPTION');\n".
"    opt.value = value;\n".
"    opt.text  = text;\n".
"    fld.options.add( opt, index );".
"    fld.options[index].selected = true;\n".    
"}\n".    
"</script>\n";

// new $form object 
$form =& new FormHandler(); 

// the options 
$options = array(
  
=> "Option 1",
  
=> "Option 2",
  
=> "Option 3"
);

// options field
$form->listField ("Options""options"$options''true);

// button to add a option
$form->button(
  
"Add option"
  
"btnAddOption"
  
"onclick='addOption( ".
  
"  elements[\"options_ListOff\"],".
  
"  prompt(\"Enter the value of the field\", \"\"),".
  
"  prompt(\"Enter the text to display of the field\", \"\")".
  
")'" 
);

// button beneath it 
$form->submitButton("Save");

// set the 'commit after form' function 
$form->OnCorrect("doRun"); 

// flush the form 
$form->flush();
?>


  Mels van Kooten 07 March 05 / 11:45  
Nice work teye!!

  Top


powered by PHP-GLOBE   © 2004 - 2012 FormHandler. All rights reserved.   -   Open source license