Get another variable

Posted on 2006-04-19
Last Modified: 2006-11-18
So, I have this script, and it feeds a bunch of variables to the next form.  But due to how the form is layed out, and for a viewer's perspective, we don't ask one variable.  So when the user clicks submit, I route them to another page, and ask them that one question.  Is there a way to do this via javascript or something, so when they click submit, I would pop up the window and get that last variable??

And if so, any way to do any checking (i.e. I'd be looking for a number, so if they put in text, I could just reassert the window or something?)

Thank you.
Question by:dougp23
    LVL 11

    Expert Comment

    You can hidden variables which stores users responses with a particular seperator and based on this values in the next page you can do some maipulation.
    LVL 17

    Accepted Solution

    Hi dougp23,

    You can do something like this in javascript, and I will show you an example, but I suggest that you find another way to do this without javascript because javascript is client-side and it can be compleetely disabled by the user.  PHP or ASP, are server-side scripts that will run 100% of the time.  Still, PHP cannot make a popup, so in the end that final question should be attached to that form or something convient, for now here is a javascript example:

    <script type="text/javascript">
    function askQuestion()
      var input = prompt("Are you scared!? Answer on a 0-10 scale!");
      if (isNaN(input) || input < 0 || input > 10)
        alert("Must be a Number from 1-10!");
        return false;
      document.getElementById("hide").value = input;
      return true;

    <h3>Here is a makeshift form, you don't need to do anything but push the submit button!</h3>
    Name: <input type="text" name="NAME">
    <input type="hidden" name="HIDDEN" id="hide">
    <input type="submit" value="submit" onclick="return askQuestion();">

    Test it out, it just has a javascript prompt() that asked for a number for 0 to 10 =)
    Joe P

    Featured Post

    How to improve team productivity

    Quip adds documents, spreadsheets, and tasklists to your Slack experience
    - Elevate ideas to Quip docs
    - Share Quip docs in Slack
    - Get notified of changes to your docs
    - Available on iOS/Android/Desktop/Web
    - Online/Offline

    Join & Write a Comment

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    Consider the following scenario: You are working on a website and make something great - something that lets the server work with information submitted by your users. This could be anything, from a simple guestbook to a e-Money solution. But what…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

    745 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

    17 Experts available now in Live!

    Get 1:1 Help Now