chiprivers Posted August 17, 2010 Share Posted August 17, 2010 Could somebody please check my syntax in the below javascript function? I am not overly experienced with complex javascript so I have thrown this together based mainly on my knowledge of php. I am pretty sure the logic behind my function is right but I am unsure of the syntax. It is throwing up an error whenever I call this function. function selecter(click_ff,click_start,click_end,res) { //if (document.getElementById(su_ff).value == null) { // set form field values document.getElementById(su_ff).value = click_ff; document.getElementById(su_start).value = click_start; document.getElementById(su_end).value = click_end; } else if (document.getElementById(su_end).value - document.getElementById(su_start).value == res + 1) { // unshade previously selected cells // set form field values document.getElementById(su_ff).value = click_ff; document.getElementById(su_start).value = click_start; document.getElementById(su_end).value = click_end; } else if (click_ff != document.getElementById(su_ff).value) { // unshade the previously selected cell/s // set form field values document.getElementById(su_ff).value = click_ff; document.getElementById(su_start).value = click_start; document.getElementById(su_end).value = click_end; } else { if (click_start < document.getElementById(su_start).value) { // set form field values document.getElementById(su_start).value = click_start; } if (click_end > document.getElementById(su_end).value) { // ser form field values document.getElementById(su_end).value = click_end; } } // shade selected cells document.getElementById('_'+click_ff+'_'+click_start+'_'+click_end).style.backgroundColor = '#333333'; } Quote Link to comment https://forums.phpfreaks.com/topic/210988-syntax-check-please/ Share on other sites More sharing options...
Psycho Posted August 17, 2010 Share Posted August 17, 2010 The only errors I see have nothing to do with JS specifically: 1. You commented out the first IF condition so the closing } before the first ELSE IF is out of context and plus you can't have ELSE IF statements without an IF statement. 2. The function is full of variables that are not defined - unless you defined them as gloabl variables somewhere else. The parameters in the function definition are named "click_???" but in the code it is "su_???" Quote Link to comment https://forums.phpfreaks.com/topic/210988-syntax-check-please/#findComment-1100502 Share on other sites More sharing options...
chiprivers Posted August 19, 2010 Author Share Posted August 19, 2010 Many thanks mjdamato. The commented out first line was an error! I was commenting out various bits for testing to try and find the problem and obviously left the comments there when I copied it over to the thread. The variables used are all valid in the context of where the function is being used. However, I have found the problem to have been where I using the getElementById() I needed to put the ids in ' ', ie getElementById('su_ff). That part of it is working fine now Quote Link to comment https://forums.phpfreaks.com/topic/210988-syntax-check-please/#findComment-1101168 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.