Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5

Thread: Form link

  1. #1
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Form link

    Is there anyway that i can create a form, where depending on what the viewer types depends on what webpage they go to. I have a page where i want it to go.
    For example. The viewer is on the home page (0), on that page there is a form. If they type in 1 it will go to page (1) or if they type in 2 it will go to (2), but if they type in a page that does not exist they get a custom error.

    I'm not even sure this is the right section to put it in.

  • #2
    Senior Coder koyama's Avatar
    Join Date
    Dec 2006
    Location
    Copenhagen, Denmark
    Posts
    1,246
    Thanks
    1
    Thanked 5 Times in 5 Posts
    From your description it is not clear whether the user is required to click a submit button or not after selecting the number.

    In any case, either way, to get what you want you would need either server-side scripting (e.g. php) or JavaScript.

  • #3
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well i want the users to click submit, and i would rather use javascript, does anyone know what to do with it

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Having a navigation system that relies solely on javascript is very bad from an accessibility point of view. Not everyone has javascript enabled. I don't have javascript enabled by default. Here is how you do it with javascript.
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <title>Untitled Document</title>
    <script type="text/javascript">
    function goTo()
    {
    	
    	var el = document.getElementById('pagenum').options[document.getElementById('pagenum').options.selectedIndex].value;
    	if(el == 'none')
    	{
    		alert('You have not chosen a page number.');
    	}
    	else
    	{
    		window.location = el;
    	}
    	return false;
    }
    </script>
    </head>
    <body>
    <form action="#" method="post" onsubmit="return goTo(this.pagenum.value)">
      <select name="pagenum" id="pagenum">
        <option value="none">Choose a page</option>
        <option value="page1.html">Page 1</option>
        <option value="page2.html">Page 2</option>
        <option value="page3.html">Page 3</option>
        <option value="page4.html">Page 4</option>
      </select>
      <input type="submit" value="Go">
    </form>
    </body>
    </html>
    I think the select menu is a little more user friendly than an input box.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New to the CF scene
    Join Date
    May 2007
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks alot mate. that seems great, but just out of interest what would need to be changed to make it an input box
    Last edited by flyingspacebar; 05-23-2007 at 09:37 AM.


  •  

    Posting Permissions

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