How can I get input value to work in Javascript -
i learning javascript , trying create today. have text box, submit button , hidden p tag called "demo". want user enter either number or text. if user enter number 1 thing , if user text thing. please see code (any input help...):
<%@ page language="c#" autoeventwireup="true" codebehind="practice.aspx.cs" inherits="javascript.javascript.practice" %> <!doctype html> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server"> <title></title> <script> function takeaction(){ var x = document.getelementbyid("textid").value; // var y = document.getelementbyid("demo").innerhtml=("you entered "+x + "."); if (x == number) { function numberfunction() { switch (x) { case 1: document.getelementbyid("demo").innerhtml = ("you entered " + x + " , number 1."); break; case 2: document.getelementbyid("demo").innerhtml = ("you entered " + x + " , number 2."); break; default: document.getelementbyid("demo").innerhtml = ("you entered " + x + " , number not between 1 & 2."); break; } } if (x == text) { function textfunction() { switch (x) { case "john": document.getelementbyid("demo").innerhtml = ("you " + x + " , number 1 position."); break; case "chris": document.getelementbyid("demo").innerhtml = ("you " + x + " , number 2 position."); break; default: document.getelementbyid("demo").innerhtml = ("you " + x + " , number not member."); break; } } } } } </script> </head> <body> <form id="form1" runat="server"> <div> <label>please enter something: </label> <input type="text" id="textid" /> <button id="btn" onclick="takeaction()">submit</button><b /> <p id="demo"></p> </div> </form> </body> </html>
i guess can use this
html:
<form id="form1" > <div> <label>please enter something: </label> <input type="text" id="textid" /> <button id="btn" onclick="takeaction()">submit</button><b /> <p id="demo"></p> </div> </form>
js:
function takeaction() { var x = document.getelementbyid('textid').value; function numberfunction(number) { var y = number; switch (parseint(y)) { case 1: document.getelementbyid('demo').innerhtml = ("you entered " + y + " , number 1."); break; case 2: document.getelementbyid('demo').innerhtml = ("you entered " + y + " , number 2."); break; default: document.getelementbyid('demo').innerhtml = ("you entered " + y + " , number not between 1 & 2."); break; } } function textfunction(text) { var y = text; switch (y) { case "john": document.getelementbyid('demo').innerhtml = ("you " + y + " , number 1 position."); break; case "chris": document.getelementbyid('demo').innerhtml = ("you " + y + " , number 2 position."); break; default: document.getelementbyid('demo').innerhtml = ("you " + y + " , number not member."); break; } } if (isnan(x)) { textfunction(x); } else { numberfunction(x); } }
Comments
Post a Comment