Click here to Skip to main content
15,892,537 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How do I get this script to generate the links inside of the code depending on what pictures are selected? http://jsfiddle.net/P74tn/1/

<!DOCTYPE html>
<html>
  
  <style>
    .radio div{
    background: url($image) no-repeat #EEE;
    height:50px;
    width: 50px;
    border: 2px solid #DDD;
    padding: 5px;
    float: left;
    margin-right: 10px;
    cursor: pointer;
    &.active{
        box-shadow: 0px 0px 2px 1px blue inset;
    }
}
  </style>

<body>

<script>
$('.radio div').on('click', function() {
    var $this   = $(this),
        $parent = $this.parent(),
        value   = $this.attr('value');

    $parent.children().removeClass('active');
    $this.addClass('active');
    $parent.attr('value', value);
}); 
function tryToMakeLink()
    {
        //get all selected radios
        var q1=document.querySelector('input[name="q1"]:checked');
        var q2=document.querySelector('input[name="q2"]:checked');
        var q3=document.querySelector('input[name="q3"]:checked');
        //make sure the user has selected all 3
        if (q1==null || q2==null ||q3==null)
        {
            document.getElementById("linkDiv").innerHTML="<input type=button disabled=disabled value=Next>";
        }
        else
        {
            //now we know we have 3 radios, so get their values
            q1=q1.value;
            q2=q2.value;
            q3=q3.value;
            //now check the values to display a different link for the desired configuration
            if (q1=="AT&T" && q2=="8GB" && q3=="Black")
            {
              document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://google.com/';\">att 8gb black</input>";
            }
            else if (q1=="Other" && q2=="8GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://yahoo.com/';\">other 8b white</input>";
            }
            else if (q1=="AT&T" && q2=="16GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://bing.com/';\">another option</input>";
            }
            else if (q1=="AT&T" && q2=="16GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://gmail.com/';\">oops</input>";
            }
            else if (q1=="AT&T" && q2=="8GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://hotmail.com/';\">can't</input>";
            }
            else if (q1=="Other" && q2=="8GB" && q3=="Black")
            {
              document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://images.google.com/';\">yours</input>";
            }
            else if (q1=="Other" && q2=="16GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://youtube.com/';\">mines</input>";
            }
            else if (q1=="Other" && q2=="16GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://docs.google.com/';\">what</input>";
            }
            else if (q1=="Unlocked" && q2=="8GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://wepriceit.webs.com/';\">red</input>";
            }
            else if (q1=="Unlocked" && q2=="8GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://webs.com/';\">orange</input>";
            }
            else if (q1=="Unlocked" && q2=="16GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://gazelle.com/';\">green</input>";
            }
            else if (q1=="Unlocked" && q2=="16GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://glyde.com/';\">blue</input>";
            }
        }
    }function tryToMakeLink()
    {
        //get all selected radios
        var q1=document.querySelector('input[name="q1"]:checked');
        var q2=document.querySelector('input[name="q2"]:checked');
        var q3=document.querySelector('input[name="q3"]:checked');
        //make sure the user has selected all 3
        if (q1==null || q2==null ||q3==null)
        {
            document.getElementById("linkDiv").innerHTML="<input type=button disabled=disabled value=Next>";
        }
        else
        {
            //now we know we have 3 radios, so get their values
            q1=q1.value;
            q2=q2.value;
            q3=q3.value;
            //now check the values to display a different link for the desired configuration
            if (q1=="AT&T" && q2=="8GB" && q3=="Black")
            {
              document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://google.com/';\">att 8gb black</input>";
            }
            else if (q1=="Other" && q2=="8GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://yahoo.com/';\">other 8b white</input>";
            }
            else if (q1=="AT&T" && q2=="16GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://bing.com/';\">another option</input>";
            }
            else if (q1=="AT&T" && q2=="16GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://gmail.com/';\">oops</input>";
            }
            else if (q1=="AT&T" && q2=="8GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://hotmail.com/';\">can't</input>";
            }
            else if (q1=="Other" && q2=="8GB" && q3=="Black")
            {
              document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://images.google.com/';\">yours</input>";
            }
            else if (q1=="Other" && q2=="16GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://youtube.com/';\">mines</input>";
            }
            else if (q1=="Other" && q2=="16GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://docs.google.com/';\">what</input>";
            }
            else if (q1=="Unlocked" && q2=="8GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://wepriceit.webs.com/';\">red</input>";
            }
            else if (q1=="Unlocked" && q2=="8GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://webs.com/';\">orange</input>";
            }
            else if (q1=="Unlocked" && q2=="16GB" && q3=="White")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://gazelle.com/';\">green</input>";
            }
            else if (q1=="Unlocked" && q2=="16GB" && q3=="Black")
            {
                document.getElementById("linkDiv").innerHTML="<input type=button value=Next onclick=\"window.location.href='http://glyde.com/';\">blue</input>";
            }
        }
    }
</script>

<form name="quiz" id='quiz'>
  
  
  <h4>What carrier do you have?</h4>
    <div class="radio" id="form">
      <div style="list-style: none;"  önclick=tryToMakeLink(); name="q1" value="AT&T"><img width="50px" height="50px" src="http://wepriceit.webs.com/ipad-5-image.jpg" /></div>
        <div style="list-style: none;"  önclick=tryToMakeLink(); name="q1" value="Other"><img width="50px" height="50px" src="http://wepriceit.webs.com/ipad-5-image.jpg" /></div>
        <div style="list-style: none;"  önclick=tryToMakeLink(); name="q1" value="Unlocked"><img width="50px" height="50px" src="http://wepriceit.webs.com/ipad-5-image.jpg" /></div>
    </div>
      
  <br /><br /><br />
      
  <h4>What is your phones capicity?</h4>
    <div class="radio" id="form">
        <div style="list-style: none;" type="radio"  önclick=tryToMakeLink(); name="q2" value="8GB"><img width="50px" height="50px" src="http://wepriceit.webs.com/ipad-5-image.jpg" /></div>
        <div style="list-style: none;" type="radio"  önclick=tryToMakeLink(); name="q2" value="16GB"><img width="50px" height="50px" src="http://wepriceit.webs.com/ipad-5-image.jpg" /></div>
    </div>

  <br /><br /><br />
      
  <h4>What color is your phone?</h4>
    <div class="radio" id="form">
        <div style="list-style: none;" type="radio"  önclick=tryToMakeLink(); name="q3" value="Black"><img width="50px" height="50px" src="http://wepriceit.webs.com/ipad-5-image.jpg" /></div>
        <div style="list-style: none;" type="radio"  önclick=tryToMakeLink(); name="q3" value="White"><img width="50px" height="50px" src="http://wepriceit.webs.com/ipad-5-image.jpg" /></div>
    </div>
      
    

    <br>
    <div id=linkDiv>
     <input type=button disabled=disabled value=Next>
    </div>
</form>
</body>
</html>
Posted
Comments
Sergey Alexandrovich Kryukov 25-Aug-13 16:38pm    
Not clear. Who told you to use this script? What should it do, exactly?
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900