Help please, I want to have a form with two fields one is height one is width the results to execute a java script in an i frame on same page as form. The coding i want to use for example in an if then statement is : If height = 720 and width = 500 then (statement goes here) Once code is set up i want to be able to add further statements for example : if height = 720 and width = 500 then (statement 1 goes here) if height = 720 and width = 600 then (statement 2 goes here) if height = 720 and width = 700 then (statement 3 goes here) i can keep adding different statements all run from the height and width in the form input fields Any help would be appreciated in setting up this page including all coding. Thank You
Just write the code you're initially using, then edit it to add the rest as it comes up. If you mean that you need the format, try if((height == 720) && (width == 520)) { // do whatever here } elseif((height == 720) && (width == 600)) { //do it here } elseif(...) { //whatever } etc., etc.
Is 720 the only height? If so, I'd write it like: function do-width-stuff() { fm = document.querySelector("#fmData"); sWidth = fm.sWidth.value; sHeight = fm.sHeight.value; if(sHeight == "720") { switch(sWidth) { case "500": alert("type code for 500"); break; case "600": alert("type code for 600"); break; case "700": alert("type code for 700"); break; default: alert("Uh oh, now what?"); break; } } } Code (markup):
Same here -- don't waste time running the same condition more than once. NOT that doing anything based on pixel width has much business being done from JavaScript -- very curious about the usage scenario.