Can any of you supply me with some code that will validate a set of radio buttons, show a confirm box, displaying the selected option to the user, and then proceed or stop based on what the user selects?
Thanks,
James
var Option Value = document.getElementById('ID').checked;
var Option Value = document.getElementById('ID').checked;
var Option Value = document.getElementById('ID').checked;
if(Option Value == false && Option Value == false && Option Value == false) {
msg += "You must select an option";
document.getElementById('ID').style.color="red";
return false;
}
var selected;
if(Option Value == true) {
selected = "Option Value";
}
if(Option Value == true) {
selected = "Option Value";
}
if(Option Value == true) {
selected = "Option Value";
}
if(Option Value == true || Option Value == true || Option Value == true) {
var confirmed = confirm("Are you sure you have selected the correct option?" + " You have selected: " + selected)
}
if(confirmed == false) {
result = false;
}
Hope it helps!
Related
I am using free-jqgrid 4.15.4 for showing the data. There i have a need to search date column with Date less but not empty filter, but it is not filtering correctly. In result it gives me date which are greater than searched date.
Below code is used for custom filter in date column:
customSortOperations: {
dlne: {
operand: "<!=''",
text: "Date less but not empty",
filter:function (options) {
var p = this.p, iCol = p.iColByName[options.cmName], cm = p.colModel[iCol],
newformat = cm.formatoptions != null && cm.formatoptions.newformat ?
cm.formatoptions.newformat :
$(this).jqGrid("getGridRes", "formatter.date.newformat"),
srcformat = cm.formatoptions != null && cm.formatoptions.srcformat ?
cm.formatoptions.srcformat :
$(this).jqGrid("getGridRes", "formatter.date.srcformat"),
fieldData = $.jgrid.parseDate.call(this, srcformat, options.item[options.cmName]),
searchValue = $.jgrid.parseDate.call(this, newformat, options.searchValue);
var retFData = convertD(fieldData), t = new Date(retFData);
if ((retFData.getFullYear() < searchValue.getFullYear()) && (retFData.getMonth() < searchValue.getMonth()) && (retFData.getDate() < searchValue.getDate())) {
return true
}
}
},
}
The convert function that I am using for converting string into date format, is written below:
function convertD(dateField) {
var date = new Date(dateField),
mnth = ("0" + (date.getMonth() + 1)).slice(-2),
day = ("0" + date.getDate()).slice(-2);
// year= (date.getFullYear())
var retVal = [day, mnth, date.getFullYear()].join("/");
return retVal;
}
I have taken the idea from here and made some changes but seems no avail. So requesting community to help on this.
The code of dlne could be fixed to for example the following:
dlne: {
operand: "<!=''",
text: "Date less but not empty",
filter: function (options) {
var p = this.p, iCol = p.iColByName[options.cmName], cm = p.colModel[iCol],
newformat = cm.formatoptions != null && cm.formatoptions.newformat ?
cm.formatoptions.newformat :
$(this).jqGrid("getGridRes", "formatter.date.newformat"),
srcformat = cm.formatoptions != null && cm.formatoptions.srcformat ?
cm.formatoptions.srcformat :
$(this).jqGrid("getGridRes", "formatter.date.srcformat"),
fieldData, searchValue;
// the exact condition to test for "empty" depend on the format of your data
if (!options.item[options.cmName]) {
return false; // ignore empty data
}
fieldData = $.jgrid.parseDate.call(this, srcformat, options.item[options.cmName]);
searchValue = $.jgrid.parseDate.call(this, newformat, options.searchValue);
return fieldData.getFullYear() < searchValue.getFullYear() ||
(fieldData.getFullYear() === searchValue.getFullYear() &&
fieldData.getMonth() < searchValue.getMonth()) ||
(fieldData.getFullYear() === searchValue.getFullYear() &&
fieldData.getMonth() === searchValue.getMonth() &&
fieldData.getDate() < searchValue.getDate());
}
}
see https://jsfiddle.net/OlegKi/51vfn4k9/11/
I want to get int parameter and save it to playerprefs and then get it and change it to string and display as string, but when I use ToString(); there is error: Cannot implicitly convert type string' toint' for a=b;
C# unity
public int a;
public string b;
{
car = GameObject.Find ("mastergame").GetComponent<master> ().carr;
if (car == 1) {
busted = GameObject.Find ("1").GetComponent<ruchauta1> ().busted;
gameover = GameObject.Find ("1").GetComponent<ruchauta1> ().gameover;
if (gameover == false && busted == false) {
scoree.text = "" + score;
}
if (gameover == true || busted == true) {
if(score>bestscore){
bestscore=score;
PlayerPrefs.SetInt("bestscore",bestscore);}
score=0;
PlayerPrefs.SetInt("score",score);
}
} else {
busted = GameObject.Find ("Audi").GetComponent<ruchauta> ().busted;
gameover = GameObject.Find ("Audi").GetComponent<ruchauta> ().gameover;
if (gameover == false && busted == false) {
scoree.text = "" + score;
}
if (gameover == true || busted == true) {
if(score>bestscore){
bestscore=score;
PlayerPrefs.SetInt("bestscore",bestscore);
a=PlayerPrefs.GetInt("bestscore",bestscore);}
score=0;
PlayerPrefs.SetInt("score",score);
}
}
a.ToString ();
a = b;
bestscoree.text = b;
}
void Score(){
car = GameObject.Find ("mastergame").GetComponent<master> ().carr;
if (car == 1) {
busted = GameObject.Find ("1").GetComponent<ruchauta1> ().busted;
gameover = GameObject.Find ("1").GetComponent<ruchauta1> ().gameover;
if (gameover == false && busted == false) {
score+=5;
PlayerPrefs.SetInt("score",score);
}
} else {
busted = GameObject.Find ("Audi").GetComponent<ruchauta> ().busted;
gameover = GameObject.Find ("Audi").GetComponent<ruchauta> ().gameover;
if (gameover == false && busted == false) {
score+=5;
PlayerPrefs.SetInt("score",score);
}
}
toString itself does not convert a's type, what you should do is:
String newString = a.toString()
after that, you can play with your newString.
ToString() creates a string representation of an object and returns that value. It does not (or should not) change the value/contents of the object it is operating on and it certainly does not change the type of the object. So the line with a.ToString() likely results in no change.
Since b is a string (based upon the error you gave) and presumably contains a string representation of an integer, if you want to set the value of a with the value of b, you must first convert b to an integer. I'm not sure what language this is but that is typically done with one of several methods. Some examples:
a = Convert.ToInt(b);
a = int.Parse(b);
a = Int32.Parse(b);
I have a problem with nicEdit link creation tool in IE and Firefox.
In general, I think the problem is related to the execCommand in IE and FireFox. It seems document doesn't get updated after execCommand executes.
This is an example of my problem with nicEdit create link command.
if(!this.ln) {
var tmp = 'javascript:nicTemp();';
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
// set the link text to the title or the url if there is no text selected
alert(this.ln);
if (this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
}
The code above is called when no text is selected, Chrome returns 'javascript:nicTemp()' for the alert(this.ln), while IE 8 and Firefox return 'undefined', so the next line after the alert encounters an error in IE and Firefox.
it seems findElem can't find the newly created link by nicCommand which in turn calls execCommand
I had similar problems when I try to find and modify tags created with execCommand, it seems the dom isn't updated to include them.
Am I right? How can I solve this problem? how can I force the document to be updated ....
please help
my trick for nicEdit, in the situation when no text is selected, is to paste the title given via the Add Link form into the document and select it, then the rest code works as it works when a text is selected.
I used the function pasteHtmlAtCaret described in the following link to paste the title
Insert html at caret in a contenteditable div
this.removePane();
var url = this.inputs.href.value;
var selected = getSelected();
var B= 'javascript:nicTemp()';
if (selected == '')
{
var B = url;
pasteHtmlAtCaret(this.inputs['title'].value || url,true);
}
if(!this.ln){
this.inputs.title.value;this.ne.nicCommand("createlink",B);
this.ln=this.findElm("A","href",B)
}
the getSelected is also a simple function as below
function getSelected()
{
if (document.selection)
return document.selection.createRange().text;
else
return window.getSelection();
}
Ahmad, just use this variation of the "submit" function to avoid the "insert/edit" problem with the link, it worked for me:
submit : function(e) {
var url = this.inputs['href'].value;
if(url == "http://" || url == "") {
alert("Introduce una URL valida para crear el Link.");
return false;
}
this.removePane();
if(!this.ln) {
//**************** YOUR CHANGE WITH A BIT OF VARIATION **************
var selected = this.getSelected();
var tmp = 'javascript:void(0)';
if (selected == '') {
tmp = url;
this.pasteHtmlAtCaret(this.inputs['title'].value || tmp, true);
}
//**************** END OF YOUR CHANGE WITH A BIT OF VARIATION **************
this.ne.nicCommand("createlink",tmp);
this.ln = this.findElm('A','href',tmp);
// set the link text to the title or the url if there is no text selected
if (this.ln.innerHTML == tmp) {
this.ln.innerHTML = this.inputs['title'].value || url;
};
}
if(this.ln) {
var oldTitle = this.ln.title;
this.ln.setAttributes({
href: this.inputs['href'].value,
title: this.inputs['title'].value,
target: '_blank'
});
// set the link text to the title or the url if the old text was the old title
if (this.ln.innerHTML == oldTitle) {
this.ln.innerHTML = this.inputs['title'].value || this.inputs['href'].value;
};
}
}
this.removePane();
var url = this.inputs['href'].value;
var selected = getSelected();
var isChrome = /Chrome/.test(navigator.userAgent) && /Google Inc/.test(navigator.vendor);
var tmp = "";
if(isChrome == true){
tmp=url;
}
else{tmp='javascript:nicTemp()'}
if (selected == '' && isChrome == false)
{
pasteHtmlAtCaret(this.inputs['title'].value || url,true);
}
if (!this.ln) {
//var tmp = this.inputs['title'].value == "" ? this.inputs['href'].value : this.inputs['title'].value;
this.ne.nicCommand("createlink", tmp);
this.ln = this.findElm('A', 'href', tmp);
}
function getSelected()
{
if (document.selection)
return document.selection.createRange().text;
else
return window.getSelection();
}
function pasteHtmlAtCaret(html) {
var sel, range;
if (window.getSelection) {
// IE9 and non-IE
sel = window.getSelection();
if (sel.getRangeAt && sel.rangeCount) {
range = sel.getRangeAt(0);
range.deleteContents();
// Range.createContextualFragment() would be useful here but is
// non-standard and not supported in all browsers (IE9, for one)
var el = document.createElement("div");
//create a link format
el.innerHTML = ''+ html +'';
var frag = document.createDocumentFragment(), node, lastNode;
while ( (node = el.firstChild) ) {
lastNode = frag.appendChild(node);
}
range.insertNode(frag);
// Preserve the selection
if (lastNode) {
range = range.cloneRange();
range.setStartAfter(lastNode);
range.collapse(true);
sel.removeAllRanges();
sel.addRange(range);
}
}
} else if (document.selection && document.selection.type != "Control") {
// IE < 9
document.selection.createRange().pasteHTML(html);
}
}
I have the requiredFieldValidator configured for one of my columns and it works as expected for existing rows. When I tab thru, or click to begin editing a new row, the validator does not fire when moving off the column. When move off the new row (with no data in the column) so that it commits, and then move back to the row, now the validator works...but ONLY if I put some data in the editor, and then delete it.
In other words, for new rows, the requiredFieldValidator does not do anything until I actually type something in the column. If I leave a column blank it never fires, defeating the purpose of it. Interestingly, the example they provide (http://mleibman.github.com/SlickGrid/examples/example3-editing.html) exhibits the same problem.
This checks for both values being "". I believe this should return true since a validator could be a "required" validator.
this.isValueChanged = function () {
// this needs to validate if both are empty since a validator might be a "required" validator
if ($input.val() == "" && defaultValue == "")
return true;
else
return (!($input.val() == "" && defaultValue == "")) && ($input.val() != defaultValue);
};
Preferred method would be to create a custom editor so you aren't mucking with the core library.
I concur, just encountered this behavior myself.
Here is the solution.
Change this.isValueChanged function contents to the following.
if(($input.val().length > 0) && ($input.val() != defaultValue))
return true;
else if(($input.val() == defaultValue)&&($input.val().length > 0))
return true;
else if(($input.val().length == 0) && ((undefined === defaultValue )||(defaultValue == "")))
return true;
else
return false;
For some reason defaultValue is not set during the first interraction, my guess if you initialize it to "" you would not need to check for undefined.
At any rate defaultValue holds the previous value of the cell, so when it is empty and it is the first cell being edited it is undefined, after that it is set to "" for all other empty cells.
The problem is this function needs to tell the grid that the value has changed in order for the cell editor to validate the input. In the provided implementation the expression always returns false because
$input.val() == "" evaluates to true and then the expression
!($input.val() == "" && defaultValue == null)) evaluates to false
This means defaultValue is continuously undefined.
Hope that makes sense and my code helps you out.
Had the same problem and I believe that ideally defaultValue should be set to undefined or null, when it wasn't initialized. So I've modified TextEditor in a following way:
function TextEditor(args) {
var $input;
var defaultValue;
var scope = this;
this.loadValue = function (item) {
defaultValue = item[args.column.field] || null;
$input.val(defaultValue);
$input[0].defaultValue = defaultValue;
$input.select();
};
this.isValueChanged = function () {
return $input.val() != defaultValue;
};
....
setting default defaultValue to null and simplifying isValueChanged.
There is an error in the first else if of Roman, the return is false. Otherwise, any change in cell returns true even if the value has not been changed.
I tried this and it works.
this.isValueChanged = function () {
var attuale = $input.val();
if((attuale.length > 0) && (attuale != defaultValue))
return true;
else if((attuale == defaultValue)&&(attuale.length > 0))
return false;
else if((attuale.length == 0) && ((undefined === defaultValue )||(defaultValue == "")))
return true;
else
return false;
};
How can I get the action when pressing tow keys at the same time, for example the action when pressing the up and right arrow at the same time.
This example uses JQuery but you should get the idea.
var down = false, right = false;
$(document).keydown(function(e) {
if(e.which == 40) down = true;
if(e.which == 39) right = true;
if(down && right) {
alert("Both keys pressed!");
down = right = false; // required 'cause alert stops 'keyups'
}
});
$(document).keyup(function(e) {
if(e.which == 40) down = false;
if(e.which == 39) right = false;
});