-2

I have a project to do and it is pixel art maker from udacity.

The problem is when I press on submit, it refreshes the whole page, but I want it to stop refreshing and do his job.

What should i do?

This is my JavaScript code (Note: I haven't finished yet):

document.getElementById("sizePicker").onsubmit=function(e){
  sizePicker.addEventListener("submit",function(e){
    var rows=document.getElementById("inputHeight").value;
    var cols=document.getElementById("inputWidth").value;
    makeGrid(rows,cols);
  });
}
function makeGrid(e){
  let table=document.getElementById("pixelCanvas");
  for (let k=0; k<=rows; k++){
    grid+="<tr>";
    for (let u=0; u<=cols; u++){
      grid+="<td></td>";
    }
    grid+="</tr>";
  }
}
FZs
  • 16,581
  • 13
  • 41
  • 50

1 Answers1

-1

You just need to add e.preventDefault().

sizePicker.addEventListener("submit",function(e){
  e.preventDefault();

add below submit listener;

William Gunawan
  • 748
  • 3
  • 8
  • i didn't understand what you want me to do but i have e.preventDefault – EGY D.F Gamer Aug 03 '19 at 20:02
  • then you submit listener not work. maybe cause by this. `document.getElementById("sizePicker").onsubmit=function(e){` add console log see it trigger or not. from my point of view, you don't need this part just put the eventListener without wrap by this code. – William Gunawan Aug 03 '19 at 20:06