scferg Posted February 9, 2008 Share Posted February 9, 2008 I was wondering, if it was possible to have predefined html form values. So, the form would only submit if the correct value was entered. Like, you need to enter "14" but you entered "13" ... the form would not submit. I just thought this would be a simple thing to do with javascript. Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/ Share on other sites More sharing options...
The Little Guy Posted February 9, 2008 Share Posted February 9, 2008 Something like this: function submitForm(){ var val = document.getElementById('myField').value; if(val == 14){ document.myForm.submit(); }else{ alert('Invalid Input'); } } HTML: <form name="myForm" action="page.php"> <input id="myField" name="fieldName" /> <input type="button value="Submit" onclick="submitForm();"> </form> Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462314 Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Awesome! Thanks! Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462315 Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Is there someway that if the code isn't correct, it will display a message like "Code invalid, please retype the code again" ? Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462394 Share on other sites More sharing options...
phpQuestioner Posted February 9, 2008 Share Posted February 9, 2008 Yes, look in the "Else" part of the condition; of the script, that The Little Guy provided you. Where it has this: alert('Invalid Input'); Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462445 Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Ok, thanks! Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462467 Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Hmmmm... it seems to submit the form anyway. Try it at http://sims2news.com/?page=contact and try entering something other than the image shows. It still submits the form :-\ Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462703 Share on other sites More sharing options...
The Little Guy Posted February 9, 2008 Share Posted February 9, 2008 that is because you have the type as a type="submit" change it to: type="button" Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462849 Share on other sites More sharing options...
scferg Posted February 9, 2008 Author Share Posted February 9, 2008 Great! It works Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-462902 Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 Ok, I was using that as a type of CAPTCHA thing. I just needed something simple, but it was dumb of me to do it this way -- the bots have already gotten passed it. I've search all over the internet for a *real* CAPTCHA system, but all of them seem confusing. Like, some require databases and such. Do any of you know of a good CAPTCHA script, or know how to make one? I really appreciate it Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465315 Share on other sites More sharing options...
The Little Guy Posted February 12, 2008 Share Posted February 12, 2008 Good: http://phpsnips.com/snippet.php?id=6 Or Better: http://phpsnips.com/snippet.php?id=43 Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465350 Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 I tried the Advanced CAPTCHA script, but the image.php script seems messed up. Go to http://sims2news.com/image.php to see it. I don't know how to fix it... Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465372 Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 Nevermind...I just had to download the Disney.ttf font. But, now, I can't seem to get a valid code. http://sims2news.com/form.php Everything I've tried always returns with "The number you entered doesn't match the image." Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465376 Share on other sites More sharing options...
scferg Posted February 12, 2008 Author Share Posted February 12, 2008 Ok...nevermind again The Disney font was too hard to understand, and half the time the characters were cut off. I just changed it to a different font. Thanks the help ! Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465382 Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 Hmmm....how would I implement this with my current forms if they already have an action? All of my forum have a action of http://mysite.com/v-cgi/forms.cgi Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465422 Share on other sites More sharing options...
phpQuestioner Posted February 13, 2008 Share Posted February 13, 2008 You know this is the JavaScript forum; right? ??? You need to post server side scripting questions in the appropriate forums on this website. Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465431 Share on other sites More sharing options...
scferg Posted February 13, 2008 Author Share Posted February 13, 2008 Then you can move it there. This kind of branched of my original Javascript thread. Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465432 Share on other sites More sharing options...
phpQuestioner Posted February 13, 2008 Share Posted February 13, 2008 Sorry, I cannot move this thread; I am not a moderator. You can post a question, similar to this one, in the server side scripting forums; which can be found here: http://www.phpfreaks.com/forums/index.php?action=collapse;c=25;sa=expand#25 http://www.phpfreaks.com/forums/index.php?action=collapse;c=27;sa=expand#27 Link to comment https://forums.phpfreaks.com/topic/90155-predefined-input-value/#findComment-465434 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.