/    Sign up×
Community /Pin to ProfileBookmark

Please can someone help with some code?
The attached code is something I’m working on for a course I’m doing.
I’m try to capture the data from the selected priority and add that number to the current date and display it as a future date.
i.e.
Today’s date is 15th Feb
priority 2 is selected (add 2 days)
future calculated date will be:
17th Feb

I’m able to do it by entering the number of days manually and clicking the ‘calculate fix date’ button, but I want it to be done automatically.

Any help would be much appreciated.

[upl-file uuid=8cd4f81e-6a04-4c90-b755-dbee16f7b757 size=2kB]personaldetailstest.txt[/upl-file]

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisFeb 15.2004 — Give the radio button an onclick function that adds some value the same way you use the text box.

Actually, it is simpler to do it with the radio button than the text box.
<i>
</i>function add(num) {
var newdate = new Date();
var newtimems = newdate.getTime() + (num * 24 * 60 * 60 * 1000);
// newdate.setTime(newtimems); you really want to do this?
document.form.display.value = newdate.toLocaleString();
}
...
&lt;br&gt;&lt;INPUT TYPE="radio" NAME="priority" onclick="if(this.checked){add(1)}"&gt; priority 1
&lt;br&gt;&lt;INPUT TYPE="radio" NAME="priority" onclick="if(this.checked){add(2)}"&gt; priority 2
&lt;br&gt;&lt;INPUT TYPE="radio" NAME="priority" onclick="if(this.checked){add(3)}"&gt; priority 3
Copy linkTweet thisAlerts:
@stan711authorFeb 15.2004 — gil,

thanks for your help, but, I can't seem to get it to work.

Do I just need to copy the code you posted into what I already have?

If so, where abouts should I put it?

Sorry if I'm asking stupid questions but Javascript is all a bit new to me....

Thanks again.
Copy linkTweet thisAlerts:
@gil_davisFeb 15.2004 — You are also apparently new to HTML. You don't put <h3> tags in the <head> section.

You put the function between the <script> tags in the <head> section. You change your RADIO buttons to look like the three that I posted.
Copy linkTweet thisAlerts:
@stan711authorFeb 15.2004 — gil,

Thanks again or your reply.

I managed to figure it out and have got it working perfectly.

Thanks again for your help and patience.
×

Success!

Help @stan711 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...