Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2014-02-21
2
366 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
ID: 39877379
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
ID: 39879476
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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
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…

789 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