Topic: Ok...onClick and <button> problems (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=23122" title="Pages that link to Topic: Ok...onClick and &amp;lt;button&amp;gt; problems (Page 1 of 1)" rel="nofollow" >Topic: Ok...onClick and &lt;button&gt; problems <span class="small">(Page 1 of 1)</span>\

 
Crotaline
Nervous Wreck (II) Inmate

From: Bottom of an empty bottle
Insane since: Aug 2004

posted posted 08-30-2004 14:16

I have a few reference book, but i cant seem to find what im looking for. Its also easier to ask here than troll thru a 1500 page book with type too small to read without giving myself a headache... but im rambling...

Im trying to make this :

<button onClick=" ">Close Window</button>

I know there is supposed to be something between the quotes, but I cant pull my head out of me a$$ long enough to figure it out. Im running DW MX 2004, and i cant seem to find the action there to just drop in. Its so intuitive, its been a great help with me getting up to speed, but I cant seem to get this done.

thanks.

C.

And yes, im a noob. I figured with this question it was pretty obvious, but Ill state it for the record. I have done light design for a while, and tinkered a lot, but I tend to get bored quickly. I made myself promise to really, REALLY get into DW and be somewhat proficient by the end of Sept. Wish me luck.

(Edited by Crotaline on 08-30-2004 14:24)

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 08-30-2004 15:45

First of all, you have to add a type attribute, otherwise the button will default to acting like a submit button.

code:
<button type="button">...


Secondly, you can add an onclick event like this

code:
<script type="text/javascript">
function closeWindow()
{
...
}
</script>
... etc ...
<button type="button" onclick="closeWindow()">Close Window</button>

Crotaline
Nervous Wreck (II) Inmate

From: Bottom of an empty bottle
Insane since: Aug 2004

posted posted 08-30-2004 17:01

ok . did that, and thats in the right direction, but the error i get now is this:

when the onClick="closeWindow()" has a red squiggly underline, and i hold the mouse over it it says to me,

"The onclick attribute of the button tag is not supported."

WTF??? I thought this was the 21st century, not the damn middle ages...

thanks again in advance.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 08-30-2004 17:43
quote:
but the error i get now is this:



Where do you get this error exactly?

And I may be misunderstanding, but you will need to actually define the 'closeWindow' function.



{{edit - and yes, this is the 21st century as opposed to the middle ages. That means that there are now countless sources of information from which you can learn how to do things properly and avoid getting errors

(Edited by DL-44 on 08-30-2004 17:44)

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 08-30-2004 20:05

You mentioned something about Dreamweaver...I'll take a few guesses here, using imperfect information. (I've not used dreamweaver in years, and, thankfully, I've done a good job of wiping the details from my memory.)

What doctype are you using?
If you are using XHTML and your code reads:

code:
<button onClick="closeWindow()" type="button">...


...then it could be barking because, indeed, "onClick" does not exist.
Attributes in XHTML must be in lowercase.

code:
<button onclick="closeWindow()" type="button">...



Secondly, as DL said, do you actually have a funtion closeWindow() defined?

Crotaline
Nervous Wreck (II) Inmate

From: Bottom of an empty bottle
Insane since: Aug 2004

posted posted 08-30-2004 22:16

Okay... My bad for not explaining i am a newbie (i did, but not at the front of my og post, it was at the end...)
But I guess my question is you know what... Ill copy the whole thing here...
From the last post from mobrul Im assuming i have to define the closeWimdow function somehow. And in Dreamweaver it comes up automatically with the uppercase. So unless they have it wrong in the program (possible, but not probable...) Im not sure what Im missing.
Im really thankful for all the info, and I know when its fixed Ill feel like an ass, because it will have been something so simple I should have figured it out in 5 min.


POST EDITED !!!

I found a MXP to drop in to give me the behavior I needeed. Thanks again for all the feedback below is the fixed HTML (but not the final HTML. Im still fixing the sixe and noresize, which is not written in yet.)

C.

<HTML>
<META HTTP-EQUIV="refresh" CONTENT="60">
<META HTTP-EQUIV="expires" CONTENT="0">
<META HTTP-EQUIV="pragma" CONTENT="no-cache">
<meta http-equiv="content-type" content="javascript"

<script language="JavaScript" type="text/JavaScript">
<!--
function close_window() {
window.close();
}
//-->
</script>
<HEAD>
<TITLE>Bipolar Webcam</TITLE>
</HEAD>

<BODY>
<CENTER>
<p><IMG SRC="webcam.jpg">
<BR>
<SMALL>
Powered by <A HREF="http://www.evological.com/evocam.html">EvoCam</A>
</SMALL></p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<p>&nbsp;</p>
<button type="button" onClick="closeWindow();close_window()">Close Window</button>
</p>
</CENTER>
</BODY>

</HTML>

(Edited by Crotaline on 08-30-2004 22:37)

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 08-31-2004 00:15
quote:
And in Dreamweaver it comes up automatically with the uppercase. So unless they have it wrong in the program (possible, but not probable...) Im not sure what Im missing.



What you are missing is that Dreamweaver (and the like) are horribly suited as tools on which to learn the technology you are trying to learn.
That is, learning becomes MORE difficult with this sort of software, not less.

I strongly suggest you get yourself a copy of vi, notepad, or even our very own Mr. Max's HTML Beauty and learn to code on your own. It'll be slow at first, but with some helpful people around here, you'll be actually learning in no time.

So, back to the issue at hand.
Clean up your code, at least a little bit. In your button element, the onclick attribute, what you are doing is calling a function. Well, actually, right now you are calling two functions. One of them (closeWindow()) does not exist. One of them (close_window()) does exist.
Remove the one that does not exist.

code:
<button type="button" onclick="close_window()">Close Window</button>



Now the important thing here is not that you can manipulate Dreamweaver or copy some code I (or anyone else) posts up here. The important thing is that you understand why we (me, dreamweaver, DL, etc) put that code there in the first place.

Crotaline
Nervous Wreck (II) Inmate

From: Bottom of an empty bottle
Insane since: Aug 2004

posted posted 08-31-2004 12:17
quote:
Now the important thing here is not that you can manipulate Dreamweaver or copy some code I (or anyone else) posts up here. The important thing is that you understand why we (me, dreamweaver, DL, etc) put that code there in the first place.




Uh... im not trying to steal anyones stuff...I just didnt know what I was doing, and why stuff wasnt working. I figured that the reason most people put the code here is to show in HTML what is wrong and how to fix it. I never meant to plagiarize or anything like that.

the main reason i use Dreamweaver and GoLive(not so much anymore...) is they are WYSIWYG with a split code/design view. I am very visual, so for me its easier to lay it out first as I want it, then edit the code...tweak it to do what I want. I know in some ways it would be easier to learn the core language first, then go back or not use them at all, but for now, and for what I want to do, it is easier.
And now looking at the javascript function and the button line I see exactly what you are saying with the double code error.

Thanks again (and again) for the help.(I think I should make that My sig...)

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 08-31-2004 14:50

I wasn't talking about stealing. If I put something up in here, I consider it open for people to take, use, twist, build with, learn from, and ultimately create something better...then bring it back here, share, and the process starts all over again.
Plagiarism was the last thing on my mind. No worries there.

I would argue that the "lay it out first...then edit [later]" philosophy of web design is:

  • old school
  • inefficient
  • not in line with w3c standards
  • counterproductive for learning


Now, if you're convinced Dreamweaver is the way to go, I'm not going to argue with you. You have every right to follow the path you wish. But, if you're interested in looking at web development in a different light, just say so. In fact, I'd strongly encourage you to do so.
That's all I was talking about.

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 09-09-2004 12:28

But really, all this begs the question 'why not just use this:

code:
<button type="button" onclick="window.close()">


?'

Of course, knowing squat about javascirpt myself and not being as up with my XHTML as I should be I could possibly have that wrong, but isn't it easier than creating a whole seperate function for the one method?

mobrul
Bipolar (III) Inmate

From:
Insane since: Aug 2000

posted posted 09-09-2004 17:03

I have no idea whatsoever if that validates or not.
Functionally, it would work well.

For me, it's a philosophy thing. I like to keep my JS seperate from my XHTML seperate from my CSS.
In fact, if it were me, I'd simply assign it a class = "close" with no onclick attribute.
Then, I'd have a function (called onload) which would dynamically assign to it an onclick attribute, assigning to it the appropriate function.



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu