Hi all. I have a problem with an onClick function working when I click a button. The infamous IE error reporting links it back to the button itself, but I don't think that's the case (Line 48, 49 - Object doesn't support this property or method). The code itself isn't complete since I just started and can finish the rest later. Anyways, here's what I have so far... -
<html>
-
<script type="text/javascript">
-
// if zulu - > time is checked
-
var hour1 = document.time.getElementByName("hour").value;
-
var minute1 = document.time.getElementByName("minute").value;
-
parseInt(hour1);
-
parseInt(minute1);
-
-
function local()
-
{
-
-
if (hour1 > 05 & < 23)
-
{
-
hour1 = hour1 - 5;
-
}
-
else if (hour1 = 00)
-
{
-
hour1 = 19;
-
}
-
else if (hour1 = 01) //line 20
-
{
-
hour1 = 20;
-
}
-
else if (hour1 = 02)
-
{
-
hour1 = 21;
-
}
-
else if (hour1 = 03)
-
{
-
hour1 = 22;
-
}
-
else if (hour1 = 04)
-
{
-
hour1 = 23;
-
}
-
else
-
{
-
hour1 = 00;
-
}
-
document.time.hour= hour1 //line 40
-
}
-
</script>
-
<form name=time>
-
<center>
-
<input type="text" maxlength=2 size=2 id="hour" name="hour" ></input> :
-
<input type="text" maxlength=2 size=2 id="minute" name="minute"></input>
-
<br>
-
<input type="button" id="local" value="Local -> Zulu" onClick="zulu()"></input>
-
<input type="button" id="zulu" value = "Zulu -> Local" onClick="local()"></input><br>
-
</form>
-
</html>
-
22 4071 Dormilich 8,658
Recognized Expert Moderator Expert
you have errors on line 4, 5 & 12: - if (hour1 > 05 & < 23) ???
-
-
// maybe you mean
-
if (hour1 > 05 && hour1 < 23)
Dormilich,
There's still an error somewhere. I changed the &&. Also, why would I use the getElements when there is only one element to get a value from?
@risk32
:) Because that is the syntax
Freddie
freddieMaize,
There's also a syntax for a single element, getElementBy(Id, Name, Type...)
Dormilich 8,658
Recognized Expert Moderator Expert @risk32
there isn’t*. (see ref.) everything else is getElementsBy*()
* - because the id attribute is the only one defined as unique (see html DTD).
Ah ok.. the getElement is only for ID while getElements is for Names. I got the code to produce no errors, but it's not updating the text box. I'm researching how to use objects to do this. -
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
-
<html>
-
<head>
-
<meta name="generator" content="HTML Tidy for Linux (vers 6 November 2007), see www.w3.org">
-
<script type="text/javascript">
-
// if zulu - > time is checked
-
-
-
function local()
-
{
-
-
var hour1;
-
hour1 = document.getElementsByName("hour").value;
-
var minute1;
-
minute1 = document.getElementsByName("minute").value;
-
parseInt(hour1);
-
parseInt(minute1);
-
-
if (hour1 > 05 && < 23)
-
{
-
hour1 = hour1 - 5;
-
}
-
else if (hour1 = 00)
-
{
-
hour1 = 19;
-
}
-
else if (hour1 = 01)
-
{
-
hour1 = 20;
-
}
-
else if (hour1 = 02)
-
{
-
hour1 = 21;
-
}
-
else if (hour1 = 03)
-
{
-
hour1 = 22;
-
}
-
else if (hour1 = 04)
-
{
-
hour1 = 23;
-
}
-
else
-
{
-
hour1 = 00;
-
}
-
parseString(hour1);
-
parseString(minute1);
-
document.hour.write(hour1);
-
}
-
-
-
function zulu()
-
{
-
var hour2;
-
hour2 = document.getElementsByName("hour").value;
-
var minute2;
-
minute2 = document.getElementsByName("minute").value;
-
parseInt(hour2);
-
parseInt(minute2);
-
-
if (hour2 < 19)
-
{
-
hour2 = hour2 + 5;
-
}
-
-
else if (hour2 = 20)
-
{
-
hour2 = 01;
-
}
-
-
else if (hour2 = 21)
-
{
-
hour2 = 02;
-
else if (hour2 = 22)
-
{
-
hour2 = 03;
-
}
-
else if (hour2 = 23)
-
{
-
hour2 = 04;
-
}
-
parseString(hour2);
-
parseString(minute2);
-
document.hour.write(hour2);
-
}
-
</script>
-
<title></title>
-
</head>
-
<body>
-
<center>
-
-
<input type="text" name="hour" maxlength="2" size="2">:
-
<input type="text" name="minute" maxlength="2" size="2"><br>
-
<input type="button" id="local" value="Local -> Zulu" onclick="function zulu()">
-
<input type="button" id="zulu" value="Zulu -> Local" onclick="function local()">
-
<br></center>
-
</body>
-
</html>
-
OK... I've gotten rid of the BS I don't need in my code. There's no point of messing with the minute portion of it, so I took it out. Hopefully I did the parseInt() portion of it right. After doing the mathematical functions to the recently parsed strings, I need to convert the integers back to strings to input them in the text box, right?? I'm kinda lost. The document.write(hour) doesn't seem to be working. I would imagine that it's doing nothing with it, because I am not specifiying where exactly to write the string. I'm so close to being done, but yet so far away. According to IE, there's an object that is missing, but I can't figure out what it is. -
<html>
-
<script type="text/javascript">
-
// if zulu - > time is checked
-
-
function localToZulu()
-
{
-
var hour = document.getElementByValue("hour");
-
parseInt(hour);
-
if (hour > 05 && < 23)
-
{
-
hour = hour - 5;
-
}
-
else if (hour == 00)
-
{
-
hour = 19;
-
}
-
else if (hour == 01)
-
{
-
hour = 20;
-
}
-
else if (hour == 02)
-
{
-
hour = 21;
-
}
-
else if (hour == 03)
-
{
-
hour = 22;
-
}
-
else if (hour == 04)
-
{
-
hour = 23;
-
}
-
else
-
{
-
hour = 00;
-
}
-
-
}
-
-
stringHour = parseString(hour);
-
document.hour.write(stringHour);
-
-
// if local time is checked
-
function zuluToLocal()
-
{
-
var hour = document.getElementByName("hour");
-
parseInt(hour);
-
if (hour < 19)
-
{
-
hour = hour + 5;
-
}
-
-
else if (hour == 20)
-
{
-
hour = 01;
-
}
-
-
else if (hour == 21)
-
{
-
hour = 02;
-
}
-
else if (hour == 22)
-
{
-
hour = 03;
-
}
-
else if (hour == 23)
-
{
-
hour = 04;
-
}
-
}
-
-
stringHour = parseString(hour);
-
document.hour.write(stringHour);
-
-
</script>
-
<center>
-
Hour Minute<br><input type="text" size=2 maxlength=2 name="hour">
-
<input type="text" size=2 maxlength=2 name="minute">
-
<br>
-
<input type="button" value="Local" onClick="zuluToLocal()">
-
<input type="button" value="Zulu" onClick="localToZulu()">
-
</center>
-
</html>
-
Dormilich 8,658
Recognized Expert Moderator Expert - function localToZulu()
-
{
-
// this method does not exist
-
var hour = document.getElementByValue("hour");
-
-
// hour is not affected by parseInt(), you need to assign the return value
-
parseInt(hour);
-
-
// invalid syntax, operand missing
-
if (hour > 05 && < 23)
-
-
…
-
}
-
-
// not necessary here, JavaScript does type conversation automatically
-
stringHour = parseString(hour);
-
-
// write() is a method of document only
-
document.hour.write(stringHour);
-
-
function zuluToLocal()
-
{
-
// this method does not exist
-
var hour = document.getElementByName("hour");
-
…
-
}
just out of interest, do you have any JavaScript reference work where you can look up?
My reference material is limited due to the fact I'm on a government computer.
I'll look at home to see if I can find anything. I'm used to using Java so JS seems comfusing to me in some aspects. The amount you can do in JS is limiting.
Dormilich 8,658
Recognized Expert Moderator Expert @risk32
Java and JavaScript hardly have anything in common. Don’t try to conclude from one to the other, this will only get you in trouble.
for instance:
while Java’s inheritance is class based, JavaScript’s inheritance is prototype based (see wikipedia for explanation).
you can add/alter/delete properties and methods in JavaScript anytime you want, even at runtime. @risk32
you have hardly an idea what you actually can do with JavaScript. You’d be surprised…
JavaScripts possibilities depend on the JS parser used (this may be a browser, but I’ve also seen a game engine using it)
gits 5,390
Recognized Expert Moderator Expert @risk32
Just by not knowing a language doesn't mean that it is limiting per se ... it is just limiting the 'unknowing' people ... i.e. if i don't know how to speak zulu it is limiting me! unless i have learned it ... but it isn't a limiting language itself because all native 'zulu'-speakers can have very unlimited conversations :) JavaScript has much greater potential as most people think ... even though it does have its limits of course ... like any other programming language has.
kind regards
OK...OK.... I'll admit it... I'm a fool when it comes to JS. I've only been able to pick up bits and pieces from other's work (no, i don't use what they code... that's pretty much stealing when it's not open source) and from reference material I just so happen to stumble upon when doing a google search. With the code I'm trying to produce, basically just simple math then displaying the number back into the text back, do I have the right basic idea?
Dormilich 8,658
Recognized Expert Moderator Expert @risk32
mmmmh……… no.
replacing text in form elements is (mostly) simple: - // input is the corresponding <input> element
- input.value = "new_value";
if you want one single element, use an id: - // the html element
-
<input id="box1" type="text" name="…" … >
-
-
// now in JS
-
var input = document.getElementById("box1");
-
-
// read what’s typed in
-
var usertext = input.value;
-
// if you want an integer
-
var userint = parseInt(input.value);
if you do comparisons, the syntax is always ([] - optional):
[ ( ] operand operator operand [ ) ]
ex: x < 1 && x > -1 or ((x < 1) && (x > -1))
note that the result of one of those comparison expressions is evaluated as boolean.
So basically, I create a variable to capture the input from the text box (I used "hour" for the Id)... -
var hour1 = document.getElementById("hour");
-
Seems simple enough... When replacing the text like you said, would I be in the righrt to do this?
If it's right, how would I use the text variable to replace what's in the text box?
Dormilich 8,658
Recognized Expert Moderator Expert @Dormilich
I must apologize for asking so many questions that seem fairly easy to you guys. IE is saying I have an error (Object Expected, Line 89). I've looked at the coding but everything "seems" right... The buttons are correctly directed to the JS functions. At least from what I can tell. Could you tell me if I put the code in the correct order? I put the variable before the function so that it will exist before the function starts. Then I put the hour1.value after the functions so that no matter which button is pressed, the result would still be the same. -
<html>
-
<script type="text/javascript">
-
// if zulu - > time is checked
-
-
-
-
-
var hour1 = document.getElementById("hour");
-
-
function localToZulu()
-
{
-
-
-
-
if ((hour1 > 05 && < 23))
-
{
-
hour1 = hour1 - 5;
-
}
-
else if (hour1 == 00)
-
{
-
hour1 = 19;
-
}
-
else if (hour1 == 01)
-
{
-
hour1 = 20;
-
}
-
else if (hour1 == 02)
-
{
-
hour1 = 21;
-
}
-
else if (hour1 == 03)
-
{
-
hour1 = 22;
-
}
-
else if (hour1 == 04)
-
{
-
hour1 = 23;
-
}
-
else
-
{
-
hour1 = 00;
-
}
-
-
-
-
}
-
-
-
-
-
// if local time is checked
-
function zuluToLocal()
-
{
-
-
-
if (hour1 < 19)
-
{
-
hour1 = hour1 + 5;
-
}
-
-
else if (hour1 == 20)
-
{
-
hour1 = 01;
-
}
-
-
else if (hour1 == 21)
-
{
-
hour1 = 02;
-
}
-
else if (hour1 == 22)
-
{
-
hour1 = 03;
-
}
-
else if (hour1 == 23)
-
{
-
hour1 = 04;
-
}
-
-
-
}
-
-
hour1.value = new_text;
-
-
</script>
-
<center>
-
Hour Minute<br><input type="text" id="hour" size=2 maxlength=2 value="">
-
<input type="text" size=2 maxlength=2 name="minute">
-
<br>
-
<input type="button" value="Local" onClick="zuluToLocal()">
-
<input type="button" value="Zulu" onClick="localToZulu()">
-
</center>
-
</html>
-
Dormilich 8,658
Recognized Expert Moderator Expert @risk32
ah, well, a matter of experience @risk32
unfortunately this conclusion doesn’t work. line 8 and 82 will only be executed on (before) page load plus you assign an undefined value to an undefined element. after that line 8 and 82 will not be executed any more.
if you then call the functions hour1 still doesn’t exist (is undefined). further you don’t access the input value.
you have to put the get/set operations inside the functions (because only the functions are executed): - function localToZulu()
-
{
-
var hour = parseInt(this.value);
-
-
if (1 == hour)
-
{
-
hour = 20;
-
}
-
// etc.
-
-
this.value = hour;
-
}
line 15 still is wrong
further you can improve you conditions, you can reduce it to one singe if statement. (you can get off with 5 lines of code (brackets not included) for your time conversion function.)
Here's something I've been taking a look at... Don't know if it will work or not, but it looks like it would if I split it up. -
<script type="text/javascript">
-
function changeText2(){
-
var userInput = document.getElementById('userInput').value;
-
document.getElementById('boldStuff2').innerHTML = userInput;
-
}
-
</script>
-
<p>Welcome to the site <b id='boldStuff2'>dude</b> </p>
-
<input type='text' id='userInput' value='Enter Text Here' />
-
<input type='button' onclick='changeText2()' value='Change Text'/>
-
From the way this is displayed, I could change the id of "userInput" to "display", and have the text displayed after the buttons, in a <p> section... I'll see if it works.
OK... I got it to work. But there's a problem... I'm not sure how to format the numbers to include a 0 in front of the number. I remember doing something like this in my JAVA class, but it's been a while. Does this sound right? -
-
-
hour = "0" + (hour + 5);
-
hour = "0" + (hour - 5);
-
-
I also haven't been able to figure out how to replace the original number in the text box, but what I did works... -
// JS...
-
function zuluToLocal()
-
{
-
var hour1 = document.getElementById("hour").value;
-
var minute1 = document.getElementById("minute").value;
-
var hour = parseInt(hour1);
-
-
-
if (hour > 05 && hour < 23)
-
{
-
hour = hour - 5;
-
}
-
else if (hour = 00)
-
{
-
hour = 19;
-
}
-
else if (hour = 01)
-
{
-
hour = 20;
-
}
-
else if (hour = 02)
-
{
-
hour = 21;
-
}
-
else if (hour = 03)
-
{
-
hour = 22;
-
}
-
else if (hour = 04)
-
{
-
hour = 23;
-
}
-
else
-
{
-
hour = 00;
-
}
-
-
document.getElementById("div1").innerHTML=(hour + ' ' + minute1);
-
-
}
-
-
// HTML...
-
<center>
-
Hour Minute<br><div id="div1"> <input type="text" id="hour" size=2 maxlength=2>
-
<input type="text" size=2 maxlength=2 name="minute">
-
</div>
-
<br>
-
<input type="button" value="Local" onClick="zuluToLocal()">
-
<input type="button" value="Zulu" onClick="localToZulu()">
-
<p id="display"></p>
-
</center>
-
</html>
-
Dormilich 8,658
Recognized Expert Moderator Expert @risk32
looks good @risk32
what about : - function zuluToLocal()
-
{
-
var hour1 = document.getElementById("hour");
-
var hour = parseInt(hour1.value);
-
-
// hour conversion
-
-
hour1.value = hour;
-
}
@Dormilich
I tried your suggestion. Seems to be working just fine. Thanks for all the help/
Dormilich 8,658
Recognized Expert Moderator Expert
if you're used to it, JavaScript is not complicated after all.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: malcolm |
last post by:
How do I get a web-browser loaded with on-the-fly content and a JavaScript
onclick popup function to work?
I've embedded an axWebBrowser in my (vb.net) application. The browser
starts with...
|
by: bbcrock |
last post by:
I created a "cancel" button for my form at the clients' request, I
accidentally copied a submit button and added an OnClick event- a very
simple javascript.history function. It did not appear to...
|
by: gakman_2006 |
last post by:
I am trying to get an onclick event to pass some values to a function to display in an alert box for now. I can get it sort of working but now the way I need it. I will be changing the alert in the...
|
by: Amil Hanish |
last post by:
I have a GridView with a <asp:HyperLinkinside a <TemplateItem>. I want to
add the javascript onclick code to confirm the link click. What is the best
way to do this?
I can put the onclick=......
|
by: grantmx |
last post by:
Hey guys - We am having problems with the following code in our form:
<tr><td></td><td align=right><input type="image" name="_ctl25:btnSaveLarge" onclick="if (typeof(Page_ClientValidate) ==...
|
by: KRISHNA PRAVI |
last post by:
the error is "runtime error object expected" here is the code.......................................................................................
<script language="javascript"...
|
by: Mtek |
last post by:
Hi,
We have a form defined with buttons like this:
<a class="save_menu" href="javascript:document.Detail_Screen.action =
'savedata.php?screen=EDIT';document.Detail_Screen.submit();">Update</...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |