Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

issues with jquery Code

Posted on 2011-04-30
12
Medium Priority
?
357 Views
Last Modified: 2012-05-11
I had the following question and answered by gurvinder from jquery Zone

http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_26909012.html

i am facing some some awkward issue with the jquery onpropertychange method, if you guys follow up the qustion you will see th answer @ last has been accepted and it works!

The Problem i am facing is now that

If the value is already coming in the textfield, it is just skipping it away if i enter some value in the upper level textbox on whom it is dependant..

While it should add the entry into that field!

Please guide if needs more info, do let me know

Thanks
0
Comment
  • 6
  • 6
12 Comments
 
LVL 23

Expert Comment

by:cmalakar
ID: 35496889
You mean.. on page load, if the value is coming in the text field, then the text area and radio buttons should be enabled ?
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 35497154
yup
0
 
LVL 23

Accepted Solution

by:
cmalakar earned 2000 total points
ID: 35497252
Replace your script  with this.
<script>  
                        $(document).ready(function(){  
                                $(".ToBeED").attr("disabled", "true");  

                                $(".row input[type='text']").bind('propertychange',function(){  
                                        
                                        if ( $(this).val().length > 0 )  
                                        {          
                                                var id = $(this).attr("id");  
                                                $(this).parent().children(".ToBeED").removeAttr("disabled");
                                        }  
                                        else  
                                        {  
                                                $(this).parent().children(".ToBeED").attr("disabled", "true");
												$(this).parent().children(".ToBeED").attr("checked", "");         
                                        }  
                                });  
                                $(".row div input[type='text']").bind('propertychange',function(){  

                                        if ( $(this).val().length > 0 )  
                                        {          
                                                $(this).parent().parent().find(".ToBeED").removeAttr("disabled");
                                        }  
                                        else  
                                        {  
                                                $(this).parent().parent().find(".ToBeED").attr("disabled", "true");
												$(this).parent().parent().find(".ToBeED").attr("checked", "");         
                                        }  
                                });  
        
                               $(".row div input[type='text']").trigger('propertychange');
                               $(".row input[type='text']").trigger('propertychange');

                        });  

                </script>

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 35497328
Ok here i have changed a bit of code due to some not required conditions!

The issue is if i remove this jquery, the values coming FROM DB populate some textboxes, but if enable this, it clears all the fields and no value gets appeared inside that textboxes,

PS I cannot use another events instead of onpropertychange because this is a requirement




$(document).ready(function(){  
            $(".ToBeED").attr("disabled", "true");  
            $(".row input[type='text']").bind('propertychange',function(){  
                    if ( $(this).val().length > 0 )  
                    {          
                            var id = $(this).attr("id");  
                            $(this).parent().children(".ToBeED").removeAttr("disabled");
                    }  
                    else  
                    {  
                            $(this).parent().children(".ToBeED").attr("disabled", "true");
                            $(this).parent().children(".ToBeED").attr("checked", "");         
                    }  
            });  
           $(".row input[type='text']").trigger('propertychange');
    });

Open in new window

0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35497397
I dont see any problem with this jquery code.

Is it possible to attach whole html source from browser ?
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 35497638
The issue is there are other functions which also run the javascript functions but also on onpropertychange method like this

<input type="text" name="myname" onpropertychange="validateMyFunction();">

So validateMyFunction calls another function which filles value from one textfield into another,

So jquery comes in this role as you can see the code,, it is enabling/disabling the radio buttons just on the change in the value

now if there is value already exists on the textfiel, it vanishes if i use jquery, if a valid javascript functionality of same kind can be implemented so please let me know as jquery seems no viable solution to this!
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35497757
>>  if there is value already exists on the textfiel, it vanishes if i use jquery

Jquery code above is not vanishing value of any text field.
It is just disabling and enabling.

Probably in other javascript function, the value might be getting cleared.
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 35497852
i will get Mad!

onpropertychange is making me nuts!

if i disable jquery then it works and show the value
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35497858
if possible, please post whole html source.
0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 35497872
page is too big can't post :(
0
 
LVL 23

Expert Comment

by:cmalakar
ID: 35497896
if you can identify, which input text fields should be attached with the onpropertychange jquery handlers, we can attach the event handle to only those.

With whatever html you have provided, the solution was given.

Also, you can definitely do the same thing without using jquery, but it will be more code.

0
 
LVL 16

Author Comment

by:Gurpreet Singh Randhawa
ID: 35498071
well we can do like this for each textfield check if the value exists, enable the radio buttons well i prefer anything if any thing works for me instead

The textfield values are dynamic i mean they are not known they can be n levels of textfields

so was thinking of using the array to find the index of each textfield and if it is empty do nothing else make the radios enabled & start using them, if the textfield is empty and disabled, the releavnt radio buttons will be disabled too!!

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question