Frage

i have a text box and i try to get value like this

var comment = $("input#diaMissedPucomments").val();

but the value is not fetched at the same time i have used this

$('input:checked').each(function() {
          selectedValues =$(this).val()+","+selectedValues ;
        });

to get values of selected check boxes it works fine.

<div style="display:none;" id="diaMissedPU" title="Missed P/U Comments" >
                       <table>
                            <tr>
                               <td>Enter Comments : </td>
                               <td><input tyep="text" id="diaMissedPucomments" name="diaMissedPucomments" /></td>
                           </tr>
                       </table>
                    </div>

the above is the HTML and i want to get the value of diaMissedPucomments

how to do this.

Pleas help me to get this.

Best Regards

War es hilfreich?

Lösung

It's just a mistyped tyep and must be fixed to type

<input tyep="text" id="diaMissedPucomments" name="diaMissedPucomments" />

must be

<input type="text" id="diaMissedPucomments" name="diaMissedPucomments" />

DEMO: http://jsfiddle.net/vnKza/1/

As dakait says enclose your Jquery codes to a Jquery ready handler

$(function(){
  var comment = $("input#diaMissedPucomments").val();
  //your other codes
});

Andere Tipps

You have typo change tyep="text" to type="text" Id of element is unique you can just use id selector there is no need of using input with id like input#diaMissedPucomments if id is unique.

Live Demo

var comment = $("#diaMissedPucomments").val();

i see you have spelled your input type wrong..

tyep="text" //here

should be

<input type="text" id="diaMissedPucomments" name="diaMissedPucomments" />

and jquery seems fine..

UPDATED

 $(document).ready(function(){  //make sure you have the javascript codes inside document.ready
    var comment = $("#diaMissedPucomments").val();
 });

like everybody has mentioned that you have a typo, plus make sure you have wrapped the code inside the ready handler

$(function(){
 //your code here 
});

why it work on jsfiddle then? because with default setting the fiddle wraps the code in document ready

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top