I have been using the code on the following link for quite sometime and it works great however I now have a need to require a picklist selection from the list of values. My current picklist works fine so it is the "require" capability that I need help with:
http://www.mredkj.com/tutorials/tableaddrow.html
Can someone point me in the right direction? Thanks.
CG
It was not my intention to answer my own question but in case someone else stumbles across this post in the future the solution was simple but took a bit of trial and error.
Simply add the following line to the // select cell section:
sel.required = true;
Also make sure the first option contains no text in between the second set of single quotes
sel.options[0] = new Option('-SELECT-', '');
Related
ok guys i have been working on these, this is like my main project and im pretty anxious about it, i have been practicing but im still a newbie. My code is like this and it does what it has to do, but im thinking that it could be improved to be better and more reusable, sorry to spam if i am, i already asked on the spanish version of the website with no satisfactory answer, im new to web developing and to this site, i always read the content on this site to answer my questions but for this time i didnt know how to exactly use the previous answers to fix my code, since im new to web developing and im trying to use jquery bit by bit. As i said my question is how can i create an array or a reg exp that does all the things this code does? without having to use .replace function all those times
i have tried urlencode function, and tried to iterate over arrays on jquery but i still dont know how to do it properly.
$( ".linkbestia" ).each(function() {
lnk = $(this).text();
enlace= $(this).attr("href");
espacios=lnk.replace(" ","_");
maslimpio=espacios.replace("'","%27");
muchomaslimpio=maslimpio.replace("(","%28");
muchomuchomaslimpio=maslimpio.replace(")","%29");
nuevoenlace=$(this).attr("href",enlace+muchomuchomaslimpio);
});
the actual output is for example codedquote'replaced space as i said it already does what it has to do, but i know it can be improved, i hope you guys help me since in my country these kind of questions cant be answered without a ton of difficulties
what it does right now:
what the user writes would look like this
the result would look like this
If I understand correctly you want to take href from below:
<a class="linknpc" href="url/in/url/url/The%27White_Mob">
and expected output is
The'White_Mob
after you get the href and lets say the var enlace looks like below.
var enlace = "url/in/url/url/The%27White_Mob"
Below will first use String split on '/' to get all sections from href and from resultant array get the last element by pop() and use decodeURIComponent to decode the encoded uri.
var ans = decodeURIComponent(enlace.split('/').pop())
ans would now have the value: The'White_Mob
note: If the href ends with '/' then you need to adjust above solution accordingly
i try to figure out a greasemonkey script that replaces every onmousedown on a site with an ondblclick. And i want it to constantly update, like every 1,5 Seconds, because the page refreshes using AJAX.
This is the script i came up with, but it doesn't seem to be working.
window.setInterval(document.body.innerHTML= document.body.innerHTML.replace('onmousedown','ondblclick');,1500);
The page it should work with is internal use only. But a good example would be the google search, where onmousedown is used for the links of the results to swap out the URL before you click it.
I also tried it without the semicolon after the document.body.innerHTML.replace.
I'm really new to JavaScript, but since i'm the only one in the company who can code, this one is stuck with me.
Any help would be appreciated.
Also, a small "side question"
Do i have to use #exclude, or is it enough to only use #include internal.companysite.tld* so it will only work on this site ?
A direct answer: you need to supply a function to setInterval - and it's best to set a variable so that you can later cancel it with clearInterval() if necessary.
function myF(){document.body....;}
var myIntv = setInterval(myF, 1500);
You could also do it using an anonymous function in one line as you're trying to do... do that this way:
var myIntv = setInterval(function(){document.body....;}, 1500);
I wouldn't suggest this as the solution to your problem. What it sounds like you want to do is manipulate the active DOM - not really change the UI. You likely need something like this:
var objs = document.getElementsBy__(); // ById/ByName/etc - depends on which ones you want
for (var i in objs){objs[i].ondblclick = objs[i].onmousedown;objs[i].onmousedown = undefined;} // just an example - but this should convey the basic idea
Even better, if you can use jQuery, then you'll be able to select the proper nodes more easily and manipulate the event handlers in a more manageable way:
$(".class.for.example").each(function(){this.ondblclick = this.onmousedown;this.onmousedown = undefined;}); // just an example - there are multiple ways to set and clear these
I'm just starting with jquery so maybe there's a really easy way to do this... but I would like to have a form with an input element, where a user can enter a filename, and then next to it a listbox or something similar where it displays the folder(s) in which files that match the input pattern are displayed.
Ideally I wouldnt start searching the folders until I have 3 characters or so as well since there may be a lot of folders.
The autocomplete that comes with jquery out of the box seems to have some of what, I wan't but being a jquery n00b I'm not sure if that is the right way to approach this or I should do something else.
Thanks!
Edit: Here's how I'm getting the folders:
var fso = new ActiveXObject("Scripting.FileSystemObject");
var folder = fso.GetFolder("top/level/directory");
// Iterate over folders
var subFlds = new Enumerator(folder.SubFolders);
var subFolder;
for (; !subFlds.atEnd() ; subFlds.moveNext()) {
subFolder = subFlds.item() + "";
if (subFolder.match(/* My input string goes here */)) {
break;
}
}
This isn't the exact way I would use this for the use case I describe, but it shows what I'm doing to go through folders.
It sounds like you need to get familiar with the jQuery UI Autocomplete documentation:
http://jqueryui.com/autocomplete/
I hate to just leave a RTFM response, but it is important for you to be familiar with the widget so that you can ask a more precise question.
The page allows you to view source and see exactly what their demo was using to operate. And the API documentation has a plethora of more examples.
If you have any specific questions on it, let us know.
This might be a noob question, but I have tried to find an answere here and on other sites and I have still not find the answere. At least not so that I understand enough to fix the problem.
This is used in a userscript for chrome.
I'm trying to select a date from a string. The string is the innerHTML from a tag that I have managed to select. The html structure, and also the string, is something like this: (the div is the selected tag so everything within is the content of the string)
<div id="the_selected_tag">
link
" 2011-02-18 23:02"
thing
</div>
If you have a solution that helps me select the date without this fuzz, it would also be great.
The javascript:
var pattern = /\"\s[\d\s:-]*\"/i;
var tag = document.querySelector('div.the_selected_tag');
var date_str = tag.innerHTML.match(pattern)[0]
When I use this script as ordinary javascript on a html document to test it, it works perfectly, but when I install it as a userscript in chrome, it doesn't find the pattern.
I can't figure out how to get around this problem.
Dump innerHTML into console. If it looks fine then start building regexp from more generic (/\d+/) to more specific ones and output everything into a console. There is a bunch of different quote characters in different encodings, many different types of dashes.
[\d\s:-]* is not a very good choice because it would match " 1", " ". I would rather write something as specific as possible:
/" \d{4}-\d{2}-\d{2} \d{2}:\d{2}"/
(Also document.querySelector('div.the_selected_tag') would return null on your sample but you probably wanted to write class instead of id)
It's much more likely that tag.innerHTML doesn't contain what you think it contains.
OK, beating my head against the Javascript/jQuery wall over here,
here is the code, which I simply can't get to work properly, any help is highly appreciated!
Especially this bugs me, changing row 60 from
c.gbForm.validator = c.dom.gbForm.validate(c.gbForm.validator); to
c.gbForm.validator = $("#gbForm").validate(c.gbForm.validator);
and row 61 from
c.dom.gbForm.unbind('submit').submit(c.gbForm.doAdd); to
$("#gbForm").unbind('submit').submit(c.gbForm.doAdd);
makes it kinda work, except then I get
this[0] is undefined error which I think is the jQuery validate plugin but I simply can't locate the exact spot at fault... So any hints/pointers to why the whole "var c" business isn't working and the same for the "this[0]" part would be awesome!
Thanks for any assistance!
John
Yes, here are a few things to look at
c.gbForm.validator = $("#gbForm").validate(c.gbForm.validator);
here you are referencing c.gbForm.validator before it is set (assuming this is the first assignment to c.gbForm.validator).
try this.
c.gbForm.validator = $("#gbForm");
c.gbForm.validator = $("#gbForm").validate(c.gbForm.validator);
also, why do you call c.doc.gbForm in one spot and just c.gbForm in another?
and as the comment says, validation should be as simple as $("gbForm").validate();