How to make dynamic apps using Phonegap?

  • 2
  • Problem
  • Updated 6 months ago
Hi there, i am a student creating an app. But having some problems, i still cudn't found that what are the plugins and how we can use i used many from list but all they are not responding. Phonegap Team please help me i just want to create an app with camera(to capture images) and Call(to a particular number) how i can use them? I am using build.phonegap.com using dreamweaver. Thanks in advance. I also attached the screen shot of my app
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes

Posted 4 years ago

  • 2
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, Good Morning, I googled and found that the image size i was using, that was large, and when i used small size It was loading at phone too.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Dear Petra, I have little confusion yet, about Phoneno, and email, fields, Actually i was validating fields, If I will not make phone no and email mandatory, Then how i can contact to complainant?In case of Complain solved or Unsolved?
Suggest me better, thank u
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Several options:
- make either one mandatory (let user decide which one), so you can contact him directly
- make none mandatory; if user doesn't supply data he will not be contacted
- additionally: supply an overview page with complaints and status, so every user can see in the app what the status of each complaint is, OR
after receiving a complaint, display a randomly generated Complaint ID (not the autoincrement PK, of course), with which the user can check the Complaint status in the app (since he doesn't now the ID of other Complaints, he will not have access to them). You can keep his Complaint ID's in localStorage for future reference, but these data won't be available in other devices, unless you create a sync mechanism.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
-I make one field now as u said, e.g. Email/Phone, users either can input their email, or phone number.
-As far as I understand, I should make another column in Complaint table e.g. COMPLAINNO , Is it possible to have two auto_increment fields in same table? one is Pk (1,2,3,4......n) and second COMPLAINNO (COMPNO001, COMPNO002, COMPNO002.....COMPNO00n)?
-After Successfully submit the form, user can see another page or dialog box with caption "Your Complain Has been booked, and your complain no. is COMNO0089, Please check the status here. and whenever user will click on here link, he can find another page with small form have two fields (Please enter Complain no. and email/phone), and when he will submit the small form, he can fetch the details from database e.g. solved or unsolved.Am i going right?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Is it possible to have two auto_increment fields in same table?
Yes. But for this randomly generated ComplaintNO you don't want an auto_increment, because users could then guess the complaint numbers of others.

(In fact, you could use this randomly Complaint number as primary key instead of the auto-increment field, as long as you make sure it's unique)

Am i going right?
Why so complicated? Would you like to use functionality like that if you were the user?
If I were the person filing complaints, I would expect an overview with my complaints and their statuses (and I should be able to access that overview anytime, not just from a 'here' link in that one-time message..
Or at least a small form page where I can enter the complaint number and see its status. Why should I enter email/phone just to see the status of my complaint?

Anyway: what were the community's requirements regarding feedback to the user who filed a complaint?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
-Yes email Id is not necessary to fetch complaints statuses, i was wrong.
-It should be a different form for users they can see statuses anytime. And just by enter a randomly created COMPLAINTNO. I got it , Thank you PETRA sooooo much. Petra as Jesse said, I should not ask help to you? You feel irritated or bad?

The community is totally depended on me, they just said ask for user's complaint, and they will sortout problems and update their databases.

Petra Once again THANK YOU SO MUCH, i can't forget your favors on me.
You know You are teaching me here, IT .
"You are my Inspirational person now in the world."
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra I used this UUID() method to create randomly complainNo,
left(uuid(), 8)
and it's returned
326f8afe
So it's correct to create random data?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
No. That way, each device can only file one complaint.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Then How I can ? Please give little Hint, thank you
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Basic javascript.
Easy to find.

http://www.w3schools.com/jsref/jsref_...
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes

<script>
function myFunction() {
var x = document.getElementById("demo")
x.innerHTML = Math.floor((Math.random() * 1000000) + 1);
}
</script>

If I am using this function, so it will be unique numbers b/w 1 and 1000000?
Evertime when I will call it?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Did you try it?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Yes I tried, Petra, It's showing numbers randomly but I was just making confirm. :)
That all the numbers it's showing all are different or not
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
They are. It's correct.
But....you must make sure that the number you get is unique (not yet in database). That would require an additional ajax call to check if the number is already taken, OR a mechanism to make sure it is unique (for instance by concatenating a timestamp - or at least a microtime - to the number).
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Ok Petra, Thank U so much :) u r awesome.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Respected Petra,
This is my task remains:

I am just scaring from ajax calls. :(
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
??
You want to do 7,8,9 before doing the client/server communication?
And where is your backend development?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Oh Sorry, Yes ofcourse after successful server/client communication I will do final touching. Petra, what i was saying that, I will check on free webhost first, when It will be successful after I will buy space from webserver? is it possible?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Don't you think the community has its own data center, or at least a managed server? Shouldn't the back end run on the community's facilities?

(If I were the IT boss of that community, I would make sure that
- the backend is hosted where I can manage it
- the sources of the application are in my possession
- generally: I want to be independent of the supplier and thus reduce risks)
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, actually when I talk about to handover this app to them, after successful build, before few days ago, They said that I should manage all the activities of app, even they are related to backend or front. They want I will be there database manager to update or another task, Now i can say I will be responsible for all tasks, I want to check first on any free webhosting service, when It will work fine, I will upload on purchased space from any authorized company.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
You are right Petra, Thats y i m holding now all the tasks related to App. You are always right. :) and good human too. May Allah give u long life with happiness, health and worship aameen :)
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Good Morning Petra, Have a Nice day.
I have few questions/problems:
1. How I can validate my 'Email/Mobile' filed with correct phone NUmber or email is same field?
2. I have three buttons in my 'Post Complain' Page, and thrice are behaving like submit buttons, Whenever I am clicking 'Capture Photo' or 'Choose from Gallery' Buttons, both they are behaving like 'Submit' Buttons, they are working properly, but they are validating fields, and when I am coming back from both buttons after choose/capture picture, the all fields are going blank.
Can u find out the problems?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
1. If it's a valif phone#, treat it as phone#.
If it's a valid mail address, treat it as email, otherwise issue an error message.

2. They should not behave as submit buttons. But since I can't see your code, I have no idea what you are doing wrong this time.
(Edited)
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
For Camera and Library:


<button onclick="capturePhoto();">Capture Photo</button> <br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" /><br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<input type="submit" value="Submit" class="button button-pill button-action button-large">




Java Script:

<script type="text/javascript" charset="utf-8">

var pictureSource; // picture source
var destinationType; // sets the format of returned value

// Wait for Cordova to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);

// Cordova is ready to be used!
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}

// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);

// Get image handle
//
var smallImage = document.getElementById('smallImage');

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}

// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
// console.log(imageURI);

// Get image handle
//
var largeImage = document.getElementById('largeImage');

// Unhide image elements
//
largeImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageURI;
}

// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}

// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
This code nowhere clears form fields or triggers a form submit.
In fact, there is no form element, so the first thing to do is use a Validator or Lint to validate your html code.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
See complete Petra:

<form name="myForm" action="#" onsubmit="return validateForm()" method="post">
<input type="text" name="personname" placeholder="Name" required class="text"><span class="error">*</span><br><br>
<input type="text" name="emailphn" placeholder="Email/Mobile" required class="text"><span class="error">*</span><br><br>
<textarea cols=30 rows=5 placeholder="Enter Complain's Address" name="locationtxt" width=100% style="background:#12192C; width:80%; border-radius:0 6px 6px 0; border:none; outline:none; color:#999; font-family: 'Source Sans Pro', sans-serif"></textarea>
<textarea cols=30 rows=5 placeholder="If other, please specify!" name="otherdescription" class="textarea"></textarea>
<br>
<button onclick="capturePhoto();">Capture Photo</button> <br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" /><br>
<button onclick="getPhoto(pictureSource.PHOTOLIBRARY);">From Photo Library</button><br>
<img style="display:none;width:60px;height:60px;" id="smallImage" src="" />
<input type="submit" value="Submit" class="button button-pill button-action button-large">
</p></form>


