?
Solved

Day of the week

Posted on 2014-01-10
10
Medium Priority
?
252 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
  • 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
The viewer will learn how to count occurrences of each item in an array.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

840 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