Solved

Day of the week

Posted on 2014-01-10
10
235 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
 

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
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

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 500 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Article by: Matthew
I am a very big proponent of technology compliance standards and strive to meet such criteria in all of my work. That includes my site, which is 100% XHTML 1.0 compliant as determined by the World Wide Web Consortium. https://www.matthewstevenkel…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
The viewer will learn how to dynamically set the form action using jQuery.
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…

760 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now