Inmagic Forums
Inmagic Forums
Scripting
Javascript: copy the whole contents of one field to another field|
Go
![]() |
New
![]() |
Find
![]() |
Notify
![]() |
Tools
![]() |
Reply
![]() |
|
Hello
Could anyone help regarding tweaking one of the Sample Javascripts that is available in DBText help. The code that DBText gives you (Sample JavaScript Script 5) allows you to copy the first word of one field to another field (if the second field is empty) when the record is saved. I would like to copy the whole contents of one field to another field if the second field is empty when the record is saved. Apologies if this is really simple but I have tried tweaking the last part of the script but can't get it work but I'm not familiar with Javascript. Any ideas? I have reproduced the script below (including my field names) Many thanks Claire function onRecordSave() { var srcBox = Form.boxes("ExpertType"); if (srcBox) // be sure there is a box with the given name { var srcText = srcBox.content; if (srcText != "") // proceed only if the first box is nonempty { var tgtBox = Form.boxes("ExpertTypeAll"); if (tgtBox && tgtBox.content == "") // second box must exist and be empty { var allWords = srcText.split(" "); // allWords is an array of words tgtBox.content = allWords[0]; } } } } |
|||
|
For the last if statement, use:
if (tgtBox && tgtBox.content == "") {
tgtBox.content = srcText;
}
Peter Tyrrell, MLIS Director and Lead Developer Andornot Consulting Inc. http://andornot.com/about/developerblog http://twitter.com/andornot |
||||
|
Brilliant - the script is now doing just what I needed.
Thanks very much much Peter - you're a star! Claire p.s I have reproduced the whole script below just in case any other non-javascript experts need it in future. function onRecordSave() { var srcBox = Form.boxes("ExpertType"); if (srcBox) // be sure there is a box with the given name { var srcText = srcBox.content; if (srcText != "") // proceed only if the first box is nonempty { var tgtBox = Form.boxes("ExpertTypeAll"); if (tgtBox && tgtBox.content == "") // second box must exist and be empty { tgtBox.content = srcText; } } } } |
||||
|
| Powered by Eve Community |
| Please Wait. Your request is being processed... |
|
Inmagic Forums
Inmagic Forums
Scripting
Javascript: copy the whole contents of one field to another field
