i have a select tag, with some options
<select id="sel">
<option>text1</option>
<option>text2</option>
<option>text3</option>
<option>text4</option>
</select>
i want to delete all options except second, i.e i want to get
<select id="sel">
<option>text2</option>
</select>
i think it must looks something like this
document.getElementById('sel').options.length= 0;
but it deletes all list, so could you help me.
thanks
$.post("/diabetes/ropimages/getcount.php",{pid:$("#patient_id").val()} ,function(data1){
//alert(data1);
var count = data1;
var pid = $("#patient_id").val();
var rid;
for( var i = 1 ; i <= count ; i++)
{
var link ='<img src="/diabetes/ropimages/thumbpicdisplay.php?pid=+pid+&rid=1" />';
$("#content1").empty().html(link);
}
});
i am trying to pass pid value in url ..but its taking directly as +pid+ as value ..how do i give it the value of pid.
and how do i print 3 images in a div ? like the one in code
Here is the code I am working with:
$(document).ready(function () {
var TemplateEditor = function () {
var GroupClassName = 'group';
var SelectedGroup = 0;
var BindClicks = function () {
$('.CriteriaSelections').unbind('click').click(function (event) {
event.preventDefault();
if (fnIsTheClickedBoxaGroup($(this))) {
TemplateEditor.GroupClicked();
}
else {
TemplateEditor.CriteriaClicked($(this), SelectedGroup);
}
});
$('.groupselected').unbind('click').click(function (event) {
event.preventDefault();
SelectedGroup = $(this).attr('group-'.length);
TemplateEditor.SelectGroup(SelectedGroup);
});
}
var fnGetGroupID = function (Obj) {
if (fnIsTheClickedBoxaGroup(Obj) == true) {
return null;
}
else {
//Get parent which is the group
var ObjParent = Obj.parent();
var GID = ObjParent.attr('id').substr('group-'.length);
return GID;
}
}
var fnIsTheClickedBoxaGroup = function (Obj) {
var GetClass = Obj.attr('class');
if (GetClass == GroupClassName) {
return true;
}
else {
return false;
}
}
return {
Init: function () {
BindClicks();
},
CriteriaClicked: function (Obj, GroupID) {
$('<div>').attr({ id: '' }).addClass('selection').text(Obj).appendTo('#group-' + GroupID);
},
GroupClicked: function () {
},
SelectGroupClicked: function () {
},
UpdateTargetPanel: function () {
}
};
} ();
TemplateEditor.Init();
});
I am trying to access this variable:
GroupClassName
This variable is inside this function
var fnIsTheClickedBoxaGroup = function (Obj) {
var GetClass = Obj.attr('class');
if (GetClass == GroupClassName) {
return true;
}
else {
return false;
}
}
When I run the program it says GroupClassName is undefined. Am I missing something here?
I am coding my website, and a friend of mine was helping me. This code does not work on IE 10 (Windows 7). I even tried the legacy modes and to no avail. Upon clicking on "services" for example, this code would work on FF or Chrome. But, not on IE. Can someone help me fix this code so it would also work on IE?
$('#services-fr-2').on('click',function(){
$( ".clientsFr" ).hide();
$('.servicesFr').fadeToggle();
$('#green-pouch-fr').animate({
'top':'450px'//,
//'height':'450'
})
Here is the the function and the globals:
$note_instance = Array();
$note_count = 0;
function create(text){
count = $note_count++;
time = 5000;
$note_instance[count] = $notifications.notify("create", text);
setTimeout(function(){ $note_instance[count].close() }, time);
}
The function simply opens a notification, a sets a timeout to close it in 5 seconds.
so if i call this
create("Good Note 1");
create("Good Note 2");
create("Good Note 3");
Ecah note should close 5 seconds from their creation, however always and only the last note closes, in this case "Good Note 3".
Each note object has its own entry in the the $note_instance global array so the timeouts should no be overwriting themselves.
What am i missing here folks? Thanks in advance
hi there,
i have this website, by clicking on certain link on the website an iframe will be created within the same window.
my question, just wondering how to access this iframe?
i tried document.getElementById() return null
tried window.frames not there
Thanks
var radiobox = document.getElementById('<%=rdoRiskAccepted.ClientID%>');
alert(radiobox[0].checked);
I am getting undefined as a alert. what am I doing wrong.
I have a function to return points along a line and my return comes back with two decimal points...? For example, a return of my variable px will be something like -88.4029.032940598.
vx is the x vector and mult is the distance of the line plus distance to calculate the point.
Here is the operation that is returning these values:
var mult = parseFloat(mag + theUnit);
var px = coord_one.x_point + (vx * mult);
console.log(px);
Never have seen this before- I appreciate any and all help!
I want to get the object of this code ,
<input class="radio"
id="conversation_sub_kind_id_208"
name="conversation[sub_kind_id]"
onclick="set_department_name('department_name208')"
type="radio"
value="208" />
I want to use jQuery Framework to get the object, like the document.getElementbyTagName("conv..."); what should i do in here?
Thank you, and best regards!
I have a javasrcript variable
var hash = {
'.bmp' : 1,
'.gif' : 1,
'.jpeg' : 1,
'.jpg' : 1,
'.png' : 1,
'.tif' : 1,
'.tiff' : 1,
};
I want to display the values (.bmp, .gif, .jpeg, .jpg, .png, .tif, .tiff) of this "hash" object in my alert message. How can I do this? Please help.
Hi,
Would like to write a script to detect the file size of the target of a link on a web page.
Right now I have a function that finds all links to PDF files (i.e. the href ends with '.pdf') and appends the string '[pdf]' to the innerText. I would like to extend it so that I can also append some text advising the user that the target is a large file (e.g. greater than 1MB).
Thanks
My codes is like
pattern = 'arrayname[1]'; // fetch from dom, make literal here just for example
reg = new RegExp(RegExp.quote(pattern), 'g');
mystring.replace(reg, 'arrayname[2]');
But it just cannot get running with error message says: "RegExp.quote is not a function", am i missing something simple?
I'm wondering about the .childNodes property, I have the code below, and for some reason I get 18 children, while 6 are HTMLInputElements as expected, and the rest are undefined. What is this about? Is there an efficient way to iterate over the input elements?
<html>
<head>
<script>
window.onload = function(e){
form = document.getElementById('myForm');
alert(form.childNodes.length);
for(i=0; i<form.childNodes.length; i++){
alert(form[i]);
}
}
</script>
</head>
<body>
<form id='myForm' action="haha" method="post">
Name: <input type="text" id="fnameAdd" name="name" /><br />
Phone1: <input type="text" id="phone1Add" name="phone1" /><br />
Phone2: <input type="text" id="phone2Add" name="phone2" /><br />
E-Mail: <input type="text" id="emailAdd" name="email" /><br />
Address: <input type="text" id="addressAdd" name="address" /><br />
<input type="submit" value="Save" />
</body>
</html>
my code-
<?php
session_start();
$_SESSION['errors']="failed";
?>
<head>
function myfunc()
{
alert(<?php echo $_SESSION['errors']; ?>);
}
</head>
<body onload="myfunc();">
but alert msg is not popping up.
I need to replace a substring from some string. I've already created corrected code for doing it. But I amn't sure is it best way. Please, see code below:
var str = 'test ruby,ruby on rails,ruby,'
var substr = 'ruby';
var reg = new RegExp(',' + substr + ',|^' + substr + ',', 'gi');
str.replace(reg, ','); //returns "test ruby,ruby on rails,"
function my_func(a, b){
if(typeof(a) !== 'undefined'){
// do stuff
}
return b;
}
How can I call this function will only the second argument? In other words, I want a to be undefined.
I suppose there should be a way to set a cookie to be accessible from the entire domain nevermind from which directory you are setting the cookie.
Say in mypage.com/blue/index.php y set the cookie "colour=blue;" this way:
document.cookie = "colour" + "=" + "blue"
+ "; expires=" + expireDate.toGMTString()
+ "; path=/";
Using this code, the cookie retrieval function in mypage.com/home.php can't access the content of the cookie.
If it was just from first level directories that the cookie needs to be set, we would be ok by doing path=../ instead of path=/
But how do you go about writing generic code that sets a cookie that is accessible from any page in that domain not minding how deep in the file structure is the page the cookie is being set from?
Hi,
I am wondering if anyone knows a java script library that would add a "select" type of functionality as seen in excel/google docs where you can click and select several different parts of a row and/or column. I am looking at adding this functionality to my web application. Does anyone know where of library's preferably in java script that will be able to add this.
Thanks in advance
Is there an easy way to loop through all td tags and change them to th? (etc).
My current approach would be to wrap them with the th and then remove the td, but then I lose other properties etc.
I have an html form that has the following structure:
<input type="text" name="title" />
<input type="text" name="persons[0].name" />
<input type="text" name="persons[0].color" />
<input type="text" name="persons[1].name" />
<input type="text" name="persons[1].color" />
I would like to serialize this into the following json:
{
"title":"titlecontent",
"persons":[
{
"name":"person0name",
"color":"red"
},
{
"name":"person1name",
"color":"blue"
}
]
}
Notice that the number of persons can vary from case to case.
The structure of the html form can change, but the structure of the submitted json can't.
How is this done the easiest?
Trying to fire off (trigger) a click event. Its easy to do in jQuery, but cannot figure out how to set the coordinates of the event and send them along.
Essentially, I need to trigger a click at a specific location (which is calculated prior to the trigger() call).
Any way to do this (in jQuery or otherwise)?
Thanks -
I'm building a webapp for Android smartphones that runs with the OS internet browser. the main interface is to input datas. the data is added to a queue (android 1.5: gears, android 2.x: html5). Each 5 minutes (using setTimeout), the script looks if an internet connection is active, and if so, sends all the queue to the server.
If the phone is plugged on the wall and the webpage is ontop, the timeout works. if the browser is minimized or another application runs on top of it, the timeout doesn't work. if the phone is in sleep mode it doesn't work either.
can only native apps runs in background?
I've got a list of links that point to images, and a js function that takes a URL (of an image) and puts that image on the page when the function is called.
I was originally adding an inline onlick="showPic(this.getAttribute('href'))" to each a, but I want to separate out the inline js. Here's my func for adding an onclick to each a tag when the page loads:
function prepareLinks(){
var links = document.getElementsByTagName('a');
for(var i=0; i<links.length; i++){
var thisLink = links[i];
var source = thisLink.getAttribute('href');
if(thisLink.getAttribute('class') == 'imgLink'){
thisLink.onclick = function(){
showPic(source);
return false;
}
}
}
}
function showPic(source){
var placeholder = document.getElementById('placeholder');
placeholder.setAttribute('src',source);
}
window.onload = prepareLinks();
...but every time showPic is called, the source var is the href of the last image. How can I make each link have the correct onclick?
Do you know if toFixed is a localized function?
I mean will this:
var n = 100.67287;
alert(n.toFixed(2));
show "100.67" on english US OS/browsers
and "100,67" (with comma) on Italian OS/browsers (Italian or any other local system that uses comma as decimal separator).
Thanks!