JavaScript function

Sunday, March 30, 2014

0 comments
I have been stuck on this problem and I know its something small but cannot get it working.

I have two queries and I want the user to have an option of what query they want to display and what type of graph. I can get one working but not at the same time. I always get one says no data and the other displays and vice a versa.

The user needs to have option which one they would like to display eg: query 1 or query 2 ( it should be just a simple if statement)
<script type="text/javascript">
     
var resultArray = ['test'];
      // Define a callback function to receive the SPARQL JSON result.
      function myCallback(str) {
        // Convert result to JSON
        var jsonObj = eval('(' + str + ')');

        // Build up an array of results.
resultArray = new Array();
resultArray[0] = jsonObj.head.vars;
for(var i = 0; i <  jsonObj.results.bindings.length; i++) {
resultArray[i+1] = new Array();
resultArray[i+1][0] = jsonObj.results.bindings[i].Name.value;
resultArray[i+1][1] = jsonObj.results.bindings[i].Population.value / 1000;
        } 
     }
      
     // Make the query.
    // sparqlQueryJson(query, endpoint, myCallback, false);
      
 
      google.load("visualization", "1", {packages:["corechart"]});
     
      function drawChart() {
 
var item = document.getElementById('selQuery').value;
var item2 = document.getElementById('graphs').value;
if (item == 'query1')
{
function sparqlQueryJson(queryStr, endpoint, callback, isDebug) {
      var querypart = "query=" + escape(queryStr);
    
      // Get our HTTP request object.
      var xmlhttp = null;
      if(window.XMLHttpRequest) {
        xmlhttp = new XMLHttpRequest();
     } else if(window.ActiveXObject) {
       // Code for older versions of IE, like IE6 and before.
       xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
     } else {
       alert('Perhaps your browser does not support XMLHttpRequests?');
     }
    
     // Set up a POST with JSON result format.
     xmlhttp.open('POST', endpoint, true); // GET can have caching probs, so POST
     xmlhttp.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
     xmlhttp.setRequestHeader("Accept", "application/sparql-results+json");
    
     // Set up callback to get the response asynchronously.
     xmlhttp.onreadystatechange = function() {
       if(xmlhttp.readyState == 4) {
         if(xmlhttp.status == 200) {
           // Do something with the results
           if(isDebug) alert(xmlhttp.responseText);
           callback(xmlhttp.responseText);
         } else {
           // Some kind of error occurred.
           alert("Sparql query error: " + xmlhttp.status + " "
               + xmlhttp.responseText);
         }
       }
     };
     // Send the query to the endpoint.
     xmlhttp.send(querypart);
    
     // Done; now just wait for the callback to be called.
    };
var endpoint = "http://sws.ifi.uio.no/sparql/world";
      var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX owl: <http://www.w3.org/2002/07/owl#>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX w: <http://sws.ifi.uio.no/ont/world.owl#>PREFIX dbpo: <http://dbpedia.org/ontology/>PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>PREFIX dct: <http://purl.org/dc/terms/>PREFIX fn: <http://www.w3.org/2005/xpath-functions#>PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>PREFIX npdv: <http://sws.ifi.uio.no/vocab/npd#>PREFIX npdv2: <http://sws.ifi.uio.no/vocab/npd-v2#>PREFIX geos: <http://www.opengis.net/ont/geosparql#>SELECT * WHERE{ []  a w:Country ; w:hasName ?Name ; w:hasCountryPopulation ?Population ; } ORDER BY DESC(?Population) LIMIT 10" ;
sparqlQueryJson(query, endpoint, myCallback, false);
var data = google.visualization.arrayToDataTable(resultArray);

        var options = {
          title: document.selectionForm.graphName.value,
          hAxis: {title: 'Note: All Values are in thousands',  titleTextStyle: {color: 'red'}}
};
            if (item2 == 'bar'){
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        chart.draw(data, options);}
else if (item2 == 'pie'){
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
}
else if (item2 == 'column'){
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
        chart.draw(data, options);
}
      }
else if (item == 'query2')
{
var endpoint = "http://sws.ifi.uio.no/sparql/world";
var query = "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>PREFIX owl: <http://www.w3.org/2002/07/owl#>PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>PREFIX w: <http://sws.ifi.uio.no/ont/world.owl#>PREFIX dbpo: <http://dbpedia.org/ontology/>PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#>PREFIX dct: <http://purl.org/dc/terms/>PREFIX fn: <http://www.w3.org/2005/xpath-functions#>PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>PREFIX npdv: <http://sws.ifi.uio.no/vocab/npd#>PREFIX npdv2: <http://sws.ifi.uio.no/vocab/npd-v2#>PREFIX geos: <http://www.opengis.net/ont/geosparql#>SELECT * WHERE{ [] a w:City ; w:hasName ?Name ; w:hasCityPopulation ?Population ; } ORDER BY DESC(?Population) LIMIT 10";
var data = google.visualization.arrayToDataTable(resultArray);

        var options = {
          title: document.selectionForm.graphName.value,
          hAxis: {title: 'Note: All Values are in thousands',  titleTextStyle: {color: 'red'}}
 
 
        };
if (item2 == 'bar'){
var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
        chart.draw(data, options);}
else if (item2 == 'pie'){
var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
        chart.draw(data, options);
}
else if (item2 == 'column'){
var chart = new google.visualization.ColumnChart(document.getElementById('chart_div'));
        chart.draw(data, options);
}
      }
 
}
    </script>

