display image on another window when click select button using Javascript

SoloKifle

Hello there I'm new to the world of Javascript, and I really really need help for school project. What I want to do, is to display on another windows not only the text with the price, but also the image itself. I tried to add the id on the image and added it to function. Anybody please? I have this code here in the body element along with other images:


Nike 1 price:$110.99
Size: 9   10   11

       <input type= submit value=submit onclick="a()">

This is my script function:

       <script>
       function a(){
       var size ="";
       var price = 0;
       if(document.getElementById('nike1').checked)
       {
       price=document.getElementById("nike1").value;
       var x =document.getElementById("myimg").src;
       }

       else if(document.getElementById('nike2').checked)
       {
       price=document.getElementById('nike2').value;
       }

       var inputs = document.getElementsByName('r1');
       for(var i =0; i<inputs.lenght; i++){
       if(inputs[i].checked){
       size = inputs[i].value;
       }
       }


       var inputs1 = document.getElementsByName('r2');
       for(var i =0; i <inputs1.lenghts;i++){
       if(inputs1[i].checked){
       size=inputs1[i].value;
       }
       }

       var myWindow = window.open("","MsgWindow","width=200,height=400");
       myWindow.document.write("<p><h1>Order Detail</h1> Your ordered Nike shoes<br/>                                                                                        Size:"+size + "<br/>Price:S"+ price + "</p>");

}

Yohaï-Eliel Berreby

Please indent you code for readability. Here it is, a little bit cleaned and with error fixes.

   function a() {
       var size, price;
       if (document.getElementById('nike1').checked) {
           price = document.getElementById("nike1").value;
           var x = document.getElementById("myimg").src;
       } else if (document.getElementById('nike2').checked) {
           price = document.getElementById('nike2').value;
       }

       var inputs = document.getElementsByName('r1');
       for (var i = 0; i < inputs.length; i++) {
           if (inputs[i].checked) {
               size = inputs[i].value;
           }
       }


       var inputs1 = document.getElementsByName('r2');
       for (var i = 0; i < inputs1.length; i++) {
           if (inputs1[i].checked) {
               size = inputs1[i].value;
           }
       }

       var myWindow = window.open("", "MsgWindow", "width=200,height=400");
       myWindow.document.write('<p><h1>Order Detail</h1> Your ordered Nike shoes<br/>'+
       '<img src="path/to/your/image.png" alt="Nike shoes"></img>'+
       '<p>Size: ' + size + '<br/>Price: ' + price + '</p>');
   }

To solve your problem, write an img element with a src attribute. Change "path/to/your/image.png" with the real path to the image you want to display.

There were also errors in your code. Your two for loops contained a wrong value: your wrote lenght in the first and lenghts in the second. I fixed it. I tested it and it works. This fiddle is fairly simple and incomplete but shows you the result.

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Display the file upload percentage in text box with progress bar on click browse button using jquery,javascript and html

분류에서Dev

Display Checkboxes on Click of a button

분류에서Dev

Display confirm dialog box on button click using rails 4?

분류에서Dev

Display javascript error when using gulp

분류에서Dev

How to click through array of objects and display data in div using javascript

분류에서Dev

How use Jquery Save Cookie inthe browser when click button window reload

분류에서Dev

Display Image From browse button

분류에서Dev

I want to play audio one after another when i click button in android

분류에서Dev

Swift: Change button image in table view on click

분류에서Dev

Click on iframe using javascript

분류에서Dev

javascript function not calling from code behind when i'm calling another function within same click event

분류에서Dev

Button Click Event from inside a modal not firing when using angular.js and ui.bootstrap

분류에서Dev

Qt Creator : Button Click Signal to make a window pop-up

분류에서Dev

How to trigger on click event to a button which is on a modal window

분류에서Dev

How do you open a new JPanel window on a click of a button?

분류에서Dev

Replace an Image when another Image is uploaded

분류에서Dev

Mail Compose not dismiss when click cancel button

분류에서Dev

when click on fb connect button nothing happens

분류에서Dev

Error when setting a click listener to a button

분류에서Dev

ng-click not working when button is pushed

분류에서Dev

How to select (this) image when clicked?

분류에서Dev

jquery to pure javascript ul li button click

분류에서Dev

Javascript code disappears after button click

분류에서Dev

Passing button id on click in javascript (meteorJs)

분류에서Dev

How to call javascript function after click of a button?

분류에서Dev

Show error after button click Javascript

분류에서Dev

Toggle menu only when it is open when we click anywhere on window

분류에서Dev

How to click iframe button on Python using Selenium?

분류에서Dev

Unable to click on a button using watir-webdriver

Related 관련 기사

  1. 1

    Display the file upload percentage in text box with progress bar on click browse button using jquery,javascript and html

  2. 2

    Display Checkboxes on Click of a button

  3. 3

    Display confirm dialog box on button click using rails 4?

  4. 4

    Display javascript error when using gulp

  5. 5

    How to click through array of objects and display data in div using javascript

  6. 6

    How use Jquery Save Cookie inthe browser when click button window reload

  7. 7

    Display Image From browse button

  8. 8

    I want to play audio one after another when i click button in android

  9. 9

    Swift: Change button image in table view on click

  10. 10

    Click on iframe using javascript

  11. 11

    javascript function not calling from code behind when i'm calling another function within same click event

  12. 12

    Button Click Event from inside a modal not firing when using angular.js and ui.bootstrap

  13. 13

    Qt Creator : Button Click Signal to make a window pop-up

  14. 14

    How to trigger on click event to a button which is on a modal window

  15. 15

    How do you open a new JPanel window on a click of a button?

  16. 16

    Replace an Image when another Image is uploaded

  17. 17

    Mail Compose not dismiss when click cancel button

  18. 18

    when click on fb connect button nothing happens

  19. 19

    Error when setting a click listener to a button

  20. 20

    ng-click not working when button is pushed

  21. 21

    How to select (this) image when clicked?

  22. 22

    jquery to pure javascript ul li button click

  23. 23

    Javascript code disappears after button click

  24. 24

    Passing button id on click in javascript (meteorJs)

  25. 25

    How to call javascript function after click of a button?

  26. 26

    Show error after button click Javascript

  27. 27

    Toggle menu only when it is open when we click anywhere on window

  28. 28

    How to click iframe button on Python using Selenium?

  29. 29

    Unable to click on a button using watir-webdriver

뜨겁다태그

보관