Note that there are some explanatory texts on larger screens.

plurals
  1. POChanging form variables and need to change javascript to new variables
    primarykey
    data
    text
    <p>I am a complete newbie to javascript. I have some js on my website that is handling hiding some divs in a form. I'm wanting to change some of the values of the form, and I'm confused by some of the syntax of the javascript. Here is the html and script that I am working with:</p> <pre><code>&lt;div class="outeremailcontainer"&gt; &lt;div id="emailcontainer"&gt; &lt;?php include('verify.php'); ?&gt; &lt;form action="../index_success.php" method="post" id="sendEmail" class="email"&gt; &lt;h3 class="register2"&gt;Newsletter Signup:&lt;/h3&gt; &lt;ul class="forms email"&gt; &lt;li class="name"&gt; &lt;label for="yourName"&gt;Name: &lt;/label&gt; &lt;input type="text" name="yourName" class="info" id="yourName" value="&lt;?php echo $_POST['yourName']; ?&gt;" /&gt;&lt;br /&gt; &lt;/li&gt; &lt;li class="city"&gt;&lt;label for="yourCity"&gt;City: &lt;/label&gt; &lt;input type="text" name="yourCity" class="info" id="yourCity" value="&lt;?php echo $_POST['yourCity']; ?&gt;" /&gt;&lt;br /&gt; &lt;/li&gt; &lt;li class="email"&gt; &lt;label for="emailFrom"&gt;Email: &lt;/label&gt; &lt;input type="text" name="emailFrom" class="info" id="emailFrom" value="&lt;?php echo $_POST['emailFrom']; ?&gt;" /&gt; &lt;?php if(isset($emailFromError)) echo '&lt;span class="error"&gt;'.$emailFromError.'&lt;/span&gt;'; ?&gt; &lt;/li&gt; &lt;li class="buttons email"&gt; &lt;button type="submit" id="submit"&gt;Send&lt;/button&gt; &lt;input type="hidden" name="submitted" id="submitted" value="true" /&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/form&gt; &lt;div class="clearing"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and the script:</p> <pre><code>&lt;script type="text/javascript"&gt; $(document).ready(function(){ $('#emailFrom') .focus(function(){ if ($('#overlay').length) { return; } // don't keep adding overlays if one exists $('#sendEmail') .find('.name, .city').slideDown(300, function(){ $(this).show(); }); $('.outeremailcontainer').css({ position: 'relative', bottom: 0, left: 0, zIndex: 1001 }); $('&lt;div id="overlay"&gt;&lt;/div&gt;').appendTo('body'); }); $('#overlay').live('click', function(){ $('#sendEmail') .css({ backgroundColor : 'transparent' }) .find('.name, .city').slideUp(300); $('.outeremailcontainer').css({ position : 'static' }); $('#overlay').remove(); }); }); </code></pre> <p></p> <p>There is also a script at the bottom of the page in an include:</p> <pre><code>$(document).ready(function(){ $('#emailFrom') .focus(function(){ if ($('#overlay').length) { return; } // don't keep adding overlays if one exists $('#sendEmail') .find('.name, .city').slideDown(300, function(){ $(this).show(); }); $('.outeremailcontainer').css({ position: 'relative', bottom: 0, left: 0, zIndex : 1001 }); $('&lt;div id="overlay"&gt;&lt;/div&gt;').appendTo('body'); }); $('#overlay').live('click', function(){ $('#sendEmail') .css({ backgroundColor : 'transparent' }) .find('.name, .city').slideUp(300); $('.outeremailcontainer').css({ position : 'static' }); $('#overlay').remove(); }); }); $(document).ready(function(){ $("#submit").click(function(){ $(".error").hide(); var hasError = false; var emailReg = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/; var emailFromVal = $("#emailFrom").val(); if(emailFromVal == '') { $("#emailFrom").after('&lt;span class="error"&gt;&lt;br /&gt;You forgot to enter the email address to send from.&lt;/span&gt;'); hasError = true; } else if(!emailReg.test(emailFromVal)) { $("#emailFrom").after('&lt;span class="error"&lt;br /&gt;&gt;Enter a valid email address to send from.&lt;/span&gt;'); hasError = true; } var yourNameVal = $("#yourName").val(); if(yourNameVal == '') { $("#yourName").after('&lt;span class="error"&gt;&lt;br /&gt;You forgot to enter your name.&lt;/span&gt;'); hasError = true; } var yourCityVal = $("#yourCity").val(); if(yourCityVal == '') { $("#yourCity").after('&lt;span class="error"&gt;&lt;br /&gt;You forgot to enter your city.&lt;/span&gt;'); hasError = true; } if(hasError == false) { $(this).hide(); $("#sendEmail li.buttons").append('&lt;img src="/wp-content/themes/default/images/template/loading.gif" alt="Loading" id="loading" /&gt;'); $.post("/includes/sendemail.php", //emailTo: emailToVal, { emailFrom: emailFromVal, yourName: yourNameVal, yourCity: yourCityVal }, function(data){ $("#sendEmail").slideUp("normal", function() { $("#sendEmail").before('&lt;h3 class="register2"&gt;Thank you! You\'re on the email list!&lt;/h3&gt;&lt;p class="emailbox"&gt;Click &lt;a href="xxx"&gt;HERE&lt;/a&gt; for your free song.&lt;/p&gt;'); }); } ); } return false; }); }); </code></pre> <p>The above code all works just fine. However, I am wanting to use a different form action with some different variables. The form part of the code will need to look like this:</p> <pre><code> &lt;div class="outeremailcontainer"&gt; &lt;div id="emailcontainer"&gt; &lt;?php include('verify.php'); ?&gt; &lt;form action="https://madmimi.com/signups/subscribe/66160" method="post" id="mad_mimi_signup_form" class="email"&gt; &lt;h3 class="register2"&gt;Newsletter Signup:&lt;/h3&gt; &lt;ul class="forms email"&gt; &lt;li class="name"&gt; &lt;label for="signup_name"&gt;Name: &lt;/label&gt; &lt;input type="text" name="signup[name]" class="info" id="signup_name" value="&lt;?php echo $_POST['signup_name']; ?&gt;" /&gt;&lt;br /&gt; &lt;/li&gt; &lt;li class="city"&gt;&lt;label for="signup_city"&gt;City: &lt;/label&gt; &lt;input type="text" name="signup[city]" class="info" id="signup_city" value="&lt;?php echo $_POST['signup_city']; ?&gt;" /&gt;&lt;br /&gt; &lt;/li&gt; &lt;li class="email"&gt; &lt;label for="signup_email"&gt;Email: &lt;/label&gt; &lt;input type="text" name="signup[email]" class="required" id="signup_email" value="&lt;?php echo $_POST['signup_email']; ?&gt;" /&gt; &lt;?php if(isset($emailFromError)) echo '&lt;span class="error"&gt;'.$emailFromError.'&lt;/span&gt;'; ?&gt; &lt;/li&gt; &lt;li class="buttons email"&gt; &lt;button type="submit" id="webform_submit_button"&gt;Send&lt;/button&gt; &lt;input type="hidden" name="submitted" id="submitted" value="true" /&gt; &lt;/li&gt; &lt;/ul&gt; &lt;/form&gt; &lt;div class="clearing"&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>I can't figure out which of the js code I will need to change for the div hiding actions to still work with the new values. Can anyone help with this? Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload