Welcome to WebmasterWorld Guest from 54.146.217.179

Forum Moderators: incrediBILL

Message Too Old, No Replies

Problem across browsers in submitting form through Javascript

     
12:27 pm on May 21, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:May 18, 2007
posts:49
votes: 0


I am submitting a form using javascript code document.formname.submit()

It works fine in IE but the other browsers are not supporting this feature. I have tried Firefox, Netscape and Opera. The Javascript Error Console in Firefox and Netscape showed error on that very line.

Have anyone got any idea. I searched google but thats a real waste of time.....

4:47 pm on May 21, 2007 (gmt 0)

Senior Member

WebmasterWorld Senior Member tedster is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:May 26, 2000
posts:37301
votes: 0


First, I'd say validate your html against the doctype you are using to find any missing close tags or other true errors. Also try document.forms.formname.submit() - that might make a difference.
8:40 am on May 22, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:May 18, 2007
posts:49
votes: 0


Hi,

No result. I have also tried document.getElementById('f1').submit() where f1 is the id of the form.

Can anyone help me out?

1:56 pm on May 22, 2007 (gmt 0)

Full Member

5+ Year Member

joined:Dec 3, 2006
posts:257
votes: 0


What about :
document.forms['form-name'].submit();
or
document.forms[form-num].submit();
5:36 am on May 23, 2007 (gmt 0)

Junior Member

5+ Year Member

joined:May 18, 2007
posts:49
votes: 0


It works. But my purpose has not solved yet. I want to store some values in hidden fields in a form and submit it automatically when I call the form submitting function. My code is:
<form name="f1" action="search_cdr_result.php" method="post">
<input type="hidden" name="sDate" value="<?php echo($sDate);?>">
<input type="hidden" name="eDate" value="<?php echo($eDate);?>">
<input type="hidden" name="phone" value="<?php echo($phone);?>">
<input type="hidden" name="flag" value="2">
</form>
<script language="JavaScript">
function submitform()
{
document.forms['f1'].submit();
}
submitform();
</script>

Any suggestion? I can pass the values as:
$url="search_cdr_result.php?sDate=".$sDate."&eDate=".$eDate."&phone=".$phone."&flag=2";

But when the number of variables increases its hard to maintain.

5:37 am on May 23, 2007 (gmt 0)

Senior Member from MY 

WebmasterWorld Senior Member vincevincevince is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Apr 1, 2003
posts:4847
votes: 0


You need to have a SUBMIT type INPUT element to automatically sumbit the form in many browsers.

<input type="submit" style="width:0px;height:0px" value="">

Something like that should work fine.

For passing lots of variables, consider using an array... <input name="something[]" type="hidden" value="1">
<input name="something[]" type="hidden" value="2">
<input name="something[]" type="hidden" value="3">

That gives you, on your server side, something[0], something[1], something[2]

2:01 pm on May 24, 2007 (gmt 0)

Full Member

5+ Year Member

joined:Dec 3, 2006
posts:257
votes: 0


All form elements values are transmited on submit, even hidden fields. What is you problem?