Jump to content
Larry Ullman's Book Forums

Help With "Onfocus" Issue - Don'T See It In The Book.


Recommended Posts

I have these two lines that are causing me issues. I believe it is a JavaScript issue, but not sure. I'm using Aptana to view my pages and edit them. I keep getting an error that reads unknown attribute "onfocus", but I can't find anything in my new book...I'm new to js so any help would be great. Here are the lines of code that is killing me:

 

<label id="hideState"><input type="password" id="ppp_password" name="ppp_password" size="30" onfocus="onInputKeyUp(2);" /></label>

<label id="showState"><input type="text" id="ppp_password_show" name="ppp_password_show" size="30" onfocus="onInputKeyUp(2);" /></label>

 

These are the lines that have the error indicator.

 

What is happening when this is ran in simulation is that the 1st input area is disappearing and it is pushing the second input area one line down and to the left. Below is the JavaScript that is associated with the above lines of code, I think. Also there is other JavaScript code that doesn't apply to my lines, but I'm not sure which ones effect my lines and which don't. Again, I'm new to JavaScript. Thank you, Carol Beaman

 

 

<script type="text/javascript">

var availInfNames = '<%ejGetOther(availInfNames, all)%>';

var wanInfNames = '<%ejGetOther(wanInterfaces, all)%>';

var layer2Info = '<%ejGetOther(layer2Info, all)%>';

var traffictype = '<%ejGetOther(trafficType, 0)%>';

var l2info = layer2Info.split('|');

var wanInf = "";

var redirect = "quick.html";

var infname = 'atm0/(0_0_35)';

var ppp_pwd = '';

var wantype = '';

var layer2Infoptm = '<%ejGetOther(layer2Info, PTM)%>';

var l2infoptm = layer2Infoptm.split('|');

var key = '<%ejGetOther(encrypt_key, 0)%>';

vId = l2infoptm[8];

vPr = l2infoptm[9];

 

function onInputKeyUp(index) {

var form = document.forms[0];

 

if (index == 1) {

document.getElementById("hideState").style.display = "block";

document.getElementById("showState").style.display = "none";

} else {

document.getElementById("hideState").style.display = "none";

document.getElementById("showState").style.display = "block";

form.ppp_password_show.focus();

}

}

 

function do_load() {

var form = document.forms[0];

var dns_type = "";

if (wanInfNames != '') {

var wanNameTypes = wanInfNames.split('|');

var nameType = wanNameTypes[0].split(':');

var wanEntryInfo = nameType[4].split(';');

wanInf = nameType[1];

infname = nameType[0];

wantype = nameType[3];

if (wantype == "PPPoE") {

var ppp_usr_name = decodeUrl(wanEntryInfo[0]);

var idx = ppp_usr_name.indexOf('@');

 

if (idx == -1) {

form.ppp_username.value = ppp_usr_name;

form.ppp_domain.selectedIndex = 1;

} else {

var domain_name = ppp_usr_name.substring(idx);

 

if (domain_name == "@qwest.net") {

form.ppp_domain.selectedIndex = 0;

form.ppp_username.value = ppp_usr_name.substring(0, idx);

}

/* else

if (domain_name == "@qwest.com")

{

form.ppp_domain.selectedIndex=0;

form.ppp_username.value = ppp_usr_name;

}

*/

/* else if (domain_name=="@msndsl.net")

{

form.ppp_domain.selectedIndex=1;

form.ppp_username.value =ppp_usr_name.substring(0,idx);

}

*/

else {

form.ppp_username.value = ppp_usr_name;

form.ppp_domain.selectedIndex = 1;

}

}

ppp_pwd = wanEntryInfo[1];

if (wanEntryInfo[1] == "")

pass_len = 0;

else

pass_len = 100;

 

if (pass_len > 0) {

form.ppp_password.value = "********";

form.ppp_password_show.value = "";

} else {

form.ppp_password.value = "";

form.ppp_password_show.value = "";

}

}

var wanEntryName = infname;

var index = wanEntryName.indexOf("(");

 

if (index != -1) {

/* dsl wan */

var index2 = wanEntryName.indexOf(")");

sid = wanEntryName.substring(index + 1, index2);

} else

sid = infname;

 

} else {

var names = availInfNames.split('|');

var regexp = /^ptm/;

 

if (traffictype == 'PTM') {

regexp = /^ptm/;

} else if (traffictype == 'ATM') {

regexp = /^atm|^pppoa|^ipoa/;

} else {

regexp = /^ptm/;

traffictype = "PTM";

//return;

}

 

for (var i = 0; i < names.length; i++) {

if (names.search(regexp) != -1) {

infname = names;

break;

}

}

}

 

onInputKeyUp(1);

 

}

 