Java Script for Validation


<script type="text/javascript">
function validateForm()
{
var x=document.forms["myForm"]["personname"].value;
if (x==null || x=="")
{
alert("Name must be filled out");
return false;
}

var y=document.forms["myForm"]["emailphn"].value;
if (y==null || y=="") {
alert("Email/Phone must be filled out");
return false;
}
}
</script>
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
OK.
Add a type attribute with value "button" to the button elements. Otherwise, the default type value would be 'submit'.

Official documentation:
https://www.w3.org/TR/2011/WD-html5-2...
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Alhumdulillah, now it's working fine, this was only the reason, thats y it was behaving like submit button, and both problems solved when i usedtype="button"Its also not doing empty fields. Thank You Petra, Like always You are here with me, havn't words to pay yout thanks:)
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Good Morning Dear Petra,
with lots of trials I made validation for 'Email or Mobile Number field' and It's now working fine, have a look:

var email = document.getElementById('emailphn');
var mailFormat = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})|([7-9]{1}[0-9]{9})+$/;
if (email.value == "") {
alert( " Please enter your Email or Phone Number ");
}
else if (!mailFormat.test(email.value)) {
alert( " Email Address / Phone number is not valid, Please provide a valid Email or phone number ");
return false;
}

have a form look now, i made it beautiful :D.


but i have a little problem now:
When I am capturing picture, its showing in image block, and when I am uploading the image it's also showing in the image block, Can't I do like this: that whenever i capture image it show only captured image, ? and when i upload image it how only uploaded picture in the image block? and vice versa?
I mean only one image can hold in the image block which is used after.
It's a snap shot below i am facing problem
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, How're You?
are you okay?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Fine.
Then only show one image, not both. Clear the image area first, before adding a new one.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Then which one? IMAGEURI or IMAGE DATA?
see java script:

<script type="text/javascript" charset="utf-8">

var pictureSource; // picture source
var destinationType; // sets the format of returned value

// Wait for Cordova to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);

// Cordova is ready to be used!
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}

// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);

// Get image handle
//
var smallImage = document.getElementById('smallImage');

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}

// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageURI) {
// Uncomment to view the image file URI
console.log(imageURI);

// Get image handle
//
var largeImage = document.getElementById('largeImage');

// Unhide image elements
//
largeImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
largeImage.src = imageURI;
}

// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.FILE_URI,
sourceType: source });
}

// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}

</script>

HTML



<table border=0 width=100%><tr><td><button type="button" onclick="capturePhoto();" class="btn"><img src="images/placeholder.png" width="30" height="25" align="center">Take Photo</button> </td><td>
<button type="button" onclick="getPhoto(pictureSource.PHOTOLIBRARY);" class="btn">+Upload Image</button>
</td></tr></table>
<br>
<img style="display:none;width:120px;height:120px;" id="smallImage" src="" />
<img style="display:none;width:120px;height:120px;" id="largeImage" src="" />
<input type="submit" value="Submit" class="button button-pill button-action button-large">
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
You have the value for destinationType attribute wrong. Follow the plugin docs exactly...not more or less.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
I read the documents, but in which function , destinationType value is wrong? in capturephoho() or getPhoto()?
and which value should i use?
Both are showing images in image area, but I want in same image area i cud use img src, of getphoto if a user files take photo option , and it will be change in img src of getPhoto(source), if a user upload the pic.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
The value should be Camera.DestinationType.DATA_URL
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
1.Petra, u want i use DATA_URL instead of FILE_URI, because i want image in same image area?
2.I kept the value of DestinationType.FILE_URI because i read the following statement regarding DestinationType.

