Forum Moderators: open

Message Too Old, No Replies

OnClick Javascript Forms

         

TheKiller

6:28 am on Sep 28, 2010 (gmt 0)

10+ Year Member



Hello Everyone

So i have a form With 6 Names/Values
And i would like a Button that once clicked it enters some values in them and as u click the Reset button it will reset the forms

i have come across this line of code:

<input type="button" onclick="javascript:THE_NAME.value='THE_VALUE';" value="ClickMe To Enter Value in form"/>

But it will only enter the THE_VALUE in the the THE_NAME for one form

I Need one button that will enter more values in different names

Here is my example code:

<input type="text" size="1" maxlength="2" name="Day" value="17">
<input type="text" size="1" maxlength="2" name="Mon" value="12">
<input type="text" size="1" maxlength="4" name="Year" value="2007">
<input type="text" size="1" maxlength="2" name="Hr" value="03">
<input type="text" size="1" maxlength="2" name="Min" value="14">
<input type="text" size="1" maxlength="2" name="Sec" value="00">


i want to remove all the Values from there and let them show there only if i click the button to enter them

Sorry if i havent mad myself understood right

my english was kinda bad while writing this xD

TheKiller

7:21 am on Sep 29, 2010 (gmt 0)

10+ Year Member



Anyone please ?

Heres a example on what the javascript should do..
but i want it to do all that functions on a single button

<input type="button" onclick="javascript:Day.value='15';" value="ClickMe To Enter Value in form"/>
<input type="button" onclick="javascript:Mon.value='02';" value="ClickMe To Enter Value in form"/>
<input type="button" onclick="javascript:Year.value='1992';" value="ClickMe To Enter Value in form"/>
<input type="button" onclick="javascript:Hr.value='13';" value="ClickMe To Enter Value in form"/>
<input type="button" onclick="javascript:Min.value='01';" value="ClickMe To Enter Value in form"/>
<input type="button" onclick="javascript:Sec.value='00';" value="ClickMe To Enter Value in form"/>


Can anyone please help?
i know nothing about javascript :|

Thanks

ProbablyMike

10:37 am on Sep 29, 2010 (gmt 0)

10+ Year Member



The code you have will not work, you'll just get JavaScript errors for each one saying it's not defined, eg "Day is not defined"

You want something like this to do it from one button:


<html>

<head>
<title></title>
<script type="text/javascript">
function FillForm() {
document.getElementById("day").value = "15";
document.getElementById("mon").value = "02";
document.getElementById("year").value = "1992";
document.getElementById("hr").value = "13";
document.getElementById("min").value = "01";
document.getElementById("sec").value = "00";
}
</script>
</head>

<body>
<form action="yourscript.asp" method="post">
<input type="text" size="1" maxlength="2" name="Day" id="day">
<input type="text" size="1" maxlength="2" name="Mon" id="mon">
<input type="text" size="1" maxlength="4" name="Year" id="year">
<input type="text" size="1" maxlength="2" name="Hr" id="hr">
<input type="text" size="1" maxlength="2" name="Min" id="min">
<input type="text" size="1" maxlength="2" name="Sec" id="sec">
<input type="button" onclick="javascript:FillForm();" value="ClickMe To Enter Value in form"/>
</form>
</body>

</html>

TheKiller

5:23 am on Sep 30, 2010 (gmt 0)

10+ Year Member



Thank You So much Mike !
That did the work :D

im making some Unix TimeStamp Converter for my own use and i wanted to enter the current day values into the form