www.webdeveloper.com
Results 1 to 3 of 3

Thread: Dynamic Method Link Action URl ... How ?

  1. #1
    Join Date
    May 2008
    Posts
    19

    Dynamic Method Link Action URl ... How ?

    Hi,

    I want to change the url dependant on a question result "Do you wish to continue ?'"

    so if :
    document.forms[0].continue is equal to Yes go to url A
    document.forms[0].continue is equal to No go to url B

    so i want a way to pass a parameter to :

    <form METHOD="LINK" ACTION="targeturl..."

    any help greatly appreciated , see current working code below.

    Thanks

    Code:
      <script type="text/javascript">
    //	var f =  document.forms["myform"];
    	
    	function validate() {
    
    	if((document.forms[0].age[0].checked==false)&&(document.forms[0].age[1].checked==false))
    		{
    		alert('Are you aged 18-25 ?');
    		return false
    		} 
    
    	if((document.forms[0].dyslexic[0].checked==false)&&(document.forms[0].dyslexic[1].checked==false))
    		{
    		alert('Are you dyslexic ?');
    		return false
    		} 
    	if((document.forms[0].continue[0].checked==false)&&(document.forms[0].continue[1].checked==false))
    		{
    		alert('Do you wish to continue ?');
    		return false
    		} 
    	}
    	
    	</script>
    </head>
    
    <body>
    
     <form  METHOD="LINK" ACTION="http://www.site.com/page1.htm" onsubmit="return validate()" >
       <p> Age : 18-25 Yes:
         <input type="radio" name="age" />
         No: <input type="radio" name="age" />
         <br />
         
         Dyslexic : Yes: 
         <input type="radio" name="dyslexic" />
         No: <input type="radio" name="dyslexic" />
         <br />
         Continue : Yes: 
         <input type="radio" name="continue" />
         No: <input type="radio" name="continue" />
         <br />
         <input type="submit" value="Submit">
       </p>
    </form>

  2. #2
    Join Date
    Oct 2005
    Posts
    843
    There are lots of ways to do this, one way is a JavaScript function like:
    Code:
    function formSubmission()
    {
    	document.location = (document.forms[0].continue[0].checked) ? "http://www.google.ca" : "http://www.bing.ca";
    }
    With a button like so:
    Code:
    <input type="button" value="Submit" onclick="formSubmission()">
    So Continue: Yes goes to Google while Continue: No goes to Bing

    Also, LINK isn't a valid attribute of method, the two valid ones are "post" or "get"
    Welsh

  3. #3
    Join Date
    May 2008
    Posts
    19
    Thank you.

    works just great now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles