/    Sign up×
Community /Pin to ProfileBookmark

Please help a noob with Javascript

I want to pass information to a function based on the HTML input box that was clicked. Then I want to take that information and use it in a function to pass information back to the HTML input box that this came from. I am using a double click as the event. The doubleclick works in bringing the information to the function, but I don’t know how to get the function to place the info back into the input box. Here is the code:

<SCRIPT LANGUAGE=”JavaScript”>
<!– Start Hiding the Script
// JavaScript Function for inserting current date into Invoice Date
function NewBillDate(InputName) {

var date = new Date();
var d = date.getDate();
var day = (d < 10) ? ‘0’ + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? ‘0’ + m : m;
var yy = date.getYear();
var year = (yy < 100) ? yy + 1900 : yy; // Why (yy < 1000) ?? // I changed it to (yy < 100)

var finishedyear = (month + “/” + day + “/” + year);

// Bad Code is as follows

document.form1.InputName.value = finishedyear;

// End of Bad Code
}
–>
</SCRIPT>

<input type=”text” name=”BillDate” size=”10″ ID=”Text3″ onDblClick=”NewBillDate(‘BillDate’);”>

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@UltimaterMay 05.2005 — document.form1[InputName].value = finishedyear;
Copy linkTweet thisAlerts:
@CharlesMay 05.2005 — &lt;script type="text/javascript"&gt;
&lt;!--
Date.prototype.toDateString = function () {return [this.getMonth() &lt; 9 ? '0' + (this.getMonth() + 1) : this.getMonth(), this.getDate() &lt; 10 ? '0' + this.getDate() : this.getDate(), this.getFullYear()].join ('/')}

Date.prototype.getNewBillDate = function () {this.setMonth (this.getMonth() + 1); return this}
// --&gt;
&lt;/script&gt;

&lt;input type="text" onchange="this.value = new Date (this.value).getNewBillDate().toDateString()"&gt;
The method [font=monospace]Date.getYear()[/font] has been removed from JavaScript and it's support is spotty. Use instead [font=monospace]Date.getFullYear()[/font]
Copy linkTweet thisAlerts:
@EnjoyLifeauthorMay 05.2005 — Thank you Ultimater, that did the trick.

Charles, I got this function over a year ago. I've looked at your suggestion and have improved my code. Thanks.
Copy linkTweet thisAlerts:
@CharlesMay 05.2005 — [font=monospace]Date.getYear()[/font] was tossed out back in the last Century.
Copy linkTweet thisAlerts:
@EnjoyLifeauthorMay 05.2005 — I've changed it. My JavaScript book is from last Century as well. Maybe I need to update my book.
×

Success!

Help @EnjoyLife 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.18,
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,
)...