1

I'm displaying the alphabets in a grid view,whenever i click on each alphabet it has to display the corresponding words of that alphabet,for that i could able to get the position of each alphabet,so how can i retrieve or pass the data from database?

here is the screenshot of that

enter image description here

the code for that grid view is

var a2zArray =['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'];

$(document).ready(function()
{
    createA2ZGrid();
});

function createA2ZGrid(){
var rowElem='';

for (var i=0; i < a2zArray.length; i++){
    rowElem = rowElem +" "+ "<label id='elementId' onclick=onClicked('"+a2zArray[i]+"')>" + a2zArray[i] + "</label>";

}
         $("#A2Z-GridId").html(rowElem);
}

function onClicked(element){
alert("Onclicked : "+element);

};

how can i pass the argument from html to js?

pujitav
  • 528
  • 1
  • 5
  • 17
  • You have to use AJAX in order to do so. You can find a lot of tutorials or try with documentation : http://api.jquery.com/category/ajax/ – Michael Lumbroso Aug 20 '12 at 12:18
  • here i dont need to use the server or anything...i have my local database,without ajax can i accomplish my requirement?? – pujitav Aug 20 '12 at 12:27
  • See this answer : http://stackoverflow.com/questions/857670/how-to-connect-to-sql-server-database-from-javascript You cannot access directly DB from JS (forget that ugly IEish ActiveX...), you have to use server side hence AJAX. – Michael Lumbroso Aug 20 '12 at 12:29
  • i have already connected to my db and able to process using phonegap,but i wanted to know how can i reuse them by each mouse click? – pujitav Aug 20 '12 at 12:33
  • Ok, didn't know phoneGap used SQLite! So what is the problem in triggering a call to the DB in your function onClicked? BTW, you used the same id on all labels, careful with this ;-) – Michael Lumbroso Aug 20 '12 at 12:39

1 Answers1

0

In case you are using phonegap, you have to dive in to jquery mobile In your index.html page in your header: (or see phonegap documentation)

<script type="text/javascript" src="js/cordova-2.5.0.js"></script>
<script type="text/javascript" src="js/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.1.0.min.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/webtoolkit.base64.js"></script>
<script type="text/javascript" src="js/MacAddress.js"></script>
<script type="text/javascript" src="js/your_own_javascript.js"></script>
<link rel="stylesheet" href="css/jquery.mobile-1.1.0.min.css" />

then for your code: I tested this:

<label id='elementId' onclick="onClicked('Test')">test</label>

and in your javascript.js (or in the html code in script tags):

function onClicked(element){
    navigator.notification.alert("Onclicked : "+element);

};

and this works

as far as I can see in your code, you are missing the quotes around the function

"<label id='elementId' onclick=onClicked('"+a2zArray[i]+"')>" + a2zArray[i] + "</label>"

will result in

<label id='elementId' onclick=onClicked('something')>something</label>

and it should be:

<label id='elementId' onclick="onClicked('something')">something</label>

so this should work:

"<label id='elementId' onclick='onClicked('"+a2zArray[i]+"')'>" + a2zArray[i] + "</label>"
michel.iamit
  • 5,788
  • 9
  • 55
  • 74