Javascript select() value

I am sure this is super easy, but for some reason I just can't figure this one out. I need to create a form on the page with the following fields and rules. If the user submits a form but the rules are broken for any field, the behavior listed must be done to advise the user. I am not allowed to use jQuery. Field01 & Field02 is one box. Field03 & Field04 is one box. * Field01: "Username" - Rule01: Cannot be empty, Behavior01: Put focus on it using focus(). * Field02: "Username" - Rule02: Cannot be empty, Behavior02: Alert the user that "username is required". * Field03: "Birthyear" - Rule03: Must be numeric, Behavior03: Select the value using select(). * Field04: "Birthyear" - Rule04: Must be between 1900 - 2012, Behaviour04: Turn the Birthyear text box background color to yellow. This is what I have so far... Struggling with the Field03 & Field04. Does anyone know how to approach this? HTML:
Username:
Birth Year:

JS in Separate file: document.getElementById("username").focus(); // focus on text box function validateForm(){ var x=document.forms["myForm"]["username"].value; if (x==""){ alert("Username Required!"); // focus on text box document.getElementById("username").focus(); return false; // validation failed }else{ return true; // validation success } }
Take a look at this answer and fiddle for a general outline of how to setup the validation process (sans jQuery).

以上就是Javascript select() value的详细内容,更多请关注web前端其它相关文章!

赞(0) 打赏
未经允许不得转载:web前端首页 » JavaScript 答疑

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址

前端开发相关广告投放 更专业 更精准

联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