1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Two simple website additions! but i'm stumped!

Discussion in 'HTML, Graphics & Programming' started by titchard, 14 May 2006.

  1. titchard

    Soldato

    Joined: 10 Feb 2004

    Posts: 5,116

    Location: Crewe, UK

    Hey!

    I have to add two pieces of code to an "Instant Store" website, within the little HTML sections that they provide!

    The two things need are to allow a person to pick two options (radio buttons possibly, like red and cat) and depending on the answers route them to a certain page!

    The other is to randomly pick a URL out of a list and forward the user onto that page!

    I'm just a bit stumped on how to do it!

    would anyone be able to help me out?

    Thanks in Advance!

    Rich
     
  2. Beansprout

    Man of Honour

    Joined: 31 Jan 2004

    Posts: 16,313

    Location: Plymouth

    Depends what this instant store thing is like - ask them, not us :)
     
  3. JustinW

    Associate

    Joined: 27 Dec 2005

    Posts: 97

    You will probably need some JavaScript to do this? Are you able to write JavaScript?

    Justin
     
  4. titchard

    Soldato

    Joined: 10 Feb 2004

    Posts: 5,116

    Location: Crewe, UK

    'Fraid not, but I get that the first request I made is just a series of "IF" Statements, i've just never touched JavaScript before.

    Rich
     
  5. JustinW

    Associate

    Joined: 27 Dec 2005

    Posts: 97

    Hi,

    I was more getting at- will the instant store allow you to include JavaScript on the pages.

    JavaScript is quite simple, take a look at W3 Schools for a tutorial on JavaScript.

    Also, remember that JavaScript can be disabled by the client, so your customers can bypass it.

    Justin
     
  6. titchard

    Soldato

    Joined: 10 Feb 2004

    Posts: 5,116

    Location: Crewe, UK

    Alright!

    I have got this far!

    Code:
    <html>
    <body>
    
    <script type="text/javascript">
    if (radio_button.radio_young.checked and radio_button.radio_dry.checked)
    {
    function forward(){
    location.href="YOUR YOUNG / DRY LINK HERE"
    }
    if (radio_button.radio_young.checked and radio_button.radio_normal.checked)
    {
    function forward(){
    location.href="YOUR YOUNG / NORMAL LINK HERE"
    }
    if (radio_button.radio_young.checked and radio_button.radio_greasy.checked)
    {
    function forward(){
    location.href="YOUR YOUNG / GREASY LINK HERE"
    }
    if (radio_button.radio_old.checked and radio_button.radio_dry.checked)
    {
    function forward(){
    location.href="YOUR OLD / DRY LINK HERE"
    }
    if (radio_button.radio_old.checked and radio_button.radio_normal.checked)
    {
    function forward(){
    location.href="YOUR OLD / NORMAL LINK HERE"
    }
    if (radio_button.radio_young.checked and radio_button.radio_dry.checked)
    {
    function forward(){
    location.href="YOUR OLD / GREASY LINK HERE"
    }
    </script>
    <form>
    <input type="radio" value="Young" name="radio_young">Young
    <br>
    <input type="radio" value="Old" name="radio_old">Old
    <br>
    </form>
    <form>
    <input type="radio" value="Dry" name="radio_dry">Dry
    <br>
    <input type="radio" value="Normal" name="radio_normal">Normal
    <br>
    <input type="radio" value="Greasy" name="radio_greasy">Greasy
    <br>
    <input type="submit" value="Submit">
    </form>
    
    </body>
    </html>
    How do I get it to run when I click submit!!

    I'm a bit stumped!

    Rich
     
  7. JustinW

    Associate

    Joined: 27 Dec 2005

    Posts: 97

    <input type="submit" value="Submit" onclick="functionname()" />

    HTH,
    Justin
     
  8. titchard

    Soldato

    Joined: 10 Feb 2004

    Posts: 5,116

    Location: Crewe, UK

    You sir, have earned yourself a huge bag of Cookies!

    Rich
     
  9. titchard

    Soldato

    Joined: 10 Feb 2004

    Posts: 5,116

    Location: Crewe, UK

    wait!

    Do I know stick all those IF statments into the brackets on the function() bit?

    Rich
     
  10. JustinW

    Associate

    Joined: 27 Dec 2005

    Posts: 97

    Yep,

    Stick all the code you want execute into a function. i.e.

    function functionName(){

    ...insert code here...

    }

    Justin
     
  11. JustinW

    Associate

    Joined: 27 Dec 2005

    Posts: 97

    Sorry, your JavaScript needs to be cleaned up a bit.

    if (radio_button.radio_young.checked and radio_button.radio_dry.checked)
    {
    function forward(){
    location.href="YOUR OLD / GREASY LINK HERE"
    }

    What you have done here is say IF the radio button is checked then define afunction called forward which will send you to this link.

    The function forward never actually gets called. What you need to do is define your function 'forward()' like so:

    function forward(url){
    location.href=url;
    }

    Do this once only!

    Then your if statements need to look like this:

    if (radio_button.radio_young.checked and radio_button.radio_dry.checked)
    {
    forward("url here"){
    }

    You will need to define the function forward before it is called'.

    Justin