function On_Apply() {

var lochead = 'quick.cmd?';

var loc = '';

var msg = '';

var rege = /[^A-Za-z0-9@\-._!\"\#$%\&\'\(\)\*+,\/:\;\<\>=?\`{\|}\~\[\\\]^\ ]/;

var mat;

with(document.forms[0] ) {

if (wanInf == '')

loc += 'serviceId=0';

else/* editing */

loc += 'serviceId=1&wanInf=' + wanInf;

loc += '&wanL2IfName=' + infname;

 

var len = ppp_username.value.length;

mat = ppp_username.value.match(rege);

if (len > 246) {

msg = 'The length of user name (' + len + ') is too long [0-246].';

// alert(msg);

pop_up(msg, 0);

return;

} else if (mat) {

if (mat.length > 0) {

// alert("The username is invalid. Please enter a valid one.");

tips = "The username is invalid. Please enter a valid one.";

pop_up(tips, 0);

return;

}

} else {

var realmIdx = ppp_username.value.indexOf('@');

var realmString = '';

if (realmIdx != -1) {

realmString = ppp_username.value.substring(realmIdx + 1, len);

if (realmString.indexOf('@') != -1) {

msg = 'Invalid username format, please input valid entry.';

// alert(msg);

pop_up(msg, 0);

return;

}

}

 

//if ((encodeUrl(ppp_username.value)).indexOf('@') != -1)

if (realmIdx != -1) {

if (ppp_username.value == "connect@qwest.com")

loc += '&pppUserName=' + newEncodeUrl(ppp_username.value);

else if (ppp_domain.selectedIndex == 0) {

realmString = ppp_username.value.substring(0, realmIdx);

loc += '&pppUserName=' + newEncodeUrl(realmString + ppp_domain.value);

} else if (ppp_domain.selectedIndex == 1) {

loc += '&pppUserName=' + newEncodeUrl(ppp_username.value);

}

} else {

loc += '&pppUserName=' + newEncodeUrl(ppp_username.value + ppp_domain.value);

}

}

 

// password was handed as below:

ppp_password.value = ppp_password_show.value;

len = ppp_password.value.length;

if (len > 32) {

msg = 'The length of password (' + len + ') is too long [0-32].';

// alert(msg);

pop_up(msg, 0);

return;

} else if (ppp_password.value == "********") {

loc += '&pppPassword=' + newEncodeUrl(ppp_pwd);

} else {

loc += '&pppPassword=' + newEncodeUrl(ppp_password.value);

}

loc += '&ntwkPrtcl=0';

if (traffictype == "PTM") {

loc += '&vlanMuxId=' + vId;

loc += '&vlanMuxPr=' + vPr;

}

 

}

document.getElementById('apply_btn').disabled = true;

loc += '&redirect=' + redirect;

loc += '&needthankyou=quick.html';

loc = encrypt_query(loc, key);

lochead += loc;

//var code = 'location="' + lochead + '"';

//eval(code);

postSubmit(lochead);

}

 

function MM_preloadImages() {//v3.0

var d = document;

if (d.images) {

if (!d.MM_p) {

d.MM_p = new Array();

}

var i, j = d.MM_p.length, a = MM_preloadImages.arguments;

for ( i = 0; i < a.length; i++) {

if (a.indexOf("#") != 0) {

d.MM_p[j] = new Image;

d.MM_p[j++].src = a;

}

}

}

}

 

function MM_swapImgRestore() {//v3.0

var i, x, a = document.MM_sr;

for ( i = 0; a && i < a.length && ( x = a) && x.oSrc; i++) {

x.src = x.oSrc;

}

}

 

function MM_findObj(n, d) {//v4.01

var p, i, x;

if (!d) {

d = document;

}

if (( p = n.indexOf("?")) > 0 && parent.frames.length) {

d = parent.frames[n.substring(p + 1)].document;

n = n.substring(0, p);

}

if (!( x = d[n]) && d.all) {

x = d.all[n];

}

for ( i = 0; !x && i < d.forms.length; i++) {

x = d.forms[n];

}

for ( i = 0; !x && d.layers && i < d.layers.length; i++) {

x = MM_findObj(n, d.layers.document);

}

if (!x && d.getElementById) {

x = d.getElementById(n);

}

return x;

}

 

function MM_swapImage() {//v3.0

var i, j = 0, x, a = MM_swapImage.arguments;

document.MM_sr = new Array;

for ( i = 0; i < (a.length - 2); i += 3) {

if (( x = MM_findObj(a)) != null) {

document.MM_sr[j++] = x;

if (!x.oSrc) {

x.oSrc = x.src;

}

x.src = a[i + 2];

}

}

}

 

</script>

Link to comment
Share on other sites

The focus event is covered in the book, specifically in the chapter on events. This is probably not the answer you want to hear, but there are a lot of problems with that JavaScript code you have. My recommendation would be to start learning JavaScript and see how to do this properly, from the ground up.

Link to comment
Share on other sites

After looking at your code thoroughly, I agree with Larry.

We don't want to scare you away though, Carol.

 

Perhaps if you'd be willing to explain to us exactly what you want to do, we could better help you with specific details and code snippets.

Thanks (and welcome to the forums!).

Link to comment
Share on other sites

 Share

×
×
  • Create New...