Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

is this same code work in web work also?

Hi

SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
						                String dateOfJourney = dateFormat.formatLocal(_dateField.getDate());
						
dateFormat = new SimpleDateFormat("HH:mm");
					                                                                                                    String timeOfJourney = dateFormat.formatLocal(_timeField.getDate());
					 
					 
				
			
	int pin = DeviceInfo.getDeviceId();
					 
					

 i write this code in java for  getting a date , actually i need same code in phone gap using java script . i want  to ask this  question is this work in phonegap or not??

Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: is this same code work in web work also?

To start I need to say Cordova/PhoneGap is only a framework that adapts the APIs of mobile OSs to make them similar across the OSs to avoid writing source code for each of them but at the end it isn't changing or extending fundamental things like working with Date in JavaScript, so your question hasn't anything to do with Java or Cordova/PhoneGap.

 

All you need is, again, a tutorial or page to get all the informations about working with the Date object. Using Google I think this tutorial is a good starting point to become familiar with Date object: http://javascript.info/tutorial/datetime-functions


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: is this same code work in web work also?

Thanks sir ...!!

 

1 question more

is there any way to show button after filling the text in text filed .I am not asking for disble button. i am asking to show button when user fill the text filled, if text filled is blank the button is not display on screen. is this possible

Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: is this same code work in web work also?

Something like that might work:

 

<textarea id="myTXTArea"></textarea>
<button id="myBtn" style="display: none;">a button</button>

<script type="text/javascript">
	document.getElementById('myTXTArea').onkeyup = function(e) {
		var length = (e.currentTarget||e.srcElement).value.length||0;
		// if textarea is empty
		if(length <= 0) {
			document.getElementById('myBtn').style.display = 'none';
		}
		// if textarea isn't empty
		else {
			document.getElementById('myBtn').style.display = 'block';
		}
	}
</script>

 

 


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: is this same code work in web work also?

(e.currentTarget||e.srcElement).value.length||0;

what is meaning "||"0 it is or operator i think .
.value.length||0;

what is this "||"?
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: is this same code work in web work also?

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
  	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  	<title>Departure Schedule</title>
  	
	<script type="text/javascript">
   		
   		
   		
   		document.getElementById('myTXTArea').onkeyup = function(e) {
	   		alert("p");
		var length = (e.currentTarget||e.srcElement).value.length||0;
		// if textarea is empty
		if(length <= 0) {
			document.getElementById('myBtn').style.display = 'none';
		}
		// if textarea isn't empty
		else {
			document.getElementById('myBtn').style.display = 'block';
		}
	}
   		

</script>
	
</head>
<body onload="GetDepartureStationDashboard()">
<textarea id="myTXTArea"></textarea>
<button id="myBtn" style="display: none;">a button</button>

</body>
</html>

 

Hi. sir this is nice code. I check this code like when i get web service resone button is display, it woking fine.

 

 

But this keyup event is not fir i think..i used like 

 

Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: is this same code work in web work also?

First of all you need to understand how JavaScript initialization works. Thats why I used the HTML source first and then placed the script-tag with source. When using document.getElementById('myElement') the DOM needs to have the reference to element with ID "myElement". In your example the browser first executes the script-tag source, but will not be able to get any reference object by executing document.getElementById('myTXTArea') so it will throw an error.

 

So, how does it read/execute your source code:

 

1) HEAD-> script-tag (will not find the textarea since not yet available in DOM)
2) BODY-> textarea + button (now elements are available in DOM)

And in comparison to my source code:

 

1) BODY-> textarea + button (now elements are available in DOM)
2) BODY-> script-tag (will find the textarea since available in DOM)

 

 

So, what to do: Use Firebug (in Firefox) or Web Inspector (in Chrome) to debug your source code. With Web Inspector you are also able to debug the app running on a BlackBerry device really well. Add the provided sample JavaScript source to your onload-function (onload="GetDepartureStationDashboard()") or use another onload function to seperate a little bit.

 

For the || operator try to search using google. If you do not know what || means you should try to understand JS in more detail since this is one of many fundamental things you need to know, I think!!


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.
Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: is this same code work in web work also?

Thanks

sir nice anwer ...

Developer
Posts: 777
Registered: ‎07-21-2012
My Device: 9810
My Carrier: 0

Re: is this same code work in web work also?

I understand every thing but 

 

(e.currentTarget||e.srcElement).value.length||0;  can you please explain this please sir...

 

|| this is OR operator but what is the use here

Developer
Developer
Posts: 607
Registered: ‎04-29-2011
My Device: PlayBook 16GB, BB10 LE Z10 (red)
My Carrier: none

Re: is this same code work in web work also?

If there isn't any input in eg. the textarea this will fail:

 

(e.currentTarget||e.srcElement).value

 and throw an error, so you can not call it, but using the || (OR) here you can avoid the error and return 0 since there isn't any input and therefor the value.length would be 0 (if there wouldn't be the error).

 


"Like" if you liked the post.
"Accept as Solution" if the post solves your question.