Submit form of iframe from parent window

In phpxperts yahoo group there was a thread about how to submit a form in a iframe outside the iframe I mean from parent window. I replied my idea using js but the iframe should be in same domain. The js code is like
[code language=”php”]window.top.myframename.document.myformname.submit();[/code]
let me give u whole code. make a new file named frame.html and write the bellow code in that file
[code language=”php”]
<form id="myformid" name="myformname" method="post" action="" target="_self" onSubmit="">
Name: <input type="text" size="20" name="name" value="" id="namefield" />
</form>
[/code]

and open a new file again and save in same dir with name index.html and write the bellow code in it
[code language=”php”]
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Iframe form submit from outside</title>
</head>

<body>

<div id="infodivid"></div>
<iframe src ="frame.html" width="auto" height="40px" frameborder="0" id="myframeid" name="myframename">
</iframe>
<p><input onClick="submitiframeform(); return false;" type="button" name="submit" value="Submit" /></p>
<script type="text/javascript">

function submitiframeform(){
window.top.myframename.document.myformname.submit();
}
</script>
</body>
</html>
[/code]

now open the index.html in browser and click the submit button and see the form is getting submitted. I think If you just check the code then I don’t need to explain ‘what is why’.

thanks

childNodes problem in FF !!!

I was working with js and got a peculiar problem (it’s was unknown to me 😛 😀 🙁 ) about childNodes count in firefox and opera. Internet explorer showed perfectly. suppose my html is like
[sourcecode language=’css’]

  • One
  • Two

[/sourcecode]
Now the js:
[sourcecode language=’css’]
objFather = document.getElementById(‘ul_id’); //get the father ul’ ID
arrayChildren = objFather.childNodes; //geting array of children
childNum = arrayChildren.length;
[/sourcecode]

Here childNum will give diff values for diff browser. FF, Opera counts the whitespaces . textnodes as child but IE is normal in this case.

Usefull link: One

Detect browser name and version using js

I was trying to detect browser version and browser name using java script. I got so many techniques but I am happy with jquery’s one. It’s pretty simple and small block of code. Just check the bellow code that I got from jquery. As it is not possible to use the whole js library all the time but I like to use some part of it or follow the techniques for cross browser tasks. 😀
[sourcecode language=’css’]
//Detect browser version
var userAgent = navigator.userAgent.toLowerCase();
// Figure out what browser is being used
var browser = {
version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],
safari: /webkit/.test( userAgent ),
opera: /opera/.test( userAgent ),
msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),
mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )
};
alert(‘Browser Version=’+browser.version.toString()+ ‘ Safari=’+(browser.safari? ‘Yes’: ‘No’)+’ Opera=’+(browser.opera? ‘Yes’: ‘No’)+’ IE=’+(browser.msie? ‘Yes’: ‘No’)+’ FF=’+(browser.mozilla? ‘Yes’: ‘No’));
//end browser detection
[/sourcecode]

Edit: Here one thing you may be confused about the test() method. It’s a builtin function in js. The test() method is used to search for a match of a regular expression in a string.

Here’s some links about Test();

  1. Email Address valiadtion
  2. W3 school link