Go Back   CodingForums.com > :: Client side development > JavaScript programming > Ajax and Design

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-19-2013, 04:25 AM   PM User | #1
hitlar
New to the CF scene

 
Join Date: Feb 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hitlar is an unknown quantity at this point
how value do not update according to script running after ajex response

<form action="start.do" method="post" name="login" onSubmit="formPost('loginsubmit.do', v); return false;">
<input type="text" name="login" size="35" class="ctrl">
<input type="text" name="password" size="35" class="ctrl">
<script>var v = new validator('login', a_fields, o_config);</script>
<input type="submit" name="Submit" value="Submit" class="btnform">
</form>`

My problem eval execute validator script but it does not update v of formPost argument. this data come from ajax response and add to div by document.getElementById.innerHTML. this page loads smoothly but when click submit button v is undefined. how i solve this problem to update v according v after running script
hitlar is offline   Reply With Quote
Old 02-19-2013, 08:16 AM   PM User | #2
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,454
Thanks: 0
Thanked 498 Times in 490 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by hitlar View Post
<form action="start.do" method="post" name="login" onSubmit="formPost('loginsubmit.do', v); return false;">
<input type="text" name="login" size="35" class="ctrl">
<input type="text" name="password" size="35" class="ctrl">
<script>var v = new validator('login', a_fields, o_config);</script>
<input type="submit" name="Submit" value="Submit" class="btnform">
</form>
There isn't any complete JavaScript there. If you want us to help you work out why JavaScript isn't working then you will need to show us the formPost() and validator() functions as well (along with any other code those funcvtions call).
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is online now   Reply With Quote
Old 02-19-2013, 12:31 PM   PM User | #3
hitlar
New to the CF scene

 
Join Date: Feb 2013
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
hitlar is an unknown quantity at this point
above code also come from formPost method, in above code script part run by paseScript function which is checked by firebug and it run smoothly but problem is when i click on submit button v is undefined

function formPost(strURL, v) {
if(v)
if(!v.exec())
return;
var xmlHttpReq = false;
var self = this;
if (window.XMLHttpRequest) {
self.xmlHttpReq = new XMLHttpRequest();
}
else if (window.ActiveXObject) {
self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}

self.xmlHttpReq.open('POST', strURL, true);
self.xmlHttpReq.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function() {
if (self.xmlHttpReq.readyState == 4) {
updatepage(self.xmlHttpReq.responseText); //,responsediv); //Text,responsediv);
}else{
updatepage(responsemsg,responsediv);
}
}
self.xmlHttpReq.send();

}

function updatepage(text){
document.getElementById(id).innerHTML = parseScript(text);
}

function parseScript(strcode) {
/* www.webdeveloper.com */
var scripts = new Array(); // Array which will store the script's code

// Strip out tags
while(strcode.indexOf("<script") > -1 || strcode.indexOf("</script") > -1) {
var s = strcode.indexOf("<script");
var s_e = strcode.indexOf(">", s);
var e = strcode.indexOf("</script", s);
var e_e = strcode.indexOf(">", e);

// Add to scripts array
scripts.push(strcode.substring(s_e+1, e));
// Strip from strcode
strcode = strcode.substring(0, s) + strcode.substring(e_e+1);
}

// Loop through every script collected and eval it
for(var i=0; i<scripts.length; i++) {
try {
var scr = scripts[i].trim();
eval(scr);
}
catch(ex) {
// do what you want here when a script fails
}
}
}
hitlar is offline   Reply With Quote
Reply

Bookmarks

Tags
javascript

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:34 PM.


Advertisement
Log in to turn off these ads.