homepage Welcome to WebmasterWorld Guest from 54.226.80.196
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
form submit problem using javascript
can not submit the form data using javascript
enil




msg:3179648
 5:23 am on Dec 6, 2006 (gmt 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

 

rocknbil




msg:3180807
 2:10 am on Dec 7, 2006 (gmt 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.

Achernar




msg:3181955
 12:21 am on Dec 8, 2006 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved