alalsebatoria
New Member
I'm trying to write a function to rotate through different images but I have a feeling the syntax in my conditions is incorrect. Any thought?Here is part of my javascript code: \[code\] // FUNCTION Check Captcha function checkCaptcha() { var captchaText = document.getElementById("captchaInput").value; var captchaIMG = document.getElementById("captcha").src; // If statement for captcha checks if (captchaIMG == "captcha01.gif") { if (captchaText == "4D7YS") { calculateCostsFunctionFORM2(); } else { alert("Captcha does not match! Try again."); captchaIMG = "captcha02.gif"; } } else if (captchaIMG == "captcha02.gif") { if (captchaText == "28ivw") { calculateCostsFunctionFORM2(); } else { alert("Captcha does not match! Try again."); captchaIMG = "captcha01.gif"; } } }\[/code\]I call the function with the first button below. Here is my HTML code:\[code\]<table border="1"> <tr> <td>Calculate Costs of Fuel/Hour</td> <tr> <td>Departure Port</td> <td> <select id="departureFORM2"> <option value="http://stackoverflow.com/questions/15457123/falmouth">Falmouth</option> </select> </td> </tr> <tr> <td>Destination</td> <td> <select id="destinationFORM2"> <option value="http://stackoverflow.com/questions/15457123/nantucket">Nantucket</option> <option value="http://stackoverflow.com/questions/15457123/edgartown">Edgartown</option> <option value="http://stackoverflow.com/questions/15457123/oakBluffs">Oak Bluffs</option> <option value="http://stackoverflow.com/questions/15457123/newport">Newport</option> </select> </td> </tr> <tr> <td>Speed</td> <td> <select id="speed"> <option value="http://stackoverflow.com/questions/15457123/14kt">14kt</option> <option value="http://stackoverflow.com/questions/15457123/18kt">18kt</option> <option value="http://stackoverflow.com/questions/15457123/20kt">20kt</option> <option value="http://stackoverflow.com/questions/15457123/22kt">22kt</option> </select> </td> </tr> <tr> <td> <img id="captcha" src="http://stackoverflow.com/questions/15457123/captcha01.gif" height="44" width="146" /> </td> <td> <input type="text" id="captchaInput" style="text-align:right;"> </td> </tr> <tr> <td> <button onclick="checkCaptcha()">Calculate</button> </td> <td> <input type="text" id="outputDisplayFORM2" style="text-align:right;" readonly> </td> </tr> <tr> <td> <input type="text" id="test" readonly /> </td> <td> <button onclick="testOutput()">Test</button> </td> </tr></table>\[/code\]Essentially, the logic for the if statement should be this:check if input matches captcha of img1: if yes = run function if no = change to im2check if input matches captcha of img2: if yes = run function if no = change to img1Let me know if there's anything else you may need that I'm missing. Thanks for your time.