1

So, now I just type in this. Initially, I was going for the iframe target but I had the target on the picture already. What I wanna do is when I click on the image, the description will come out on the second td iframe. How do I link the function to the iframe( the 1st 1)

<script>
function myFunction(){
   var resultBox = document.getElementById("scarf1");
   if(resultBox == "scarf1.jpg"){  // <= you can put your condition here
       resultBox.innerHTML="A soft brushed cashmere scarf featuring the iconic check. The scarf is made in Scotland at a mill with a long heritage in producing cashmere.To create a subtle lustre and soft texture, the cashmere is washed in spring water, then woven on traditional looms and brushed with natural teasels.Measuring 168 x 30cm/66.1 x 11.8in, the design is hand-finished with fringing.";
   }</script>
    <table>
<tr>

    <td width="190px" height="190px">
    <a href="scarf1.jpg" target="frame"><img alt="HERITAGE CHECK CASHMERE SCARF" onclick="myFunction()" id="scarf1"height="100" src="scarf1.jpg" width="100"   onmouseover="bigImg(this)" onmouseout="normalImg(this)"/></a>
    </td>
    <td>
    <iframe src="Burberry_product_women_accessories_frame2.html" target="frame1" name="frame1" scrolling="no">
    </iframe></td>
    <td rowspan="4">

    <iframe height="750" width="480" target="frame" name="frame" scrolling="no" float="right" src="Burberry_product_women_accessories_frame.html">
    </iframe>
    </td>
    </tr>
    <tr>
    <td width="190px" height="190px">
    <a href="scarf2.jpg" target="frame"><img alt="HERITAGE CASHMERE SCARF" height="100" src="scarf2.jpg" width="100"  onmouseover="bigImg2(this)" onmouseout="normalImg2(this)" /></a>
    </td>
    <td>HERITAGE CASHMERE SCARF</td>
    </tr>
    <tr>
    <td width="190px" height="190px">
    <a href="wwallet.jpg" target="frame"><img alt="HAYMARKET CHECK CONTINENTAL WALLET" height="100" src="wwallet.jpg" width="100"   onmouseover="bigImg3(this)" onmouseout="normalImg3(this)"/></a>
    </td>
    <td>HAYMARKET CHECK CONTINENTAL WALLET</td>
    </tr>
    <tr>
    <td width="190px" height="190px">
    <a href="wumbrella.jpg" target="frame"><img alt="CHECK FOLDING UMBRELLA" height="100" src="wumbrella.jpg" width="100"   onmouseover="bigImg4(this)" onmouseout="normalImg4(this)"/></a>
    </td>
    <td>CHECK FOLDING UMBRELLA</td>
    </tr>

    </table>
3
  • what you need to check with if/else? Commented Mar 22, 2014 at 7:18
  • I mean this is just a sample code. How would i enter the if else statement ? where should it be ? Commented Mar 22, 2014 at 7:20
  • You has more than one solution... See my answer Commented Mar 22, 2014 at 7:21

4 Answers 4

1
function myFunction(){
   var resultBox = document.getElementById("demo");
   if(textA){  // <= you can put your condition here
       resultBox.innerHTML=textA;
   }else{
       resultBox.innerHTML=textB; 
   }
  // OR you can use ternary operator
  // resultBox.innerHTML =  (textA) ? textA : textB;
}

Updated

It's hard to know what are you trying to do, however it seems your want put html when particular image is found.. HTML

<img alt="HERITAGE CHECK CASHMERE SCARF" onclick="myFunction('scarf1.jpg')"

JS

 function myFunction(imgVal){
   var resultBox = document.getElementById("resultBox"); 
   // here is the id of result element instead ---^--- of resultBox
   if(imgVal == "scarf1.jpg"){  // <= you can put your condition here
       resultBox.innerHTML="A soft brushed cashmere....... ";
    }
} 
Sign up to request clarification or add additional context in comments.

5 Comments

Help me with my new question. Thanks ><
the resultBox is image tag and you can't put the text into it as innerHTML, What exactly want you.
Please update your question, and avoid the completely change it.
I wanted to link the text in the innerHTML to the iframe. So when I click the image, I got one iframe with the description while the other (which I've already done) have image.
then you should get iframe by var resultBox = document.getElementById('myIframe').contentWindow; and put the result inside this
0
<!DOCTYPE html>
<html>
    <head>
        <script>
            function myFunction(text) {
                document.getElementById("demo").innerHTML = text;
            }
        </script>
    </head>
    <body>
        <p>Click the button to trigger a function.</p>
        <button onclick="myFunction(/* What you need to check */ ? 'Text 1' : 'Text 2')">Click me</button>
        <p id="demo"></p>
    </body>
</html>

Comments

0

Here you go: JS:

function myFunction()
{
i=true; // i is true
if (i) // Check if i is true.
{
document.getElementById("demo").innerHTML="i is true"; // Event to do if i is true
}
else // else if i is not the condition above (true)
{
document.getElementById("demo").innerHTML="i is false"; 
/* 
*Event to do if i is not the condition above
*/
}
}

Comments

0

here is something that you can test: Not the best code, but you can copy paste this into the w3schools editor and you should be able to see it in action.

<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
if(document.getElementById("demo").innerHTML == "Hello World") {
document.getElementById("demo").innerHTML="Click Me";
} else {
document.getElementById("demo").innerHTML="Hello World";
}
}
</script>
</head>
<body>

<p>Click the button to trigger a function.</p>

<button onclick="myFunction()">Click me</button>

<p id="demo"></p>

</body>
</html>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.