Basic HTML If statment

in Genius Bar edited January 2014
Ok, i know this is nto Apple related but you guys are better than any of the other foruims that i am a member of.

I need to do a basic if statment on a web page that i am developing. Bassicailly what I want to do is have a user enter a code, lets say 123, click submitt and be redirected to 123.php or what ever page.




  • Reply 1 of 13
    xoolxool Posts: 2,460member
    Here's a solution. This is a form that triggers a javascript which performs the redirect. I didn't add comments or test in any browsers other than Safari.




    <script type="text/javascript">

    function processForm()


    if (document.entryForm.code.value != '')


    document.location=document.entryForm.code.value + ".html";

    return false;




    alert("You messed up!");

    return false;






    <form name="entryForm">

    <input name="code">

    <a href="javascript : processForm();">Go!</a>




  • Reply 2 of 13
    kickahakickaha Posts: 8,760member

    HTML has no if statement. It is a non-computative markup language.

    Javascript has an if statement. It is a Turing-complete computational language that can be embedded as a script element in HTML.

  • Reply 3 of 13
    jhazeljhazel Posts: 28member
    You can also do this very easily with ASP. Are you wanting the pages to be created on the fly or will these "123" pages already be there. In other words, what if I type in 456 and there isn't a 456 page... are you wanting it to be created on the fly or should I receive an error message indicating an invalid code...?
  • Reply 4 of 13
    agallantagallant Posts: 87member
    The pages are allready there.
  • Reply 5 of 13
    jhazeljhazel Posts: 28member
    Would you rather them have a drop down list to select one of the codes or do you want them to be able to type in an incorrect code and receive an error message?
  • Reply 6 of 13
    agallantagallant Posts: 87member
    I would rather them gen an error message. The point of this is our clients are having there subcontractors sighnup for a new service with us we are gathering there(the subs) information so we can send emails out to the subs when our clients need to send out a bid. Right now they are doing it by paper. We do not want the subs to see which clients have sighned up for this service. we only want them registering with the client that requested it. So we do not want john the carpet man to see that abc construction is gathering vender information when he (john) was only invited to sighn up with acme construction co.

    So what we are doing is sending out one final mailing to tell the subs that if they wat to get bid requests they need to go to our website and enter in the code for the construction company that is requisting there infromation
  • Reply 7 of 13
    jhazeljhazel Posts: 28member
    How many codes do you have? Sorry for all the questions but I like to be able to see the whole picture before throwing a solution out there. Can you email me a list of all the codes? I can write and test the structure real quick and shoot it back to you...
  • Reply 8 of 13
    agallantagallant Posts: 87member
    Therre is only only a hand full of clients that are using this. I don't see more than 10 or so. Maybe this will help it is not in production yet but ther section where it says Private Invination is what i am trying to get to work and security is not a major concern so if they want to view the source and see what other codes ther are i don't care, we just can not make it easy for them by using a drop down menu.

  • Reply 9 of 13
    jhazeljhazel Posts: 28member
    Okay, do this. Add a blank page to your site. It needs to end in .asp (whatever.asp). Set your form's action to point to this page. Then, on this page place this code at the top:


    dim sendto, invitation

    invitation = request.form("textfield")


    select case invitation

    case "abc"

    \tsendto = "abc.html"

    case "123"

    \tsendto = "123.html"

    case else

    \tsendto = "error.html"

    end select



    Just add a new case statement for each invitation you have. Also, either create an error page that will redirect them back to the main page or, if you already have an error page, change the case else statement to reflect your current error page. This page will not even be seen. It just acts as an intermediary processing page to do a little redirection.
  • Reply 10 of 13
    agallantagallant Posts: 87member
    What does the invitation = request.form("textfeld") do?

    When you say at the top what do you mean? before the <html> tag?
  • Reply 11 of 13
    jhazeljhazel Posts: 28member
    It really doesn't matter where it is on the page... I just said at the top for ease of explanation. You can place it right after your </head> tag if you want...

    The invitation = request.form("textfeld") string grabs the value they entered on the previous form. Here's the breakdown:

    invitation: Just a variable created on this page to be used in the select/case statement.

    request.form: The VB command telling it to look at the form from where the page was called.

    ("textfield"): Tells which field from the form to assign to the variable. On your page you posted you have the field name set to textfield. If you change'll need to change this as well.

    Hope that helps.
  • Reply 12 of 13
    karl kuehnkarl kuehn Posts: 756member
    jhazel: You do realize you are on a Mac centric board, and therefor most of the people are not using windows server, and thus do not have ASP? This is just as trivial to do as PHP, however the person has to have a host with scripting available.
  • Reply 13 of 13
    jhazeljhazel Posts: 28member
    Good point Karl. I actually develop ASP pages primarily for Linux servers and also Windows servers but I did forget where I was posting...
Sign In or Register to comment.