Selection form with JavaScript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Gergely Kantor
    New Member
    • Nov 2010
    • 3

    Selection form with JavaScript

    Hi,


    I'm a beginner in javascript programing, but I guess that my problem is easy.
    I'd like to make a dynamic selection form with some simple questions. I mean that a message pops up before hitting Submit. For example: Do you live in EU? Answer yes or no. It's easy but I want if anybody choose the "bad" answer a line or window appears and tells that "You are not eligable for selection" or something like this.

    I hope somebody can help me!

    Best regards
  • RamananKalirajan
    Contributor
    • Mar 2008
    • 608

    #2
    Use onsubmit in the form tag to trigger a function call before submitting a form. You can use confirm to get the input from user if you have only yes or no.

    Thanks and Regards
    Ramanan Kalirajan

    Comment

    • Bharat383
      New Member
      • Aug 2011
      • 93

      #3
      Code:
      <form name="form1" onsubmit="return check_me()">
      		Name :: <Input type="text" name="name1" value="" id="name1" />
      		<br />
      		Address :: <textarea></textarea>
      		<br />
      		City :: <input type="text" name="city" value="" id="city" />
      		<br />
      		<input type="submit" name="submit_btn" value="SUBMIT" />
      	</form>
      
      
      <script type="text/javascript">
      	function check_me()
      	{
      		if(confirm("Do you live in EU? "))
      		{
      			return true;
      		}
      		else
      		{
      			alert("You are not eligable for selection");
      			return false;
      		}
      	}
      </script>
      Last edited by acoder; May 23 '12, 10:40 PM. Reason: Please use [code] tags

      Comment

      Working...