JianJunShen
asked on
Javascript: prototype, form is undefined
I have form, when user modify something, it will popup"Are you sure you want to close? Unsaved changes will be lost". If it does not modify something, page would be closed silently. The whole page is as follows. I am using prototype.
The problem is at following part of codes:
<script type="text/javascript">
$('selfregform').attribute s['id'].no deValue=$( 'selfregfo rm').seria lize();
</script>
The firebug says $('selfregform') is undefined. I change to document.forms['selfregfor m'], it complains document.forms['selfregfor m'] is undefined. How to overcome this problme?
The problem is at following part of codes:
<script type="text/javascript">
$('selfregform').attribute
</script>
The firebug says $('selfregform') is undefined. I change to document.forms['selfregfor
<html>
<head>
<script type="text/javascript" src="prototype/prototype.js"></script>
<script type="text/javascript" src="toolportal_edit.js"></script>
<script type="text/javascript">
$('selfregform').attributes['id'].nodeValue=$('selfregform').serialize();
</script>
</head>
<body>
<form id='selfregform' action="http://www.hut.fi" method="POST" class="observed-form">
<input type="text" name="aName" value="test" />
<input type="checkbox" name="ignore" />
<input type="submit" name="action" id="close_button" value="Close" onclick="if ($('selfregform').attributes['id'].nodeValue] == $('selfregform').serialize() || confirm('Are you sure you want to close? Unsaved changes will be lost.')) { } $('selfregform').action.value='close';$('selfregform.submit(); return false;"/>
</form>
</body>
</html>
ASKER
I changed to
<script type="text/javascript">
document.forms['selfregfor m'].attrib utes['id'] .nodeValue =$('selfre gform').se rialize();
</script>
<form id='selfregform' name=''selfregform' action="http://www.hut.fi" method="POST" class="observed-form">
It has same problem.
<script type="text/javascript">
document.forms['selfregfor
</script>
<form id='selfregform' name=''selfregform' action="http://www.hut.fi" method="POST" class="observed-form">
It has same problem.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi: mplungjan:
I just want to store serialised value. Is it a good way to store it into id?
Juhani
I just want to store serialised value. Is it a good way to store it into id?
Juhani
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Well, I need to check whether form has been modified or not? If not, I will submit the form directly, if modified, I will pop up a remind dialog. could a javascript variable handle that?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks a lot for mahome and mplungjan. Best regards, Juhani
ASKER
The answer is excellent. I appreciate a lot for these two experts.
I don't know Prototype but for the document.forms[] method to work the name attribute needs to be in the form tag. Right now you just have it with the ID. Add a name attribute and provide the same value and that second code should work.
Let me know if you have any questions or need more information.
b0lsc0tt