JQuery val () issue in Firefox / Safari

I am trying to access a text field using jQuery code;

$("#pg_textbox").val();

But it does not return the correct value in Firefox / Safari ..

Even

$("#paging_textbox").attr("value") 

does not work.

In the firefox debugger, this says keyCode = 13, ...

But I want the actual value to be entered by the user. Please help me. Thank.

* Updated code

HTML

<input type="text" maxlength="5" size="2" value="1" id="paging_textbox">

Js

textValue = $("#paging_textbox").attr("value");
alert(textValue);
+3
source share
1 answer

Check the id / name of your text box.

HTML

<input type="textbox" id="pg_textbox" name="pg_textbox" value="Hello!" />
<input type="button" id="GetValue" name="GetValue" value="Get Value" />

Javascript :

$("#GetValue").click(function() {
  alert( $("#pg_textbox").val() ); 
});

Try checking out this sample on jsFiddle .

+3
source

All Articles