The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Web Design
> JavaScript Development
|
This.form.name not working!
Discuss This.form.name not working! in the JavaScript Development forum on Dev Shed. This.form.name not working! JavaScript Development forum discussing JavaScript and DHTML, AJAX, and issues such as coding cross-browser JavaScript.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 26th, 2012, 02:50 AM
|
 |
Confused badger
|
|
Join Date: Mar 2009
Location: West Yorkshire
|
|
|
This.form.name not working!
Hello all
Sorry to post what may be such an obvious or schoolboy problem but I can't see why this simple code works on one website I wrote, but not another!
PHP Code:
echo "<form method='post' name='customer' id='customer'>";
echo "<a href='#' onclick='alert(this.form.name);'>select all</a> <br />";
echo "</form>";
When I click on the 'select all' link, nothing happens; if I change it to alert 'this.form', I get "undefined" but as you can see, I have named and ID'd my form!
I have searched google and the syntax etc all appears to be correct (and as I mentioned above, I have used this code on other websites without problem).
Does anyone have any suggestions please?!
__________________
The number for UK Emergencies is changing, the new number is 0118 999 881 999 119 7253
"For if leisure and security were enjoyed by all alike, the great mass of human beings who are normally stupefied by poverty would become literate and would learn to think for themselves; and when once they had done this, they would sooner or later realise that the privileged minority had no function and they would sweep it away"
- George Orwell, 1984
|

September 26th, 2012, 08:41 AM
|
|
|
|
Can you post the entire HTML document please.
|

September 26th, 2012, 09:08 AM
|
 |
Confused badger
|
|
Join Date: Mar 2009
Location: West Yorkshire
|
|
Quote: | Originally Posted by Winters Can you post the entire HTML document please. |
Sure ...
PHP Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<?php
echo "<form method='post' name='customer' id='customer'>";
echo "<a href='#' onclick='alert(this.form.name);'>select all</a> <br />";
echo "</form>";
?>
</body>
</html>
I was trying to add a Select ALL / NONE / Toggle to an existing page and when it decided not to work I wrote that code to test the code without any external "interference" and discovered that it refused to work when there was nothing else going on!
I've also viewed page source and copied that into "newfile.html" (in effect dropping all PHP) and it still refuses to work!
For what it's worth, here's the "view source" from the above PHP ...
Code:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<form method='post' name='customer' id='customer'><a href='#' onclick='alert(this.form.name);'>select all</a> <br /></form></body>
</html>
|

September 26th, 2012, 10:09 AM
|
|
|
That seemed like a very eye-rolling "sure"  I wanted to see the document type and charset.
An anchor is not part of a form so it cannot reference a form as a form element parent child. It can be referenced as a parent node.
Javascript Code:
Original
- Javascript Code |
|
|
|
Last edited by Winters : September 26th, 2012 at 10:16 AM.
Reason: additional
|

September 26th, 2012, 10:23 AM
|
 |
Confused badger
|
|
Join Date: Mar 2009
Location: West Yorkshire
|
|
|
I see, ok yes, that makes sense now!
As for the 'sure ...' haha well the code I had posted was the entire page at the time of posting, I later added the rest of the HTML to see if that would make a difference ... apparently not.
I'm on with something else now though but when I revisit the select all / none / toggle, I will use a button.
ps. With regards to nicking the line from other code, I re-checked the original source and the onclick was taken from a submit button, doh
THANK YOU for the reply and assistance, it's very much appreciated!
|

September 26th, 2012, 10:26 AM
|
|
|
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|