SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Feb 2006
    Location
    Chepstow, South Wales
    Posts
    777
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Read value of hidden input field from previous page

    I have a hidden input area within a form on a page:

    Code:
    <form id="contactForm" method="post" action="../scripts/sendmail_cdo.asp" style="background:#E6E7E8; padding:10px;">
    <div id="emailDiv">
    <input type="text" name="email" autocomplete="off" value="">
    </div>
    </form>
    On the page the form is submitted to, at the very top of the page I have my script, to check if the input has a value or not, just testing both to try and get it to work, and it doesnt seem to recognise my code, basically its not re-directing to any of the pages below

    Code:
    <script>
    var val = document.getElementById('email').value;
    if (/^\s*$/.test(val)){
    self.location="contact/index1.asp"; 
    } else {
    self.location="contact/index2.asp";  
    }
    </script>
    Not sure what Im doing wrong.

    Cheers

  2. #2
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The value isn't accessible from the DOM since it doesn't exist there anymore, rather it will currently be existing in the POST array of the page (since that is how you sent the form). In PHP you would access it with something like var email = $_POST['email'] . In asp however, it might be something like Request.Form['email'] but I'm not entirely familiar with asp and it might depend on what server language you're using.

    If you want to do it entirely in Javascript though, you would move the validation onto the same page as the form and redirect there or do it via AJAX.

  3. #3
    SitePoint Member
    Join Date
    Dec 2013
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry that PHP solution should be $email not var email. And I also noticed that you're also trying to call the element by ID without setting the ID on the input element, which is something you'll also have to do if you do the same page javascript validation solution.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •