tags:

views:

39

answers:

3

Hi,

i have a php like this:

<?php
......
?>
<html>
<head></head>
<body>
<div id="content">
<form id="myform" name="myform">
<?php include_once("ronny.php"); ?>
.....
<input type="button" value="Save" id="Save" name="Save" onclick="if(check123()==true){document.myform.submit()}" />
</div>
</form>
...

Now, in this case after i click on save i have an error document.myform.submit is not a function in firebug and in IE the error is Object doesn't support this property or method. If i delete the <?php include_once("ronny.php"); ?> everything is ok.

ronny.php is like that:

<?php

if(......)){

?>
<div></div>
<div></div>
<SCRIPT LANGUAGE="JavaScript">
....
</SCRIPT>
<?php } ?>

If i put the include in the php at the top it's ok as well.

thank you!

A: 
document.myform.submit()

myform should be the name of form. What is check123()? Function?

Alexander.Plutov
myform is the name of the form. yes, check123() is a function.
Ronny
You should use document.getElementById("myform").submit() instead of document.myform.submit(). For reasoning, see this post: http://stackoverflow.com/questions/2813582/javascript-window-object-element-properties
Timothy
tried and - `document.getElementById("myform").submit is not a function`
Ronny
A: 

If you want to use the document.myform notation, you'll have to add a name= attribute to the form tag:

<form name="myform">
...
</form>

or if you have to stick with the id version, then use this in Javascript:

document.getElementById('myform').submit();

Beyond that, what's in the ronny.php function? If taking it out makes the form work, then obviously something in ronny.php is messing with your HTML and/or Javascript and "breaking" things.

Marc B
i tried with adding the name attribute but still the same problem.
Ronny
Then do 'view source' on the generated page and see what the form really looks like. No matter how much you stare at your PHP code, in situations like this it's best to look at what the code's outputting than staring at what the code is.
Marc B
ok i found the problem. in the include page there is another `<input type="button" id="submit" name="submit">`. if i change it to `<input type="button" id="submit1" name="submit1">` it is the same?
Ronny
names and IDs have to be unique on any given page. Generally the last one found will be the one that will be used. In IE especially, it will auto-create objects for any 'name' found, so most likely the name="submit" overrode the submit() method of the original button object.
Marc B
+1  A: 

I would do :

<input type="button" value="Save" id="Save" name="Save" onclick="check123();this.form.submit();" />
M42