Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

form submit problem using javascript

can not submit the form data using javascript

5:23 am on Dec 6, 2006 (gmt 0)

New User

10+ Year Member

joined:Nov 21, 2006
votes: 0

hi 2 all,
my problem is:
i used below form,
<form method="post" name="checkfrm" id="checkfrm" style="margin:0px;" >
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<td width="50%" height="20" align="right">
<input name="domain" type="text" class="textbox1" size="30" maxlength="63" onkeypress="enter();" /></td>
<td width="5%" height="20"></td>
<td width="40%" height="20" align="left"><input name="submit_btn" type="submit" class="button" value="Go, Get It!" onClick="return validation();"/></td>
it has no action.
i programmed using javascript in a way that it determines dynamically the action.
here are the javascript
function validation()
document.checkfrm.action = "index.php";
return false;
document.checkfrm.action = "results.php";
return true;

function enter()
if(window.event.keyCode == 13)
document.forms[0].action = "results.php";
when i press button, it works fine
but i want to submit the form when anyone type something in text box and when press enter.
at that time form is submited but the value of the textbox and button are not submitted. results.php file opens but does not show the php code. it shows well when i submit form using button.

i used both, forms[0] and form name('checkfrm') in javascript. but not worked in IE.

it works fine with the firefox browser but it fails in IE.

so anyone knows the remedy, then pls let me know


2:10 am on Dec 7, 2006 (gmt 0)

Senior Member

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

joined:Nov 28, 2004
votes: 0

Try this, it's an **old** piece of code which may explain why it's working for FF:

function enterKey(e,form) {
if (window.Event) { var whichCode = e.which; } //NN
else if (e.type == "keypress") { var whichCode = e.keyCode; } // IE
else { return; }
if (whichCode == 13) { // only if enter is pressed
// Enter -only action

I say "old code" because I abandoned this method long ago. If Javascript is disabled, the enter key will still submit as if the submit button was pressed. Secondly, this is "expected behavior" for forms, many users are familiar with pressing enter to submit. You are best letting it submit to ONE script and managing it server side somehow.

12:21 am on Dec 8, 2006 (gmt 0)

Full Member

10+ Year Member

joined:Dec 3, 2006
votes: 0

I think you should try :

<form method="post" name="checkfrm" id="checkfrm" style="margin:0px;" onsubmit="return validation();">

instead of using "onClick" on the submit button.