...

View Full Version : submit() only works, sometimes



aaon
09-27-2011, 05:20 PM
I have a userscript that helps me move things around on a vB based forum that I moderate. I am using the following to quickly select and submit my selection, however, when it hits the document.vbform.submit(); part of the code the pages just sits there. It does work if the forum ID's I have in place don't line up with any of the forum ID's on the forums but it just will ooad the page and say no such forum exists. So I know submit(); can work.....



// INJECT FUNCTION TO PAGE FOR LATER USE
window.InjectFunction = function(reg) {
if (reg == "na") {
var theScr = "" +
"function des(id) {" +
"\nvar destination = document.getElementsByName('destforumid')[0];" +
"\nvar radio = document.getElementsByName('redirect');" +
"\nif (id == '39') {" +
"\nradio[0].checked = true;" +
"\n}" +
"\nelse {" +
"\nradio[2].checked = true;" +
"\n}" +
"\nfor ( var i = 0; i < destination.options.length; i++ ) {" +
"\nif ( destination.options[i].value == id ) {" +
"\ndestination.options[i].selected = true;" +
"\nreturn;" +
"\n}" +
"\n}" +
"\ndocument.vbform.submit();" +
"\n}"
}
var scrTag = document.createElement("script")
var scrHead = document.getElementsByTagName("head")[0];
scrTag.setAttribute('type', 'text/javascript');
scrTag.appendChild(document.createTextNode(theScr));
scrHead.appendChild(scrTag);
}
// ADD MENU THAT WILL PASS FORUM IDs AND CALL INJECTED FORUMS
window.NewMenu = function(reg) {
var divTag = document.createElement("div");
divTag.id = "div1";
divTag.setAttribute("align","left");
divTag.style.margin = "0px auto";
divTag.style.backgroundColor = "#f5edc3";
divTag.style.position = "fixed";
divTag.style.bottom = "0px";
divTag.style.left = "50%";
divTag.style.width = "196px";
divTag.style.marginLeft = "-98px";
divTag.style.height = "auto";
divTag.className ="dynamicDiv";
divTag.zIndex = "1000";
document.body.appendChild(divTag);
if (reg == "na") {
var dBody = '<div class="newmenu" onClick="des(\'2\');">SELECTION 2 </div>' +
'\n<div class="newmenu2" onClick="des(\'43\');">SELECTION 2 </div>' +
'\n<div class="newmenu" onClick="des(\'41\');">SELECTION 3 </div>' +
'\n<div class="newmenu2" onClick="des(\'15\');">SELECTION 4 </div>' +
'\n<div class="newmenu" onClick="des(\'4\');">SELECTION 5 </div>' +
'\n<div class="newmenu2" onClick="des(\'3\');">SELECTION 6 </div>' +
'\n<div class="newmenu" onClick="des(\'19\');">SELECTION 7 </div>' +
'\n<div class="newmenu2" onClick="des(\'39\');">TRASH </div>' ;
}
divTag.innerHTML = dBody;
}


var location = window.location.toString();

var region = location.substring((location.indexOf("//") + 2), location.indexOf("."));
var view = location.substring((location.indexOf("board/") + 6), location.indexOf(".php"));

if (view == "forumdisplay") {
HideMoveClose();
ColorThreads();
} else if (view == "postings") {
var destination = document.getElementsByName('destforumid')[0];
if ( destination != null) {
ChangeRedirect();
InjectFunction(region);
NewMenu(region);
ApplyCSS();

window.scrollTo(0,document.body.scrollHeight);
}
} else if (view == "search") {
ColorThreads();
} else {
//alert();
}

Please note I have edited out a large portion of this code to make the search for the problem a little easier and the code that remains is relevant to the issue. As you can see there are other functions and blah blah but those all work correctly. On the if statements I removed the else if's and else since they are basically just the same thing as the if portion just with a different region code. I have wrapped this whole deal in try {} catch() {} but no errors get thrown.
Please any thoughts?

aaon
09-28-2011, 03:17 PM
Bump from page 3. I don't even need the specifics why this doesn't work, a suggesting pointing me in the right direction will help too.

aaon
09-30-2011, 02:56 PM
Another 3rd page bump. Please anyone? If this thread gets to page 3 again, I will consider this a lost cause.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum