Welcome to WebmasterWorld Guest from 54.211.169.76

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
posts:19
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">
<tr>
<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>
</tr>
</table>
</form>
---------------------------------------------------------
it has no action.
i programmed using javascript in a way that it determines dynamically the action.
here are the javascript
-------------------------------------------------
function validation()
{
if(!(document.checkfrm.domain.value))
{
document.checkfrm.action = "index.php";
return false;
}
else
{
document.checkfrm.action = "results.php";
return true;
}
}

function enter()
{
if(window.event.keyCode == 13)
{
document.forms[0].action = "results.php";
document.forms[0].submit();
}
}
-------------------------------------
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

Thanks
-ENIL

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
posts:7999
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
posts:257
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.

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members