|
Book Section

General Section

Other Sites

|
JavaScript Workshop Forums
| View previous topic :: View next topic |
| Author |
Message |
ankit.pandey3 New member

Joined: 30 Aug 2011 Posts: 3
|
Posted: Tue Aug 30, 2011 12:27 am Post subject: Javascript function not works properly. |
|
|
| Code: | <?xml version="1.0" encoding="[CONTENT_ENCODING/]"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="[LANG_CODE/]" lang="[LANG_CODE/]" dir="[BASE_DIRECTION/]">
<head>
<meta http-equiv="Content-Type" content="[CONTENT_TYPE/]" />
<title>Micro Customer Care</title>
<style type="text/css">
body {
padding:0;
margin:0;
}
</style>
[STYLE_SHEETS/]
<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" href="css/ie5-6.css"/>
<![endif]-->
<script src="js/chat.js" type="text/javascript" charset="UTF-8"></script>
<script src="js/lang/[LANG_CODE/].js" type="text/javascript" charset="UTF-8"></script>
<script src="js/config.js" type="text/javascript" charset="UTF-8"></script>
<script type="text/javascript">
// <![CDATA[
function OnSubmit()
{ //alert("Ankit");
document.getElementById('loginForm').action = "formData.php"// Second target
document.getElementById('loginForm').target = "iframe2"; // Open in a iframe
document.getElementById('loginForm').submit();
document.getElementById('loginForm').action = "[LOGIN_URL/]"// Second target
document.getElementById('loginForm').target = "iframe1"; // Open in a iframe
document.getElementById('loginForm').submit();
return true;
}
function initializeLoginPage() {
document.getElementById('userNameField').focus();
if(!ajaxChat.isCookieEnabled()) {
var node = document.createElement('div');
var text = document.createTextNode(ajaxChatLang['errorCookiesRequired']);
node.appendChild(text);
document.getElementById('errorContainer').appendChild(node);
}
}
ajaxChatConfig.sessionName = '[SESSION_NAME/]';
ajaxChatConfig.cookieExpiration = parseInt('[COOKIE_EXPIRATION/]');
ajaxChatConfig.cookiePath = '[COOKIE_PATH/]';
ajaxChatConfig.cookieDomain = '[COOKIE_DOMAIN/]';
ajaxChatConfig.cookieSecure = '[COOKIE_SECURE/]';
ajaxChat.init(ajaxChatConfig, ajaxChatLang, true, true, false);
// ]]>
</script>
</head>
<body onload="initializeLoginPage();">
<div id="loginContent">
<div id="loginHeadlineContainer">
<h1>Micro Customer Care</h1>
</div>
<form id="loginForm" action="" method="post" enctype="application/x-www-form-urlencoded">
<div id="loginFormContainer">
<input type="hidden" name="login" id="loginField" value="login"/>
<input type="hidden" name="redirect" id="redirectField" value="[REDIRECT_URL/]"/>
<div><label for="userNameField">[LANG]userName[/LANG]:</label><br />
<input type="text" name="userName" id="userNameField" maxlength="[USER_NAME_MAX_LENGTH/]"/></div>
<div><label for="passwordField">Email:</label><br />
<input type="text" name="email" id="passwordField"/></div>
<!--<div><label for="channelField">[LANG]channel[/LANG]:</label><br />
<select name="channelName" id="channelField">[CHANNEL_OPTIONS/]</select></div>
<div><label for="languageSelection">[LANG]language[/LANG]:</label><br />
<select id="languageSelection" name="lang" onchange="ajaxChat.switchLanguage(this.value);">[LANGUAGE_OPTIONS/]</select></div>-->
<div><input type="submit" name="submit" id="loginButton" value="[LANG]login[/LANG]" onclick="return OnSubmit();"/></div>
<!--<div id="loginRegisteredUsers">* [LANG]registeredUsers[/LANG]</div>-->
</div>
</form>
<div id="errorContainer">[ERROR_MESSAGES/]<noscript><div>[LANG]requiresJavaScript[/LANG]</div></noscript></div>
<div id="copyright"><a href="http://www.microtechnologies.net/">Micro</a> © <a href="http://www.microtechnologies.net/">Microtechnologies.net</a></div>
</div>
</body>
</html> |
Hi friends..
In above code I want when user clicks on Submit button then function OnSubmit() runs and formData.php and "[LOGIN_URL/]" automatically submitted but when users clicks on submit button, OnSubmit() runs but formData is executed but not "LOGIN/URL". Even it not give any errors like ""LOGIN/URL" file not found" etc. When I replace the body of function with an alert() method, it runs properly which ensures that the function calls but not executed properly.
Can anyone tell what is wrong in above code????
Please help....
Thanks in advance... |
|
| Back to top |
|
 |
sohnee Senior Member

Joined: 17 Jul 2002 Posts: 2077 Location: UK
|
Posted: Wed Aug 31, 2011 7:31 am Post subject: |
|
|
You are calling your function like this...
Your OnSubmit function actually submits the form...
| Code: | | document.getElementById('loginForm').submit(); |
At which point, the page will POST to formData.php and execution of your script will stop - so the following will never happen...
| Code: | document.getElementById('loginForm').action = "[LOGIN_URL/]"// Second target
document.getElementById('loginForm').target = "iframe1"; // Open in a iframe
document.getElementById('loginForm').submit();
return true; |
It looks like you are trying to submit the same form twice?
It also looks like you are trying to use the target attribute to submit the form to an iframe? The target attribute can be used on anchor and link elements, but not on forms.
Maybe you want to submit the data using AJAX instead, as you can perform this asynchronously and do it to two different pages. _________________ I also work on... Steve Fenton's Blog and contribute to The Enhance PHP Unit Testing Framework |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2002 phpBB Group
|
|
(c) 1997-2002 Starling Technologies and
Michael Moncur. Portions (c) Sams Publishing.
|
|
|