<form name='selectionForm'>
<table border=0 style= "align:center">
<tr>
<td><b>Queries</b></td>
<td><select  id= 'selQuery' name='query'>
<option value='query1'>Top ten countries by population</option>
<option value='query2'>Top ten most populated cities in the world</option>
<option value='query3'>Query 3</option>
<option value='query4'>Query 4</option>
</select>
</td>
</tr>

<tr>
<td><b>Graphs</b></td> 
<td><select  id='graphs' name='charts'>
<option value='pie'>Pie Chart</option>
<option value='bar'>Bar Chart</option>
<option value='column'>Column Chart</option>
<option value='bubble'>Bubble Chart</option>
</select>
</td>
</tr>
<tr>
<td><b>Enter graph name :</b></td>
<td><textarea name='graphName' rows='1' cols='50'></textarea></td>
</tr>
<tr>
<td><b>Measurements:</b></td>
<td><b>Height:<textarea name='graphHeight' rows='1' cols='10'></textarea>Width:<textarea name='graphWidth' rows='1' cols='10'></textarea></b></td>
</tr>
<tr>
<td></td>
<td><input type='button' value='Submit' style='background:white; width:100px; height:30px; font-weight:900;' 
onClick='drawChart();'></td>
</tr>
</table>
</form>
<div id="chart_div" style="width: 900px; height: 500px;"></div>

 

Maybe a another set of eyes will help?

This is a jsfiddle of my code

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

MASTER PSYCHIC READER~ ACCURATE & AMUSING

Tuesday, March 25, 2014

0 comments
Your first 3 minutes are FREE talking live with me.

Please visit my website at: http://www.keen.com/Ask+Fran

Or, call me right now at: 1-800-275-5336 x0160

--
You received this message because you are subscribed to the Google Groups "Website Design Nz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to website-design-nz+unsubscribe@googlegroups.com.
To post to this group, send email to website-design-nz@googlegroups.com.
Visit this group at http://groups.google.com/group/website-design-nz.
For more options, visit https://groups.google.com/d/optout.

Re: Just need One object using two id

Sunday, March 16, 2014

0 comments
Thanks you so much 


On Sun, Mar 16, 2014 at 12:22 AM, Obi Wan <jippijappo@hotmail.com> wrote:
A better way is probably to create a common function which you pass "gmap" and "gmap1" to.

kl. 09:53:11 UTC+1 fredag 14. mars 2014 skrev cyberoot følgende:
Can i Combine two id as one?
I don't want to use two time document.getElementByID('gmap') and ('gmap1')


