[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 560
  • Last Modified:

Form field concatenation


OVERVIEW:
Need to concatenate two form fields and pass the result with the form submission.

PSEUDOCODE EXAMPLE:
<FORM name="frm_Join" METHOD="POST" ACTION="http://www.aweber.com/scripts/newlead.pl">

      <input type="text" name="custom txt_FirstName" id="firstname">
      <input type="text" name="custom txt_LastName" id="lastname">

      <SCRIPT LANGUAGE="JavaScript">
            <!-- Start
            function showFullName()
            {
            var jFirstName = document.getElementById("firstname").value
            var jLastName  = document.getElementById("lastname").value
            var jFullName  = jFirstName + " " + jLastName
            document.frm_AffJoin.name.value = jFullName
            }
      // End -->
      </SCRIPT>

      <INPUT TYPE="HIDDEN" NAME="FullName" value="FirstName LastName">

</form>

SOLUTION REQUIRED:
For the hidden FullName field to pass a concatenation of FirstName+" "+LastName when the form is submitted.

CONDITIONS:
The name of the FirstName and LastName input fields has to be two words, starting with "custom". That is a requirement of the Perl target script. That's why I'm trying to use ID.

EXPLANATION:
My JavaScript is almost non-existent, but I have tried to reach a solution by concatenating the FirstName and LastName fields in javascript, and pass the jFullName variable to the hidden field, but I don't know how to do it and everything I have tried fails. I've cut down the code just to show clearly what I am trying to do.

Thanks in advance for any help.
 - Bill H.
0
BillHely
Asked:
BillHely
  • 2
  • 2
1 Solution
 
sajuksCommented:
//r u trying something like this
<SCRIPT LANGUAGE="JavaScript">
<!-- Start
function showFullName()
    {
          var jFirstName = document.getElementById("firstname").value
          var jLastName  = document.getElementById("lastname").value
          var jFullName  = jFirstName + " " + jLastName
          document.frm_Join.FullName.value = jFullName
      }
// End -->
</SCRIPT>

<FORM name="frm_Join"  ACTION="http://search.google.com" onsubmit = "showFullName()">
     <input type="text" name="custom txt_FirstName" id="firstname">
     <input type="text" name="custom txt_LastName" id="lastname">
     <INPUT TYPE="HIDDEN" NAME="FullName" value="FirstName LastName">
     <INPUT TYPE="submit">
</form>

0
 
BillHelyAuthor Commented:

Thanks sajuks. I'll try your suggestion in the morning as I am about to go out.

However, I assume I should also remove the "value" term from:

<INPUT TYPE="HIDDEN" NAME="FullName" value="FirstName LastName">

so it reads:

<INPUT TYPE="HIDDEN" NAME="FullName">

 - Bill H.
0
 
sajuksCommented:
that is anyway removed when the function is called
 document.frm_Join.FullName.value = jFullName
but yes you can remove it
0
 
BillHelyAuthor Commented:
Thanks sajuks. That works fine.

 - Bill H.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now