Click to See Complete Forum and Search --> : NEED HELP WITH "document.write"
Hello,
My name is michael and I'm building a new website and I have this javascript that when you hit the login button it will alert you that the password is wrong on a generated page. I was woundering if it is possible to use the "document.write" function to write wrong password to the login page in a certain spot without going to another page. If there is another way to do this please let me know by replying. I tryed other document.write things but it has to be a script of its own but i need it as a part of another script. here is the code:
if ((jim==bob)&&(jim==true)){
window.location=GrantedURL}
else {
suzy=suzy+1;
if (suzy){
window.document.write <-- This needs to write in a certain part of the same document
Please help me. :confused:
What exactly do you need? The syntax of the code you posted is so far off, I can't tell what it's supposed to be doing for you. :(
This is the entire code:
Where the checkpass and the document.write is i want it to write the text in the crrent page and in a certain area.
<script language="JavaScript1.2">
<!--
var GrantedURL = 'accept.html';
var DeniedURL = 'dontaccept.html';
var jim;
var gotoit;
suzy="0"
var capable;
var name = navigator.appName.toLowerCase();
var vers = parseFloat(navigator.appVersion);
if ((name.indexOf("netscape") >= 0 && vers >= 4) || (name.indexOf("microsoft") >= 0 && vers >= 4))
capable = true;
else
capable = false;
// Constants.
var FLDSEP; // Special characters used as separators in cookie data string.
var IDXSEP;
if (capable) {
FLDSEP = String.fromCharCode(1);
IDXSEP = String.fromCharCode(2);
}
function storeData(name, months, exclude) {
var f;
var expdate;
var list, include;
var i;
var fld;
var data;
if ((document.myForm.pass.value==document.myForm.pass1.value)&&(document.jim.hiduser.value=="")&&(document.myForm.pass.value!="")){
name="jim";
document.jim.hidpass.value=document.myForm.pass.value;
document.jim.hiduser.value=document.myForm.user.value;
document.jim.hidname.value=document.myForm.name.value;
document.jim.hidhint.value=document.myForm.hint.value;
if (!capable)
return true;
// Get the named form, skip processing if not found.
if (!(f = document.forms[name]))
return true;
// Initialize the data field.
// Set the expiration date.
if (months == "")
months = 12;
expdate = new Date();
expdate.setMonth(expdate.getMonth() + months);
// Build a list of field names for exclusion.
list = new Array();
if (exclude != "") {
i = 0;
while ((i = exclude.indexOf(",")) >= 1) {
list[list.length] = exclude.substr(0, i);
exclude = exclude.substr(i + 1)
}
list[list.length] = exclude;
}
// Run through the fields and add field name/value pairs to the data string.
data = FLDSEP;
for (i = 0; i < f.length; i++) {
fld = f.elements[i];
// Is field in exclusion list?
include = true;
for (j = 0; j < list.length; j++)
if (fld.name == list[j])
include = false;
if (include) {
// Checkboxes and radio buttons.
if ((fld.type == "checkbox" || fld.type == "radio") && fld.checked)
data += setData(fld.name, fld.value);
// Selection lists (single).
if (fld.type == "select-one")
if (fld.selectedIndex >= 0)
data += setData(fld.name, fld.options[fld.selectedIndex].value);
// Selection lists (multiple). Add a unique name/value pair for each selected item.
if (fld.type == "select-multiple")
for (j = 0; j < fld.options.length; j++)
if (fld.options[j].selected)
data += setData(fld.name + IDXSEP + j, fld.options[j].value);
// Text fields.
if (fld.type == "hidden" || fld.type == "password" || fld.type == "text" || fld.type == "textarea")
data += setData(fld.name, fld.value);
}
}
// Set the cookie.
deleteCookie(name);
setCookie(name, data, expdate);
alert("THE USER: "+document.jim.hiduser.value+" HAS BEEN ADDED TO THE KD7PYO MEMBER DATABASE.");
}
else if(document.myForm.pass.value==""||document.myForm.name.value==""||document.myForm.user.value==""||document.myForm.hint.value==""||document.myForm.pass1.value==""||document.myForm.email.value=="")
alert('PLEASE FILL IN ALL OF THE FORM TO BECOME A MEMBER.');
else alert("SORRY, EITHER YOUR PASSWORDS DO NOT MATCH OR YOU HAVE REGISTERED BEFORE.");
return true;
}
function retrieveData(name) {
var f;
var i, j;
var fld;
var s;
var data;
if (!capable)
return false;
// Get the named form, return if not found.
if (!(f = document.forms[name]))
return false;
// Get the cookie for this form.
data = getCookie(name);
if (data == "")
return false;
// Run through the fields and retrieve the values.
for (i = 0; i < f.elements.length; i++) {
fld = f.elements[i];
// Checkboxes and radio buttons.
if ((fld.type == "checkbox" || fld.type == "radio") && (s = getData(fld.name, data)) != null && fld.value == s)
fld.checked = true;
// Selection lists (single).
if (fld.type == "select-one" && (s = getData(fld.name, data)) != null)
for (j = 0; j < fld.options.length; j++)
if (fld.options[j].value == s)
fld.options[j].selected = true;
// Selection lists (multiple).
if (fld.type == "select-multiple")
for (j = 0; j < fld.options.length; j++)
if ((s = getData(fld.name + IDXSEP + j, data)) != null && fld.options[j].value == s)
fld.options[j].selected = true;
// Text fields.
if ((fld.type == "hidden" || fld.type == "password" || fld.type == "text" || fld.type == "textarea") && (s = getData(fld.name, data)) != null)
fld.value = s;
}
return true;
}
function setData(name, value) {
if (value != "")
return name + "=" + value + FLDSEP;
else
return "";
}
function getData(name, data) {
var i, j;
var s;
if (data == "")
return null;
s = FLDSEP + name + "=";
i = data.indexOf(s);
if (i >= 0) {
i += s.length;
j = data.indexOf(FLDSEP, i);
if (j >= 0)
return data.substr(i, j - i);
}
return null;
}
function setCookie (name, value, expires) {
document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=/";
}
function getCookie(name) {
var search;
search = name + "="
offset = document.cookie.indexOf(search)
if (offset != -1) {
offset += search.length ;
end = document.cookie.indexOf(";", offset) ;
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(offset, end));
}
else
return "";
}
function deleteCookie(name) {
var expdate = new Date();
expdate.setMonth(expdate.getMonth() - 1);
setCookie(name, "", expdate);
}
function checkpass(){
var bob;
if (document.jim.hiduser.value==document.jim.user.value)jim=true;
else jim=false;
if (document.jim.hidpass.value==document.jim.pass.value)bob=true;
else bob=false;
if ((jim==bob)&&(jim==true)){
window.location=GrantedURL}
else {
suzy=suzy+1;
if (suzy){
window.document.write('<html><head><title>!!! Members Area !!!</title></head><body><p align="center"><i><font face="Verdana" size="4" color="#FF0000">Incorrect Username/Password</font></i></p><p align="center"><b><i><font face="Verdana" size="2" color="#FF0000"><a href="javascript:history.back(1)">Go Back</a></font></i></b></p></body></html>')}
}
}
function getit(){
if (document.jim.hidhint.value==""){
alert("Sorry, '"+document.jim.hidname.value+"' but it appears you did not anser the password hint when you registered.");}
else if (document.jim.hidhint.value==document.jim.hint.value){
alert("Your password is '"+document.jim.hidpass.value+"' according to the records.");}
else {alert("Sorry, that is not the correct password hint.")}
}
//-->
</script>
First of all, do you realize that all anyone needs to do to break through JavaScript password protection is hit view->source? Not at all secure.
Are you looking for something like this?
document.write (document.jim.pass.value);
That should write the value of what they entered into pass. (I'm assumbing that pass is an input field in a form named jim)
O.k. what it does is there is a login form and if you put in the wrong username/password you will be sent an error message but the way it is right now is it will write the contents of "document.write" to a new generated page but I would like it to post the contents of "document.write" to the same page and in a certain spot on the page. So the idea is that you click login and without going to a new page you atomaticly see "Sorry wrong Username/Password" on the same page. What i'm getting at is you never leve the same page. Here I will post the part of the script where the "document.write" function is:
-------------------------------------------------------------------
}
function checkpass(){
var bob;
if (document.jim.hiduser.value==document.jim.user.value)jim=true;
else jim=false;
if (document.jim.hidpass.value==document.jim.pass.value)bob=true;
else bob=false;
if ((jim==bob)&&(jim==true)){
window.location=GrantedURL}
else {
suzy=suzy+1;
if (suzy){
window.document.write('Sorry Incorrect Username/Password')}
}
---------------------------------------------------------------------
Sorry for the confusion please try to help me. :D
Oh, I see what you mean. Unfortunatly, document.write automaticlly erases the previous content. What might work would be to add a <div> tag and change the innerHTML. Do you know how to do that?
No sorry i'm new at this so could you please show me it. I would also accept any other way to do what i want to do.
Try this...
}
function checkpass(){
var bob;
if (document.jim.hiduser.value==document.jim.user.value)jim=true;
else jim=false;
if (document.jim.hidpass.value==document.jim.pass.value)bob=true;
else bob=false;
if ((jim==bob)&&(jim==true)){
window.location=GrantedURL}
else {
suzy=suzy+1;
if (suzy){
document.getElementById('error').innerHTML = "Sorry Incorrect Username/Password";}
}and here's your div to be placed where you want the message
<div id="error"></div>
Thank you so much that worked really well sorry i misled you befor. thankyou.
Michael :D
Glad it's working...No problem about the misunderstanding...:D
Cheers...
Yeah when it writes "Sorry wrong Username/Password" it puts in a unwanted "return" like on the keyboard it like adds another line above the "Sorry wrong Username/Password" for some reson and i don't want it there please advise. :confused:
Please anybody help me anybody.
Originally posted by mjdimick
Please anybody help me anybody. Sorry it took so long to get back to you...I had to get some sleep. :D
Anyway, I think the problems is because we used a <div> try this instead, and let me know.
<span id="error"></span>
Thank you it works now. I have another question. The code i posted earlyer has (registration, login, getpass) functions i'm trying to split the code so i can put the registration on one page and when you register it sets the cookie and then you go to the next page and login by getting the cookie but right now its all in one code and i don't know how to split it up please help.
I'm taking ansers from anybody please help.:confused:
This code look way more complex than it should possibly need to be. Why don't you explain everything that you want, and I'll see if there would be a better option. Answer this question for me, though. Does your server have PHP? I don't like the idea of making it in javascript, because it isn't even a bit secure. Anyone can break a javascript password by looking at the source.
Sorry, i have no php,cgi,my-sql,ect. on my server but if you could reccomend a free server that will alow me to do this i would appriciate it alot.:D