This is a discussion on Problem with adding value to form textbox using jQuery within the Coding Help forums, part of the Webmaster Help category; I am going out of my mind with what I would typically believe to be a trivial problem... I have ...
| |||||||
| Register | Forum Rules | FAQ | Donate | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I am going out of my mind with what I would typically believe to be a trivial problem... I have a page with a form. In the form I have a selection box and a few text boxes. When I change the selection box value to zero it should clear the text boxes, and when I change the selection box to any other value it sets the text boxes to other values (which it gets from an ajax call). This all works fine using the following code which I call from my jQuery document.ready event handler. Code: if($("select#myselboxID").val() != 0){ // if my selection box value is not zero
$.ajax({ type: "POST", url: "includes/ajax/getDetails.php?id=" + $("select#myselboxID").val(), dataType: "xml", success: function(xml){
$("form input#name").attr("Value", $(xml).find('name').text());
$("form input#phone").attr("Value", $(xml).find('phone').text());
$("form input#email").attr("Value", $(xml).find('email').text());
$("form textarea#_address").text($(xml).find('address').text());
}});
}
else{ // if my selection box value is zero
$("form input#name").attr("Value", "");
$("form input#phone").attr("Value", "");
$("form input#email").attr("Value", "");
$("form textarea#address").text("");
}
Could someone please explain to me why this is happening? I feel like there is something significant about how a browser works with form values that I'm clearly unaware of. Many Thanks |
| ||||
| I have something that's doing something similar (but not exactly the same). I use: Code: $('.display_reply').click(function(){ // if a button is clicked
$('textarea, :text').val(''); // empty a text area & all text boxes
});
Have you tried using .val() instead of setting the .attr() ? Also, how is the code you posted being triggered? Could it be to do with the event you're using when the select box is changed?
__________________ Not Work: My blog Work: Website Design Galway A little app: Twiteye.com (Application, software & service ideas from Twitter) |
| ||||
| Cheers davkell for your reply Quote:
I just tried using val() to init the values of the form components and it worked a charm!! - fair play So there's a difference between using val("") and .attr("Value", "") it would appear. At one level they work the same and then on another, they don't. All the best |
| ||||
| No bother, good to see it worked for you! |
| Tags |
| adding, form, jquery, problem, textbox |
| Thread Tools | |
| Display Modes | |
| |
| ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Is this possible? (Ajax & JQuery Document Scope Problem) | jason | Coding Help | 4 | 01-07-2008 02:07 PM |
| Can anyone recommend a text editor (textbox) like TinyMCE for websites? | dude | Webmaster Discussion | 11 | 13-04-2007 04:45 PM |
| Drupal, problem with adding content by a privilaged user | MacKozer | CMS and Content Management | 1 | 11-04-2007 11:06 AM |
| ||||
| | ![]() | |||
| | ||||