Thanks you bro.

jQuery(document).ready(function() {
 
  // Load google map
  var map = new google.maps.Map(document.getElementById('gmap'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

  var map1 = new google.maps.Map(document.getElementById('gmap1'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Just need One object using two id

Saturday, March 15, 2014

0 comments
A better way is probably to create a common function which you pass "gmap" and "gmap1" to.

kl. 09:53:11 UTC+1 fredag 14. mars 2014 skrev cyberoot følgende:
Can i Combine two id as one?
I don't want to use two time document.getElementByID('gmap') and ('gmap1')


Thanks you bro.

jQuery(document).ready(function() {
 
  // Load google map
  var map = new google.maps.Map(document.getElementById('gmap'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

  var map1 = new google.maps.Map(document.getElementById('gmap1'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Re: Just need One object using two id

Friday, March 14, 2014

0 comments
How about this as an alternative?

var MapInfo = {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
};

jQuery(document).ready(function() {
  // Load google map
  var map = new google.maps.Map(document.getElementById('gmap'), MapInfo);
  var map1 = new google.maps.Map(document.getElementById('gmap1'), MapInfo);
}

One possible side effect of the above code is that the Map function might change the contents of the MapInfo object. 
If that is undesirable, try this: 

function MapInfoFun () {
  return {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  };
}

jQuery(document).ready(function() {
  // Load google map
  var map = new google.maps.Map(document.getElementById('gmap'), MapInfoFun());
  var map1 = new google.maps.Map(document.getElementById('gmap1'), MapInfoFun());
}

On Friday, March 14, 2014 4:53:11 AM UTC-4, cyberoot wrote:
Can i Combine two id as one?
I don't want to use two time document.getElementByID('gmap') and ('gmap1')


Thanks you bro.

jQuery(document).ready(function() {
 
  // Load google map
  var map = new google.maps.Map(document.getElementById('gmap'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

  var map1 = new google.maps.Map(document.getElementById('gmap1'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Just need One object using two id

0 comments
Can i Combine two id as one?
I don't want to use two time document.getElementByID('gmap') and ('gmap1')


Thanks you bro.

jQuery(document).ready(function() {
 
  // Load google map
  var map = new google.maps.Map(document.getElementById('gmap'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

  var map1 = new google.maps.Map(document.getElementById('gmap1'),  {
    center: new google.maps.LatLng(0,0),
    zoom: 3,
    mapTypeId: google.maps.MapTypeId.ROADMAP,
    panControl: false,
    streetViewControl: false,
    mapTypeControl: false
  });

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Web Designing Online Training in Hyderabad | INDIA | USA | UK | CANADA | SINGAPORE | MALAYSIA

Thursday, March 13, 2014

0 comments
Web Designing Online Training by Webdesigningonlintraining We are providing excellent Web Designing Training by
real-time IT industry experts Our training methodology is very unique Our Course Content covers all the in-depth
critical scenarios. We have completed more than 100 Web Designing batches through Online Web Designing
Training program, Our Web Designing Classes covers all the real time scenarios, and its completely on Hands-on for each
and every session.

Contact Number : India :+91 (0) 8897931177,

Email : webdesignonlinetrainings@gmail.com ,

Web: http://webdesigningonlinetraining.com/

--
You received this message because you are subscribed to the Google Groups "Web Design & Programming | Tutorials - Tips - Tricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web-des-prog+unsubscribe@googlegroups.com.
To post to this group, send email to web-des-prog@googlegroups.com.
Visit this group at http://groups.google.com/group/web-des-prog.
For more options, visit https://groups.google.com/d/optout.

Web Designing Online Training in INDIA | MALAYSIA | JAPAN | SINGAPORE | UK

Monday, March 10, 2014

0 comments
Web Designing Online Training by Webdesigningonlintraining We are providing excellent Web Designing Training by
real-time IT industry experts Our training methodology is very unique Our Course Content covers all the in-depth
critical scenarios. We have completed more than 100 Web Designing batches through Online Web Designing
Training program, Our Web Designing Classes covers all the real time scenarios, and its completely on Hands-on for each
and every session.

Contact Number : India :+91 (0) 8897931177,

Email : webdesignonlinetrainings@gmail.com ,

Web: http://webdesigningonlinetraining.com/

--
You received this message because you are subscribed to the Google Groups "Web Design & Programming | Tutorials - Tips - Tricks" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web-des-prog+unsubscribe@googlegroups.com.
To post to this group, send email to web-des-prog@googlegroups.com.
Visit this group at http://groups.google.com/group/web-des-prog.
For more options, visit https://groups.google.com/d/optout.

MASTER PSYCHIC READER~ ACCURATE & AMUSING

Sunday, March 9, 2014

0 comments
Your first 3 minutes are FREE talking live with me.

Please visit my website at: http://www.keen.com/Ask+Fran

Or, call me right now at: 1-800-275-5336 x0160

--
You received this message because you are subscribed to the Google Groups "Website Design Nz" group.
To unsubscribe from this group and stop receiving emails from it, send an email to website-design-nz+unsubscribe@googlegroups.com.
To post to this group, send email to website-design-nz@googlegroups.com.
Visit this group at http://groups.google.com/group/website-design-nz.
For more options, visit https://groups.google.com/d/optout.

Re: text in textarea disappears

Thursday, March 6, 2014

0 comments
The contents of textarea tag is stored in the value attribute, not the innerHTML, as many seem to think. textcontent (which should be spelled textContent) changes innerHTML, not value.

Use:

   code.value = "test";


On Tuesday, March 4, 2014 4:12:24 PM UTC-5, An Mertens wrote:
A javascript application puts a message in a textarea of an html page. After the message has been put in the textarea, the message immediately disapears.

code in javascript application:

xhr.onreadystatechange=function(){
if (4===xhr.readystate){
   var code = document.querySelector("textarea")
   code.textcontent="test"
}
}
xhr.send()

code in the html file:

<textarea name="textarea" id="textarea" width="1000" style="width:1000px" autocomplete="on"></textarea>

Output in the textarea
test

But the text "test" immediately disappears.

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

text in textarea disappears

Tuesday, March 4, 2014

0 comments
A javascript application puts a message in a textarea of an html page. After the message has been put in the textarea, the message immediately disapears.

code in javascript application:

xhr.onreadystatechange=function(){
if (4===xhr.readystate){
   var code = document.querySelector("textarea")
   code.textcontent="test"
}
}
xhr.send()

code in the html file:

<textarea name="textarea" id="textarea" width="1000" style="width:1000px" autocomplete="on"></textarea>

Output in the textarea
test

But the text "test" immediately disappears.

--
You received this message because you are subscribed to the Google Groups "JavaScript Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to javascript-information+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Copyright © 2010 Web Design | Free Blogger Templates by Splashy Templates | Layout by Atomic Website Templates

Vida de bombeiro Recipes Informatica Humor Jokes Mensagens Curiosity Saude Video Games Animals Diario das Mensagens Eletronica Rei Jesus News Noticias da TV Artesanato Esportes Noticias Atuais Games Pets Career Religion Recreation Business Education Autos Academics Style Television Programming Motosport Humor News The Games Home Downs World News Internet Design Entertaimment Celebrities 1001 Games Doctor Pets Net Downs World Enter Jesus Mensagensr Android Rub Letras Dialogue cosmetics Genexus lasofia thebushrajr wingshock tripedes gorduravegetal dainfamia dejavu-transpersonal jsbenfica republicadasbadanas ruiherbon iranianforaryans eaystcheyl fotosdanadir Só Humor Curiosity Gifs Medical Female American Health Madeira Designer PPS Divertidas Estate Travel Estate Writing Computer Matilde Ocultos Matilde futebolcomnoticias girassol lettheworldturn topdigitalnet Bem amado enjohnny produceideas foodasticos cronicasdoimaginario downloadsdegraca compactandoletras newcuriosidades blogdoarmario arrozinhoii