0

I am trying to assign an initial value to a text box with using jquery. This is the text field

  <input type="text" class="info"/>

This creates more than one text fields and I need to populate the text fields with initial values which come from database. I am having problem since I am trying to it with jquery adapter.

Any clue on this?

Thanks in advance.

Here is the detailed code:

I include index.html

       <?php include "index.html"?>;  

which puts some text fields to record.php: ... ...

After including index.html I am using this code to assign intial value to the text boxes which have a class name "info":

         $('.info').each(function() {
                $('.info').val('yourvalue');
            });

Instead of assigning a constant value (here it is "yourvalue") I am going to assing some database records to each input fields.

6
  • Does you code executes in in document.ready block? Commented Oct 15, 2012 at 10:00
  • no it does not work in that block. Commented Oct 15, 2012 at 10:17
  • 1
    $(document).ready(function() { ...your code ... }); ...this is required ... insted you may have other problems too Commented Oct 15, 2012 at 10:24
  • $(document).ready(function() { alert("dfds"); $('.info').each( function(index, item) { $(item).val('yourvalue'); } ); alert works here but it does not work here: $(document).ready(function() { $('.info').each( function(index, item) { alert("dfds"); $(item).val('yourvalue'); } ); seems like it does not get in $('.aciklama').each(); Commented Oct 15, 2012 at 10:30
  • do you have you code published somewhere? the thing you ask is very simple and may be there is something else which I can not realize ...give a link and 100 of people here will solve it in minutes Commented Oct 15, 2012 at 10:50

3 Answers 3

1
$('.info').val('yourvalue');

replace yourvalue with the value you want to set..

Set this value in the success callback of your ajax request..

Sign up to request clarification or add additional context in comments.

3 Comments

What exactly I am doing is including an html file in my .php page. This html file has several input text fields in it. After including the html file I tried this: $('.info').each(function() { $('.info').val('yourvalue'); });
Just including the HTML file will not help.. Are you reading that file in some way ??
Sorry but I could not understand your question. What did you mean by reading the file? I just wrote: <?php include "index.html";?>
0
$('.info').val('value-to-be-set');

.val( value ) - Set the value of each element in the set of matched elements

Above code will set the value of the input fields where the class name if 'info'

Read More here

11 Comments

What exactly I am doing is including an html file in my .php page. This html file has several input text fields in it. After including the html file I tried this: $('.info').each(function() { $('.aciklama').val('yourvalue'); });
I include some more detail in the initial question I posted.
I tried what you did in your demo also but it did not work. I guess I am doing something wrong with including the html file to my php file and trying to change the initial value of the inputs which are all sitting on that html file.
Cannot call method 'navigation' it explains itself. it means the method is not defined. which means method is not accessible.
status of 404 (Not Found) means path to the file is not set correctly. I guess once you fix these errors jquery thing will start working
|
0
 $('.aciklama').each(function() { $('.aciklama').val('yourvalue'); }); 

you know $('.aciklama') is an array , and when you iterator you array get the object, you still get the $('.aciklama') array and set the array value, as I see It is not correct. You should write like this:

$('.aciklama').each(function(index, item) { $(item).val('yourvalue'); }); 

7 Comments

I tried this one also and did not work. I wrote more detailed version of my code in the original post I wrote. could you please have a look at that since it seems like it is little confusing.
The code is not working or you don't know how to set related database values? What's the problem actually?
@complex05, Sorry, I write wrong code, the each callback function :first parameter is index, and second one is element object, if you want get the iterator element object, you can do like $('.aciklama').each(function(index, item) { $(item).val('yourvalue')// or this.val('yourvalue') this is your current iterator object; });
Did not work again. I guess I am doing something wrong with including the html file to my php file and trying to change the initial value of the inputs which are all sitting on that html file.
@complex05, now, First you alert the each item, if item return object, you alert($(item).val()), if it doesn't work(return undefined), That's to say we get wrong element object.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.