?
Solved

Day of the week

Posted on 2014-01-10
10
Medium Priority
?
249 Views
Last Modified: 2014-01-11
How to use a day of the week in a text box without using any script
<input type="text" name="DayOfTheWeek">

Thanks
0
Comment
Question by:mustish1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 58

Expert Comment

by:Gary
ID: 39772817
You can't, you need a server side language or javascript
0
 

Author Comment

by:mustish1
ID: 39772819
Can I write it down inside the tag without calling any function something like

<input type="text" name="DayOfTheWeek" value="javascript.dateDay()">

Thanks
0
 
LVL 58

Expert Comment

by:Gary
ID: 39772828
No it would have to be a separate function outside the input.
0
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 

Author Comment

by:mustish1
ID: 39772831
document.javascript.DayOfTheWeek

Something like that
0
 
LVL 58

Expert Comment

by:Gary
ID: 39772833
There is no such thing as the name of a day in javascript - you have to create it yourself
And you cannot have javascript in an input that will fire automatically

http://jsfiddle.net/TM5Gk/

<input type="text" name="DayOfTheWeek" id="dayofweek" value="">
<script>
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
now = new Date();
day = now.getDay();

document.getElementById("dayofweek").value=weekday[day];
</script>

Open in new window

0
 

Author Comment

by:mustish1
ID: 39772847
I dont know what i made mistake its not showing in it

<html>
<head>
<title>Test Day</title>
<script>
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
now = new Date();
day = now.getDay();
document.getElementById("dayofweek").value=weekday[day];
</script>
</head>
<p><h3>Week Day</h3> </p>
<form method = "Post" action = "">
<p><label>Week Day<input name = "mDayoftheweek" type ="text" id="dayofweek"></label></p>
<input type = "submit" value = "Submit">
<input type = "submit" value = "Clear">
</form>
</body>
</html>
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 39772856
The script needs to be after the input else you will have to wrap it in a function and then put an onload into your body tag. e.g.

<html>
<head>
<title>Test Day</title>
<script>
function setDay(){
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
now = new Date();
day = now.getDay();
document.getElementById("dayofweek").value=weekday[day];
}
</script>
</head>
<body onload="setDay()">
<p><h3>Week Day</h3> </p>
<form method = "Post" action = "">
<p><label>Week Day<input name = "mDayoftheweek" type ="text" id="dayofweek"></label></p>
<input type = "submit" value = "Submit">
<input type = "submit" value = "Clear">
</form>
</body>
</html> 

Open in new window

0
 
LVL 58

Expert Comment

by:Gary
ID: 39772857
But this is preferable
<html>
<head>
<title>Test Day</title>

</head>
<body>
<p><h3>Week Day</h3> </p>
<form method = "Post" action = "">
<p><label>Week Day<input name = "mDayoftheweek" type ="text" id="dayofweek"></label></p>
<input type = "submit" value = "Submit">
<input type = "submit" value = "Clear">
</form>
<script>
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";
now = new Date();
day = now.getDay();
document.getElementById("dayofweek").value=weekday[day];
</script>
</body>
</html> 

Open in new window

0
 

Author Comment

by:mustish1
ID: 39773803
Thanks Cathal
0
 
LVL 58

Expert Comment

by:Gary
ID: 39773810
np
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are two main kinds of selectors in CSS: One is base selector like h1, h2, body, table or any existing HTML tags.  For instance, the following rule sets all paragraphs (<p> elements) to red: (CODE) CSS also allows us to define our own custom …
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question