How do I alert as FF and not 255 with this:
var myHex1 = 0xff;
alert(myHex1);//alerts 255
var myVar = 255;
var myHex2 = myVar.toString(16);
alert(myHex2);//also alerts 255 and not FF
If I attach a context menu to a td, it fires okay for text in the TD, but if I add a div to the TD, the context menu will not fire when right clicking on the div. How can I make the context menu fire when anything, data or divs, are right clicked in the td?
I have this form with a button that allows you to add fields to the form.
<form id="contact" name="contactForm" action="newPoll.php" method="post">
<fieldset>
<legend>Create A Poll</legend><br style="clear:both;">
<ol>
<li><lable for=pollTitle>Poll Title:</lable><input name="pollTitle" id="pollTitle" type="text" size="66" /> </li>
<li><lable for=question>1st Question:</lable><input name="question" id="question" type="text" size="66" /> </li>
<li><lable for=answerType>Constrained:</lable><input name="answerType" id="answerType" value="Constrained" type="radio" size="66" /><span style="margin: 0 0 0 40px;">
Unconstrained: <input style="margin-right: 30px;" name="answerType" value="Unconstrained" id="question" type="radio" size="66" /></span>(Allow multiple answers) </li>
<li><lable for=answer1>Answer:</lable><input name="answer1" id="answer1" type="text" size="66" /> </li>
<li><lable for=answer2>Answer:</lable><input name="answer2" id="answer2" type="text" size="66" /> </li>
<li><lable for=answer3>Answer:</lable><input name="answer3" id="answer3" type="text" size="66" /> </li>
<li><lable for=answer4>Answer:</lable><input name="answer4" id="answer4" type="text" size="66" /> </li>
</ol><br />
</fieldset>
<input type="button" value="Add More Answers" name="addAnswer" onClick="generateRow()" /><input type="submit" name="submit" value="Add Another Question">
</form>
And here is generateRow():
var count = 5;
function generateRow() {
var d=document.getElementById("contact");
var b = document.getElementById("answer4");
var c =b.name.charAt(0);
var f = b.name.substr(0, 6);
var y = f + count;
count = count + 1;
d.innerHTML+='<li><lable for=' + y + '>Answer:</lable><input name="' + y + '" id="' + y + '" type="text" size="66"/> </li>';
}
The issue is whenever a new row is added, it erases any input that may have been typed in any of the un-original (added) text fields. It should leave the data in form elements
Hi all, one month ago I've been interviewed by some google PTO members.
One of the questions was:
Invert a string recursively in js and explain the running time by big O notation
this was my solution:
function invert(s){
return (s.length > 1) ? s.charAt(s.length-1)+invert(s.substring(0,s.length-1)) : s;
}
Pretty simple, I think.
And, about the big-o notation, I quickly answered O(n) as the running time depends linearly on the input. - Silence - and then, he asked me, what are the differences in terms of running time if you implement it by iteration?
I replied that sometimes the compiler "translate" the recursion into iteration (some programming language course memories) so there are no differences about iteration and recursion in this case. Btw since I had no feedback about this particular question, and the interviewer didn't answer "ok" or "nope", I'd like to know if you maybe agree with me or if you can explain me whether there could be differences about the 2 kind of implementations.
Thanks a lot and Regards!
Hi all,
I can't seem to figure out what is wrong with my code. Maybe it would be simpler to just compare date and not time. Not sure how to do this either and I searched but couldn't find my exact problem.
BTW, when I display the two dates in an alert, they show as exactly the same.
My code:
window.addEvent('domready', function() {
var now = new Date();
var input = $('datum').getValue();
var dateArray = input.split('/');
var userMonth = parseInt(dateArray[1])-1;
var userDate = new Date();
userDate.setFullYear(dateArray[2], userMonth, dateArray[0], now.getHours(), now.getMinutes(), now.getSeconds(), now.getMilliseconds());
if(userDate > now)
{
alert(now+'\n'+userDate);
}
});
Perhaps there is a simpler way to compare dates and not including the time.
Hope someone has an answer...
Thanks!
So this function works fine in geko and webkit browsers, but not IE7. I've busted my brain trying to spot the issue. Anything stick out for you?
Basic premise is you pass in a data object (in this case a response from jQuery's $.getJSON) we check for a response code, set the notification's class, append a layer and show it to the user. Then reverse the process after a time limit.
function userNotice(data){
// change class based on error code returned
var myClass = '';
if(data.code == 200){ myClass='success'; }
else if(data.code == 400){ myClass='error'; }
else{ myClass='notice'; }
// create message html, add to DOM, FadeIn
var myNotice = '<div id="notice" class="ajaxMsg '+myClass+'">'+data.msg+'</div>';
$("body").append(myNotice);
$("#notice").fadeIn('fast');
// fadeout and remove from DOM after delay
var t = setTimeout(function(){ $("#notice").fadeOut('slow',function(){ $(this).remove(); }); },5000);
}
I need to make a little JS app to scroll automatically through a list of URLs. I've chosen to have the functionality in a pop-up, for various reasons.
The syntax to change the opening window's URL is:
window.opener.location.href = "http://www.example.com";
This works fine with one URL, but if two statements are called, only one is executed. I experimented with an alert statement between two of the above statements, and the alert event made the second statement function properly:
window.opener.location.href = "http://www.example1.com";
alert("hello world");
window.opener.location.href = "http://www.example2.com";
Question is: does anyone know how to get the first and second window.opener statements to work, without the intervening alert();? Also, how can I add a pause between the two statements, so that the second executes a couple of seconds after the first?
Thanks so much!
Hi,
I am developing the application in asp.net mvc with c#. I want the functionality that , a div will popup, so that i can facilate to use to upload the image file from his browser to server , in application domains file system. as usual. This question may be repeat , but i expect something more like
how to build this scenario, and what are the security issues may come?
and what care have to take while coding in the security perspective ?
Hi All,
I need to identify all html elements on a page in a browser agnostic fashion. What I am basically doing is using mouse events to record clicks on the page. I need to record which element was clicked. So I add a mouse down listener to the document.body element. And on mouse down I get the element under the mouse. Lets say its a div. I then use the index of that div inside the document.getElementsByTagName('*') nodelist and the nodeName ('div') to identify that div. A sample element id would be div45 which means its a div and its the 45th element in the '*' nodelist.
This is all fine and good until I use IE which gives me different indexes. So div45 in FireFox may be div47 in IE.
Anyone have any ideas? I just need the id of all elements on the page to be the same in any browser, perhaps indexing is not good enough but I really don't have any more ideas.
Thanks
Guido
Is there a simple way to convert a string to proper case? E.g. john smith becomes John Smith. I'm not looking for something complicated like John Resig's solution, just (hopefully) some kind of one- or two-liner.
Hi, I want to scrape data from www.marktplaats.nl . I want to analyze the scraped description, price, date and views in Excel/Access.
I tried to scrape data with Ruby (nokogiri, scrapi) but nothing worked. (on other sites it worked well) The main problem is that for example selectorgadget and the add-on firebug (Firefox) don’t find any css I can use to scrape the page. On other sites I can extract the css with selectorgadget or firebug and use it with nokogiri or scrapi.
Due to lack of experience it is difficult to identify the problem and therefore searching for a solution isn’t easy.
Can you tell me where to start solving this problem and where I maybe can find more info about a similar scraping process?
Thanks in advance!
my program is generating buttons from a mysql database.When one of the button is pressed, it would uplod the current time and the gps coordinate.
Sadly, it only works if the same button is pressed twice, but its not an option, because the button has to dissappear.
I would like to have some help in coding how to make that possible the user only need to press the button once for the correct upload.Thanks in advance
Here is the full code of my my file:
<?php session_start(); ?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>title</title>
</head>
<?php
$maidatum=date("Ymj");
echo "<script>getLocation();</script>";
//Az adatbázishoz való csatlakozás
$conn = mysql_connect("localhost","root","asd");
if(!($conn))die("Nincs conn a kiszolgálóval!".mysql_error());
$adatbazisneve="schtrans";
mysql_select_db($adatbazisneve,$conn);
mysql_query("set names 'utf8'");
mysql_query("set character set 'utf8'");
//Combobox
$sql = "SELECT Jaratszam,Vezeto FROM user";
$rs = mysql_query($sql) or die(mysql_error());
echo "<form action=\"\" method=\"post\">";
echo<<<nev
<select name='Lista'>
nev;
while($row = mysql_fetch_array($rs)){
echo "<option value='".$row["Jaratszam"]."'>".$row["Vezeto"]."</option>";
}mysql_free_result($rs);
echo "</select>";
///Combox vége
echo<<<lekerd
<form action="" method="post">
<input type="submit" name="bekuldes" value="Lekérdez" />
</form>
</form>
lekerd;
echo<<<gps
<form action="" method="post">
<input type="hidden" name= "longitude" id="longitude">
<input type= "hidden" name ="latitude" id="latitude">
</form>
gps;
if(isset($_POST["bekuldes"]))
{
$jaratszam = $_POST['Lista'];
$_SESSION['jaratsz']=$jaratszam;
$lekerdez_parancs="SELECT * FROM cim_$maidatum WHERE jarat=$jaratszam;";
$lekerdez=mysql_query($lekerdez_parancs, $conn);
echo "<table border=\"1\">";
echo "<td>Utánvétel</td> <td>Megrendelés összege</td> <td>ISZ</td> <td>Város</td> <td>Utca</td> <td>Megjegyzés</td> <td>Csomagok</td> <td>Raklaphely</td> <td>Súly</td><td>Térfogat</td><td>Latitude</td><td>Longitude</td><td>Ido</td>";
$g=1; //cimszámláló
while ($adatok=mysql_fetch_array($lekerdez)) {
echo "<tr>";
$_SESSION['adatok0'][$g]=$adatok[0];
echo "<td>$adatok[2]</td> <td>$adatok[3]</td> <td>$adatok[4]</td> <td>$adatok[5]</td> <td>$adatok[6]</td> <td>$adatok[7]</td> <td>$adatok[8]</td> <td>$adatok[9]</td> <td>$adatok[10]</td><td>$adatok[11]</td><td>$adatok[13]</td><td>$adatok[14]</td>";
if ($adatok[12]==null) {
echo<<<gomb
<form action="" method="post">
<td>
<input type="hidden" name= "longitude" id="longitude$g">
<input type= "hidden" name ="latitude" id="latitude$g">
<input type="submit" name="ido" value="$g" /></td>
</form>
gomb;
}
else {echo "<td>$adatok[12]</td>";}
$g++;
}
echo "</table>";
}
if(isset($_POST["ido"])) {
$hanyadik=$_POST["ido"];
$longitudee="longitude$hanyadik";
$latitudee="latitude$hanyadik";
?>
<script>
var x=document.getElementById("log");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition);
}
else{x.innerHTML="GPS szolgáltatás nem müködik ezen a böngészon, kérlek értesítsd a rendszergazdát!";}
}
function showPosition(position)
{
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
document.getElementById("<?php echo $longitudee;?>").value = longitude;
document.getElementById("<?php echo $latitudee;?>").value = latitude;
}
</script>
<?php
echo "<script>getLocation();</script>";
$latitude=$_POST["latitude"];
$longitude=$_POST["longitude"];
print_r($_POST);
$currentime=date("H:i:s");
$acim=$_SESSION['adatok0'][$hanyadik];
$idofeltolt_parancs="UPDATE cim_$maidatum SET ido='$currentime',lat='$latitude',longi='$longitude' WHERE cimid='$acim';";
$feltoltes=mysql_query($idofeltolt_parancs, $conn) or die(mysql_error());
//tryy
$jaratszam=$_SESSION['jaratsz'];
$lekerdez_parancs="SELECT * FROM cim_$maidatum WHERE jarat=$jaratszam;";
$lekerdez=mysql_query($lekerdez_parancs, $conn);
mysql_query("set names 'utf8'");
mysql_query("set character set 'utf8'");
echo "<table border=\"1\">";
echo "<td>Utánvétel</td> <td>Megrendelés összege</td> <td>ISZ</td> <td>Város</td> <td>Utca</td> <td>Megjegyzés</td> <td>Csomagok</td> <td>Raklaphely</td> <td>Súly</td><td>Térfogat</td><td>Latitude</td><td>Longitude</td><td>Ido</td>";
$g=1; //cimszámláló
while ($adatok=mysql_fetch_array($lekerdez)) {
echo "<tr>";
$_SESSION['adatok0'][$g]=$adatok[0];
echo "<td>$adatok[2]</td> <td>$adatok[3]</td> <td>$adatok[4]</td> <td>$adatok[5]</td> <td>$adatok[6]</td> <td>$adatok[7]</td> <td>$adatok[8]</td> <td>$adatok[9]</td> <td>$adatok[10]</td><td>$adatok[11]</td><td>$adatok[13]</td><td>$adatok[14]</td>";
if ($adatok[12]==null) {
echo<<<gomb
<form action="" method="post">
<td>
<input type="hidden" name= "longitude" id="longitude$g">
<input type= "hidden" name ="latitude" id="latitude$g">
<input type="submit" name="ido" value="$g" /></td>
</form>
gomb;
}
else {echo "<td>$adatok[12]</td>";}
$g++;
}
echo "</table>";
}
mysql_close($conn);
?>
</html>
I have a directive like the one of the examples from AngularJS, shown below.
How can I call the toggle method from the global scope?
I want to be able to toggle the zippy from some legacy code.
myApp.directive('zippy',
function(){
return {
restrict: 'E',
replace: true,
transclude: true,
scope: { title:'bind' },
template:
'<div class="zippy">' +
'<div class="title">{{title}}</div>' +
'<div class="body" ng-transclude></div>' +
'</div>',
link: function(scope, element, attrs) {
var title = angular.element(element.children()[0]),
opened = true;
title.bind('click', toggle);
function toggle() {
opened = !opened;
element.removeClass(opened ? 'closed' : 'opened');
element.addClass(opened ? 'opened' : 'closed');
}
toggle();
}
}
});
hello,
i have an ASP webform with a JQuery Thickbox, i have an image that opens the thickbox when user click.
once open the thickbox it shows me a grid with several rows and a button to select one and after the user select the record it returns to the main page the recordselected and cause a __doPostBack()
BUT! sometimes in IE6 it stay loading the postback and never ends i have to refresh the page and when it refresh it shows everything fine. but i dont want the postback stay loading AND it does not happend always.
i have to call a __doPostBack because i need to find info related to the selected record.
thanks.
I would like to replace div tags for p tags but only when the div tag does not have a class.
So this:
<div class="myDiv">
<div>sdfglkhj sdfgkhl sdfkhgl sdf</div>
<div>dsf osdfghjksdfg hsdfg</div>
</div>
Would become:
<div class="myDiv">
<p>sdfglkhj sdfgkhl sdfkhgl sdf</p>
<p>dsf osdfghjksdfg hsdfg</p>
</div>
I've tried .replace("<div>", "<p>").replace("</div>","</p>") but this replaces the closing tag of the one with a class.
Hello all,
It seems to me that this should work but I cant see what exactly is the problem.
The error Im receiving is "DDROA is not defined"
Could anyone help enlighten me.
var DDROA = {
AllowedRoutes : {
AR0 : {text : 'SomeText', value : 'SomeValue'},
AR1 : {text : 'SomeText2', value : 'SomeValue2'}
},
RouteContext : {
RC0 : {text : 'None', value : '0',
AllowedRoutes : new Array(
DDROA.AllowedRoutes.AR0 // An error occurs here
)
}
}
}
I currently have form that checks if a user has unsubmitted changes when they leave the page with a function called through the onunload event. Here's the function:
function saveOnExit() {
var answer = confirm("You are about to leave the page. All unsaved work will be lost. Would you like to save now?");
if (answer) {
document.main_form.submit();
}
}
And here's the form:
<body onunload="saveOnExit()">
<form name="main_form" id="main_form" method="post" action="submit.php" onsubmit="saveScroll()">
<textarea name="comments"></textarea>
<input type="submit" name="submit2" value="Submit!"/>
</form>
I'm not sure what I'm doing wrong here. The data gets submitted and saved in my database if I just press the submit button for the form. However, trying to submit the form through the onunload event doesn't result in anything being stored, from what I can tell. I've tried adding onclick alerts to the submitt button and onsubmit alerts to the form elements and I can verify that the submit button is being triggered and that the form does get submitted. However, nothing gets passed stored in the database. Any ideas as to what I'm doing wrong?
Thanks.
I came across the following http://ckeditor.com/demo , and was wondering if anyone had a basic tutorial how to implement this (or perhaps what key search terms I should use)?
Is this just a heavily modified TextField, or have they somehow managed to create a completely new TextField from scratch?
I tried googling this many times, and I always get pages relating to customizing the built-in TextField with CSS etc.
Hi!
I have a ASP.NET Website, where, in a GridView item template, automatically populated by a LinqDataSource, there is a LinkButton defined as follows:
<asp:LinkButton ID="RemoveLinkButton" runat="server" CommandName="Remove"
CommandArgument='<%# DataBinder.GetPropertyValue(GetDataItem(), "Id")%>'
OnCommand="removeVeto_OnClick"
OnClientClick='return confirm("Are you sure?");'
Text="Remove Entry" />
This works fine. Whenever the Button is Clicked, a confirmation dialog is displayed.
What I am trying to do now, is to allow the user to enter a reason for the removal, and pass this on the the OnClick event handler. How would I do this?
I tried OnClientClick='return prompt("Enter your reason!");', but, of course, that did not work =)
Hi All,
I have a login button at the footer of my main page or landing page.Currently when user click on the button a login form will get open from TOP to BOTTOM i.e. from the start of form to the "LOGIN" button.What i want is that when i click on the login button it should open the form using slide effect but from the BUTTON to the TOP.I don't want to include library like jQuery as there are some conflict issue with it.
Please help me out or refer me some url where it happens.
Regards,
Salil Gaikwad
I'm retrieving an array of objects from a hidden html input field. The string I'm getting is:
"{"id":"1234","name":"john smith","email":"[email protected]"},{"id":"4431","name":"marry doe","email":"[email protected]"}"
Now I need to pass this as an array of objects again. How do I convert this string into array of objects?
I have textbox whose value if entered needs to be validated using some regularexpression
I need to validate the value as user is entering the data.
Which is suitable event can be used for this ? some sample example of using onfocus event on textbox will be helpful
I'm trying to extract column names from a SQLite result set from sqlite_master's sql column. I get hosed up in the regular expressions in the match() and split() functions.
t1.executeSql('SELECT name, sql FROM sqlite_master WHERE type="table" and name!="__WebKitDatabaseInfoTable__";', [],
function(t1, result) {
for(i = 0;i < result.rows.length; i++){
var tbl = result.rows.item(i).name;
var dbSchema = result.rows.item(i).sql;
// errors out on next line
var columns = dbSchema.match(/.*CREATE\s+TABLE\s+(\S+)\s+\((.*)\).*/)[2].split(/\s+[^,]+,?\s*/);
}
},
function(){console.log('err1');}
);
I want to parse SQL statements like these...
CREATE TABLE sqlite_sequence(name,seq);
CREATE TABLE tblConfig (Key TEXT NOT NULL,Value TEXT NOT NULL);
CREATE TABLE tblIcon (IconID INTEGER NOT NULL PRIMARY KEY,png TEXT NOT NULL,img32 TEXT NOT NULL,img64 TEXT NOT NULL,Version TEXT NOT NULL)
into a strings like theses...
name,seq
Key,Value
IconID,png,img32,img64,Version
Any help with a RegEx would be greatly appreciated.
I am trying to customize a view-src bookmarklet for iPad. This one is looking pretty good so far.
But I want to make it just a little more readable: The Courier (New) font is a bit ugly even (especially?) on the retina display and I'd prefer any one of DejaVu Sans Mono, Monaco, Lucida Console, Bitstream Vera Sans Mono.
I tried to modify the bookmarklet script by adding:
pre.style.fontFamily = '"DejaVu Sans Mono", "Lucida Console", Monaco;';
It's not doing the trick.
Perhaps prettyprint cancels out my fontFamily setting when it loads. Maybe I can set it at the end of the script somehow...
How do you usually organize complex web applications that are extremely rich on the client side. I have created a contrived example to indicate the kind of mess it's easy to get into if things are not managed well for big apps. Feel free to modify/extend this example as you wish - http://jsfiddle.net/NHyLC/1/
The example basically mirrors part of the comment posting on SO, and follows the following rules:
Must have 15 characters minimum,
after multiple spaces are trimmed
out to one.
If Add Comment is clicked, but the
size is less than 15 after removing
multiple spaces, then show a popup
with the error.
Indicate amount of characters remaining and
summarize with color coding. Gray indicates a
small comment, brown indicates a
medium comment, orange a large
comment, and red a comment overflow.
One comment can only be submitted
every 15 seconds. If comment is
submitted too soon, show a popup
with appropriate error message.
A couple of issues I noticed with this example.
This should ideally be a widget or some sort of packaged functionality.
Things like a comment per 15 seconds, and minimum 15 character comment belong to some application wide policies rather than being embedded inside each widget.
Too many hard-coded values.
No code organization. Model, Views, Controllers are all bundled together. Not that MVC is the only approach for organizing rich client side web applications, but there is none in this example.
How would you go about cleaning this up? Applying a little MVC/MVP along the way?
Here's some of the relevant functions, but it will make more sense if you saw the entire code on jsfiddle:
/**
* Handle comment change.
* Update character count.
* Indicate progress
*/
function handleCommentUpdate(comment) {
var status = $('.comment-status');
status.text(getStatusText(comment));
status.removeClass('mild spicy hot sizzling');
status.addClass(getStatusClass(comment));
}
/**
* Is the comment valid for submission
*/
function commentSubmittable(comment) {
var notTooSoon = !isTooSoon();
var notEmpty = !isEmpty(comment);
var hasEnoughCharacters = !isTooShort(comment);
return notTooSoon && notEmpty && hasEnoughCharacters;
}
// submit comment
$('.add-comment').click(function() {
var comment = $('.comment-box').val();
// submit comment, fake ajax call
if(commentSubmittable(comment)) {
..
}
// show a popup if comment is mostly spaces
if(isTooShort(comment)) {
if(comment.length < 15) {
// blink status message
}
else {
popup("Comment must be at least 15 characters in length.");
}
}
// show a popup is comment submitted too soon
else if(isTooSoon()) {
popup("Only 1 comment allowed per 15 seconds.");
}
});