Solved

HTML "form" multiple conditional actions for user email sign-up using javascript.

Posted on 2014-02-21
2
362 Views
Last Modified: 2014-03-06
I have two forms: form 1 uses external API, form 2 uses server side PHP. Both forms ask for email. Both work fine but require double entry.

Code form 1:
<form action="http://some.link.com" method="post" target="_blank"><input type="text" name="btr_email" placeholder="Email"><input type="hidden" name="btr_url" value="http://other.link.com"><br>
<input type="hidden" name="schedule_type" value="0"><input type="submit" value="Follow"></form>

Open in new window


Code form 2:
<form class="sml_subscribe" method="post"><input class="sml_hiddenfield" name="sml_subscribe" type="hidden" value="1"><p class="sml_name"><label class="sml_namelabel" for="sml_name">Name:</label><input class="sml_nameinput" placeholder="Name..." name="sml_name" type="text" value=""></p><p class="sml_email"><label class="sml_emaillabel" for="sml_email">Email:</label><input class="sml_emailinput" name="sml_email" placeholder="Email Address..." type="text" value=""></p><p class="sml_submit"><input name="submit" class="btn sml_submitbtn" type="submit" value="Submit"></p></form>

Open in new window


What I need:
1. Remove form 2
2. Add check box in form 1, if checked:
                 
                 -make name input field from form 2 visible
                 -pass email address to form 2
 3. Submit to both forms when "Follow" button is pressed.

Thanks!
0
Comment
Question by:Sanction
2 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 250 total points
Comment Utility
The easiest way to do this is to use PHP to parse the initial form submission and then send the form data to the desired targets.
0
 
LVL 9

Expert Comment

by:Sar1973
Comment Utility
1. I'd rather suggest to hide the form rather then removing it from the HTML structure;
2. add an onchange event to the check object that performs:
-document.getElementById("myField").style.display = "inline";
-document.getElementById("myField2").value=document.getElementById("myEmail1");
3. add an onclick event to the button that performs: document.getElementById("myForm2").submit();
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

7 Experts available now in Live!

Get 1:1 Help Now