JavascriptJQuery GetDay() - Stack Overflow

I have the following code:I'm pletely new to javascript, this is my first time using it. The valu

I have the following code:

/

I'm pletely new to javascript, this is my first time using it. The values of the HTML selects MUST be 01,02 etc, that's why I had to use a big long if else statement. The values have to be submitted to an application on a server, which is extremely fussy about what way it takes in values.

Why won't it set the day as 15 (today) in the select box?

I have the following code:

http://jsfiddle/SPWWx/

I'm pletely new to javascript, this is my first time using it. The values of the HTML selects MUST be 01,02 etc, that's why I had to use a big long if else statement. The values have to be submitted to an application on a server, which is extremely fussy about what way it takes in values.

Why won't it set the day as 15 (today) in the select box?

Share Improve this question edited Jul 15, 2010 at 11:10 Marcus asked Jul 15, 2010 at 11:04 MarcusMarcus 31 silver badge3 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 7

You have a few issues, you're not including jQuery on the left, the element has a name not an ID or CID, so it needs to be id="CID" or your selector needs to be select[name='CID']. Last, you need to pass a string to .val() to get the result you want, otherwise it's trying to set it to "4", which doesn't equal "04".

You can shorten all your code down to this though:

var day = new Date().getDate().toString();
$("#CID").val(day.length == 1 ? "0" + day : day);​

You can test it here, also as Jamiec points out, you want .getDate() to get the date of the month as opposed to .getDay() which is of the week.

because the element's name is CID, not it's id! $('#CID') selects the element with the id CID.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745353622a4623988.html

相关推荐

  • JavascriptJQuery GetDay() - Stack Overflow

    I have the following code:I'm pletely new to javascript, this is my first time using it. The valu

    2小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信