tags:

views:

754

answers:

2

In safari, Im trying to insert a Hidden field into the DOM then update its value as below.

colHiddenFieldId = 'row_100000_0_NewValue'  

$("#" + colHiddenFieldId).val('TEST')

However the value is never getting set, it looks Safari dosn't think the hidden field exists. I know it does because it works on every other browser known to man!!!

Is this a bad thing to do in safaris book?

+2  A: 

Are you positive you're not missing a '0' in the name, or maybe adding too many? You can see if Safari has access to it by cycling through all hidden fields and alerting their ID:

Assuming the field exists already...

$("input[type='hidden']").each(function(){
  alert($(this).attr("id"));
});

Creating the field...

var myId = "someIdHere";
$("<input />")
  .attr("type","hidden")
  .attr("id",myId)
  .val("Something")
  .appendTo("body");
Jonathan Sampson
+2  A: 

It doesn't look like you're creating the hidden field -- unless you've left that part of your code out.

You need something like this:

// set the name of the hidden field
var colHiddenFieldId = 'foo';

// create the hidden field (insert it)
$("#yourForm").append("<input type='hidden' id='" + colHiddenFieldId + "' name='" + colHiddenFieldId + "' value='TEST' />");

If you've taken a different approach to inserting the hidden field, it might help to post that code as well.

bigmattyh