Ok may be because we are not using File Uri we r using base64 images, i m changing it. thank you
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
PETRA:
You just give me this answer please, i am going too much confused:
destinationType's value will be same for both functions? e.g. capturePhoto() & getPhoto(source) ?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Yes.
However, YOU must decide whether you want base64 or not. That's an application decision. Both are valid choices.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Good Morning, How r u?
I was asking because u said, read docs carefully, and whenever I read about capture photo and getphoto, everywhere they used FILE_URI for get photo from Library, When u said , i changed the value of FILE_URI to DATA_URL, It's giving option to select a photo from Library but not showing thumbnail, Look:


and when I am using FILE_URI, it's showing thumnail in Image area: Please tell me what I do?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Yes!!!!!!!!!!!!!!! I did, It's working Now as I want but still want, that Petra please check once my coding.
thanks in advance:

<script type="text/javascript" charset="utf-8">

var pictureSource; // picture source
var destinationType; // sets the format of returned value

// Wait for Cordova to connect with the device
//
document.addEventListener("deviceready",onDeviceReady,false);

// Cordova is ready to be used!
//
function onDeviceReady() {
pictureSource=navigator.camera.PictureSourceType;
destinationType=navigator.camera.DestinationType;
}

// Called when a photo is successfully retrieved
//
function onPhotoDataSuccess(imageData) {
// Uncomment to view the base64 encoded image data
// console.log(imageData);

// Get image handle
//
var smallImage = document.getElementById('smallImage');

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}

// Called when a photo is successfully retrieved
//
function onPhotoURISuccess(imageData) {
// Uncomment to view the image file URI
// console.log(imageURI);

// Get image handle
//
var smallImage = document.getElementById('smallImage');

// Unhide image elements
//
smallImage.style.display = 'block';

// Show the captured photo
// The inline CSS rules are used to resize the image
//
smallImage.src = "data:image/jpeg;base64," + imageData;
}

// A button will call this function
//
function capturePhoto() {
// Take picture using device camera and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function capturePhotoEdit() {
// Take picture using device camera, allow edit, and retrieve image as base64-encoded string
navigator.camera.getPicture(onPhotoDataSuccess, onFail, { quality: 20, allowEdit: true,
destinationType: destinationType.DATA_URL });
}

// A button will call this function
//
function getPhoto(source) {
// Retrieve image file location from specified source
navigator.camera.getPicture(onPhotoURISuccess, onFail, { quality: 50,
destinationType: destinationType.DATA_URL,
sourceType: source });
}

// Called if something bad happens.
//
function onFail(message) {
alert('Failed because: ' + message);
}
</script>
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
I'm a bit shocked.

Above, I spelled out for you what the value of attribute 'destinationType' should be:

The value should be Camera.DestinationType.DATA_URL

And yet, you still have

destinationType: destinationType.DATA_URL,

==============

I was asking because u said, read docs carefully, and whenever I read about capture photo and getphoto, everywhere they used FILE_URI for get photo from Library, When u said , i changed the value of FILE_URI to DATA_URL
I did not tell you to use DAT_URL instead of FILE_URI (and in fact NATIVE_URI would be even better than FILE_URI)! I just gave you an example of the proper classes to use when specifying the destinationType.

