0

I have a dynamic build selection list. The selection list holds "Permit" strings what the user adds to a selection list before recording the form data.

I would like to save all the values of the select box to a string, selected or not selected. Can someone pl explain how would I proceed iterating through the selection box and appending to a string all option values of the dynamicly created selection?

thank you for your smarts and time

function PermitAdd() {
var formObject = document.frmJob
if (formObject.TxtPermitNr.value!="" && formObject.TxtPermitNr.value!="") {
    addOption(formObject.lstPermits,formObject.TxtPermitNr.value,formObject.TxtPermitNr.value)
} else {
    alert("Fill permit text field ")
}

}

....

    <tr>
  <td width="25%">Permit #: </td>
  <td width="9%"><input name="TxtPermitNr" type="text" id="TxtPermitNr" value="<?php echo $strTxtPermitNr;?>" size="10" maxlength="20" />        </td>
  <td width="10%"><input name="button2" type="button" onclick="PermitAdd()" value="Add"/></td>
  <td width="16%"><div align="center">
    <select name="lstPermits" size="4" multiple="multiple" id="lstPermits">
    </select>
  </div></td>
  <td width="40%"><input name="button" type="button" onclick="PermitDelete()" value="Del"/></td>
</tr>

...

now in my php code where I save the form to the database i would like to have a string of all the values in lstPermits

    $strTxtPermitArr[] = trim($_POST['lstPermits']);
foreach($strTxtPermitArr as $key => $value){
    $strTxtPermitNr .=  $key ." - " . $value ." ";
}
Vincent
  • 1
  • 1
  • I don't understand your question. Mind to show some code? – Jürgen Thelen Apr 24 '11 at 18:01
  • the values are not posted is it possible to read the selection objects options and values? – Vincent Apr 24 '11 at 18:22
  • How is PHP supposed to know the options created by Javascript, if you don't POST or GET them to the PHP script? – Jürgen Thelen Apr 24 '11 at 18:26
  • correct, the list I reuse later to rebuild a list where users can add or delete more permit data – Vincent Apr 24 '11 at 18:29
  • can you come up with a solution? so I can save the permit list to a string and rebiuld later when needed – Vincent Apr 24 '11 at 18:31
  • maybe i force, when the form gets recorded, all options to be selected in multiple select ? – Vincent Apr 24 '11 at 18:33
  • You can not know all the values in PHP unless you POST them along. To do this just add a hidden text field and put all the option values in it with Javascript (since only Javascript knows what options there are). – Halcyon Apr 24 '11 at 18:36
  • I think you want to POST all dynamically created option values, whether they were selected or not. Just use a `` field and populate the hidden field with all dynamically created option values. – Jürgen Thelen Apr 24 '11 at 18:38
  • Jürgen I thought about this hidden field ... wanted to see if there would be another solution other then writing not only a append to the hidden field function as well I would need a delete a permit number from the hidden field string in case the user made a error. wished I just could save the permit list easier ... maybe the best is not to use a selection box – Vincent Apr 24 '11 at 18:45

2 Answers2

0

you can do this simple by dynamic generating hidden field with all values - just edit your PermitAdd() to

  1. add option as it does now
  2. add value to your hidden element

Otherwise you can generate it in onSubmit action.

I think that select can send only selected values and not all of them.

Zap
  • 259
  • 1
  • 3
  • 10
0

Maybe this question can give you some help. There are many questions of this type, just search for input, array and maybe php or html.

Community
  • 1
  • 1
Florian
  • 3,145
  • 1
  • 27
  • 38