Solved

How do I make a click on an image link tick a checkbox on another html page?

Posted on 2008-10-08
3
370 Views
Last Modified: 2008-10-08
Hi there!

I have 6 different images representing various house sizes here:

http://www.oxlund.net/storage/beregn-dit-pladsbehov.html

And then I have 6 different checkboxes representing the same sizes here:

http://www.oxlund.net/storage/bestil-opbevaring.html

When the user hovers over the house sizes and finds the size that suits him the best, he clicks on the image and a link appears below the text sending him to the order page where the appropriate checkbox has been ticked.

I assume it's supposed to be done with javascript, and i've searched everywhere for the solution, but with no luck.. Hope you can help me!!

I've attached the code for the images and for the checkboxes..

Thanks so much!
The Images:
 

                <ul class="TabbedPanelsTabGroup">

                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img src="grafik/et-vaerelse.gif" /></li>

                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img src="grafik/to-vaerelser.gif" /></li>

                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img src="grafik/3_vaerelser.gif" /></li>

                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img src="grafik/fire_vaerelser.gif" /></li>

                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img src="grafik/fem-vaerelses.gif" /></li>

				  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img src="grafik/fem-vaerelses.gif" /></li>                

                </ul>
 
 

The Checkboxes:
 

             	<input class="check" name="" type="checkbox" value="" /><span class="check_value">3-5 m2</span> 

             	<input class="check" name="" type="checkbox" value="" /><span class="check_value">6-8 m2</span>  

				<input class="check" name="" type="checkbox" value="" /><span class="check_value">9-11 m2</span>  

				<input class="check" name="" type="checkbox" value="" /><span class="check_value">12-15 m2</span><br />  

				<input class="check" name="" type="checkbox" value="" /><span class="check_value">16-20 m2</span>

				<input class="check" name="" type="checkbox" value="" /><span class="check_value">over 21 m2</span>		

				<input class="check" name="" type="checkbox" value="" /><span class="check_value">Ønsker vejledning</span>

Open in new window

0
Comment
Question by:spl2381
  • 2
3 Comments
 
LVL 10

Accepted Solution

by:
eguilherme earned 125 total points
ID: 22669977
on the beregn-dit-pladsbehov.html change this:

so that when the user clicks the img it will redirect to the other page with a parameter to know which house he clicked


                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img onclick="window.location='bestil-opbevaring.html?h=1'" src="grafik/et-vaerelse.gif" /></li>
                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img onclick="window.location='bestil-opbevaring.html?h=2'" src="grafik/to-vaerelser.gif" /></li>
                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img onclick="window.location='bestil-opbevaring.html?h=3'" src="grafik/3_vaerelser.gif" /></li>
                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img onclick="window.location='bestil-opbevaring.html?h=4'" src="grafik/fire_vaerelser.gif" /></li>
                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img onclick="window.location='bestil-opbevaring.html?h=5'" src="grafik/fem-vaerelses.gif" /></li>
                                  <li class="TabbedPanelsTab" onmouseover="TabbedPanels1.showPanel(this);"><img onclick="window.location='bestil-opbevaring.html?h=6'" src="grafik/fem-vaerelses.gif" /></li>    

on the bestil-opbevaring.html add this at the <head> tag:

<script language="javascript">
function gup( name )
{
  name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
  var regexS = "[\\?&]"+name+"=([^&#]*)";
  var regex = new RegExp( regexS );
  var results = regex.exec( window.location.href );
  if( results == null )
    return "";
  else
    return results[1];
}
function selChk()
{
     var id = gup('h')
     document.getElementById("chk_house_" + id).checked = true;
}
</script>

and on the body tag:

<body onload="selChk()">

and to finish, add those id's element to the checkboxes:

<input class="check" name="" type="checkbox" value="" id="chk_house_1"/><span class="check_value">3-5 m2</span>
                <input class="check" name="" type="checkbox" value="" id="chk_house_2" /><span class="check_value">6-8 m2</span>  
                                <input class="check" name="" type="checkbox" value="" id="chk_house_3" /><span class="check_value">9-11 m2</span>  
                                <input class="check" name="" type="checkbox" value="" id="chk_house_4" /><span class="check_value">12-15 m2</span><br />  
                                <input class="check" name="" type="checkbox" value="" id="chk_house_5" /><span class="check_value">16-20 m2</span>
                                <input class="check" name="" type="checkbox" value="" id="chk_house_6" /><span class="check_value">over 21 m2</span>            
                                <input class="check" name="" type="checkbox" value="" id="chk_house_7" /><span class="check_value">Ønsker vejledning</span>


ps. didnt test anything but i suppose it could work like this
0
 

Author Comment

by:spl2381
ID: 22670818
Hi eguilherme,

Thanks so much for the answer.. Works perfectly, except the <body onload="selChk()"> function breaks this other javascript file i have attached below. It's being used for clearing the textfields on focus, but stops clearing when i use the  <body onload="selChk()">. Any idea shat could be wrong?

Thanks again!
window.onload = formDefaultValues;
 

function formDefaultValues() {

  var fields = getElementsByClassName(document, "input", "javascript");

  if (!fields) {

    return;

  }

  var default_values = new Array();

  for (var i = 0; i < fields.length; i++) {

    fields[i].style.color = inactive_color;

    if (!default_values[fields[i].id]) {

      default_values[fields[i].id] = fields[i].value;

    }

    fields[i].onfocus = function() { 

      if (this.value == default_values[this.id]) {

        this.value = '';

        this.style.color = active_color;

      }

      this.onblur = function() {

        if (this.value == '') {

          this.style.color = inactive_color;

          this.value = default_values[this.id];

        }

      }

    }

  }

}
 

function getElementsByClassName(oElm, strTagName, strClassName){

  var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);

  var arrReturnElements = new Array();

  strClassName = strClassName.replace(/\-/g, "\\-");

  var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");

  var oElement;

  for (var i = 0; i < arrElements.length; i++) {

    oElement = arrElements[i];

    if (oRegExp.test(oElement.className)) {

      arrReturnElements.push(oElement);

    }

  }

  return (arrReturnElements);

}

Open in new window

0
 
LVL 10

Assisted Solution

by:eguilherme
eguilherme earned 125 total points
ID: 22674458
change the

<body onload="selChk()">

to

<body onload="selChk(); formDefaultValues()">  so that it will execute both functions, and then you can remove this line:

window.onload = formDefaultValues;
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

758 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now