I also said (6 days ago) that you need to decide which of both you want to use:
- file format
- base64 format
That decision will determine the field type of image in your database and the way you want to retrieve the image in the backend (in other words: how do you want to display the image to the community's responsible person?).

Apart from that, you have still more decisions to make, which I already pointed out a week ago:
- have you decided what you want your app to do if it goes offline?
- have you decided what you want your app to do if no such services are available?
- do you meanwhile have an app id, as approved by the community?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Sorry Petra, actually I updated ysteday when u said, and again I copied code from my backup data, I forgot to change destinationType value. :( Sorry
1.The second things, can we store both images in base64 encoding, as I did above?
If not then capturephoto() with DATA_URL and getphoto() with NATIVE_URI, right?
Petra all decisions are up to you, you just tell me do this, and I will.
-Obviously they want to see picture in DATA_URL not only File url.
Some more Decisions
-If a user file a complaint without having internet connection, and will try to submit offline, a dialog box will apear with message: "Check you Internet Connection"
-a dialog box with service is not available at your device/
-I created an app ID, by google?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Petra all decisions are up to you, you just tell me do this, and I will.
Oh no! Certainly not! That would spoil all the fun.
It is you who makes the decisions, and I who will tell you that your decisions are wrong. That's how we are playing this project.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra what happened to you since yesterday?
May be you are tired or irretated from me now.
-It was you hu suggest me to use static map image,
-it was you hu want to store base64 encoding images.
and blah blah blah,
I am not saying that everything you decide for my app, but truth is that the app which is now stand, only by u, by your guidance i could do this.
You are experienced ITian.
I am just asking for better for me.
Promise I will not appear here again once my app got completely build.
Thanks for your favors.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Petra what happened to you since yesterday?
Nothing. My above remark was supposed to be half-way funny.
(But bots aren't good at humor)
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
My Heart say you are human :) not bot.
-I can guess, that you are near about 45-50 years old man.
isn't?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
No, that's my grandson from first marriage.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Hahaha, really you are doing fun here :D, You mean bots have grandson, and they do marriage also LOL :D
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
I have much time for fun, I am not like all, i want to run now, how much i can, then there is lots of time for rest ahead In Shaa Allah.
See dashboard now:

before i go ahead, I want you check my enable/disable coding, it's working fine, though.

function EnableDisableTextBox(mycheck) {
var locationtxt = document.getElementById("locationtxt");
locationtxt.disabled = mycheck.checked ? true : false;
locationtxt.style.background = "#DDD";

if (!locationtxt.disabled) {
locationtxt.focus();
locationtxt.style.background = "#12192C";

}
}
function EnableDisableTextarea(othercheck) {
var otherdescription = document.getElementById("otherdescription");
otherdescription.disabled = othercheck.checked ? false : true;
student.disabled = othercheck.checked ? true : false;

otherdescription.style.background = "#DDD";

if (!otherdescription.disabled) {
otherdescription.focus();
otherdescription.style.background = "#12192C";

}
else
{
student.focus();
}
}
</script>

-if a user will fill the Location text in text field, He can'r choose current location, and when he will try to choose current location, the LOCATION TEXT field will disable.
-if a user will choose complaint type from pick list, the other description field will be disable, and when He will click on other, the pick list will be deactivate.
Is it correct?

I also created a small form for check complaint status.
with Validation of complaint type number.
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
The variable 'student' is undefined.
What do you have such variable for?
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
Petra, actually it's id name of Complaint type pick list.
<select name=student id=student>
<option value="">-Complain Regarding to:-</option>
</select>
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
For documentation purposes, you should change it. Suppose the community wants someone else to take over development, how is this person supposed to understand what 'student' stands for?

Anyway, that variable 'student' in the script is still undefined, because you don't have it set to the form element object.
Photo of Saba Rais

Saba Rais

  • 724 Posts
  • 3 Reply Likes
I used here when i fetch data from picklist using json.

<script>
$(document).ready(function() {
//////////////////////
$.getJSON("compltype-data.php", function(return_data){
$.each(return_data.data, function(key,value){
$("#student").append("<option value=" + value.compltypeid +">"+value.description+"</option>");
});
});
//////////////////////
////////////
$('#student').change(function(){
//var st=$('#student option:selected').text();
var st=$('#student').val();
alert(st);
});
/////////////////////
});
</script>

compltype-data.php

<?Php
require "config.php"; // Database Connection

$sql="select compltypeid, description from compltype where active='y' order by description asc ";
$row=$dbo->prepare($sql);
$row->execute();
$result=$row->fetchAll(PDO::FETCH_ASSOC);

echo json_encode(array('data'=>$result));
?>


-Yes you are right I should use meaningful variable names.