RootsWeb.com Mailing Lists
Total: 2/2
    1. Re: [FreeHelp] Javascript to remove blank/empty fields from html form
    2. Roger Hendrix
    3. Pat: Thanks for the response. I understand about the mailmerge template. So, I did some more searching and found that I can use the action="mailto:someone@somewhere.com" instead of pointing to the mailmerge cgi. This works; however, I still have the problem of getting all of the blank fields. The JavaScript that I found on the internet that is supposed to strip the blank/empty fields follows: ======================================================= function removeBlankFields() { var i, x; var inputs = document.getElementsByTagName("input"); var removeList = new Array(); for (i = 0; i < inputs.length; i++) { if (inputs[i].value = ""); { removeList.push(inputs[i]); } } for (x in removelist) { removeList[x].parentNode.removeChild(removeList[x]); } } ============================================ This function is called from by the form using the onsubmit function: <form onsubmit="removeBlankFields()" action="mailto:rphendrix1@gmail.com" method="post" enctype="application/x-www.form-urlencoded"> However, this does not remove the blank/empty fields before submitting the form is submitted! So, can someone out there point me in the right direction? Roger Hendrix -----Original Message----- From: Pat Asher [mailto:pjroots@att.net] Sent: Sunday, May 27, 2012 7:42 AM To: Roger Hendrix Cc: freepages-help@rootsweb.com Subject: Re: [FreeHelp] Javascript to remove blank/empty fields form html form At 06:13 PM 5/26/2012, Roger Hendrix wrote: >I am looking for a working fully functional JavaScript that will remove >blank/empty fields from an html form before the form submit function >sends the form on the it's final destination. >Consider the Family Group Sheet found at the following: >http://freepages.genealogy.rootsweb.ancestry.com/~gearyfamily/family-gr >oup-s >heet.html >I was considering using the form; however, I would like to receive the >only the fields that were filled in by the sender. If you are using Mailmerge to send an output file, the output is controlled by the template, which does not recognize whether something has been entered in a field. It sends all fields it has been scripted to send, whether they contain an entry or not. Pat Asher

    05/27/2012 03:45:13
    1. Re: [FreeHelp] Javascript to remove blank/empty fields from html form
    2. Barry Carlson
    3. Roger, The following script has been tried with Pat Asher's FGS Form and eliminates empty inputs. <script> function check_myForm(){ var inputs = document.getElementsByTagName("input"); for (var i=0; i < inputs.length; i++) { if (inputs[i].getAttribute('type') == 'text' && inputs[i].value ==''){ inputs[i].setAttribute('name',''); } } } </script> The script is relatively simple, and works as follows:- The var inputs = document.getElementsByTagName("input") gathers a list of the input tags associated with the form which are then looked at sequentially by the for (var i=0; i < inputs.length; i++) function which is a "for" loop looking for the following TRUE conditions:- inputs where the type = "text" AND where the inputs value = "null". When those conditions are met, it removes existing text associated with the 'name' attribute. I have only tested it in "mailto:", though I suspect it can be made to work using MailMerge, as received data will be allocated to 'name' fields in your template, and missing data will of course leave a blank field. Put the script in the <head> section and modify the top line of your form as follows:- <form id="myForm" action="mailto:you@domain.com" method="post" onsubmit="return check_myForm();" enctype="application/x-www.form-urlencoded"> Barry

    05/29/2012 02:04:00