views:

49

answers:

2

Is there a way to change a value of a hidden field in the markup (with jquery or js) so I could use that new value once I'm out of the script (i.e. in a different script that would be triggered later)?

Lets say :

<form>
...
  <input type="hidden" name="prev_address" id="prev_address" value="no">
  <input type="hidden" name="prev_job" id="prev_job" value="non">
...
</form>

<script>
...
$('#prev_address').toggle( nbr_daysD < min_depuis_days ); 
document.form.prev_address.value = 'yes';

$('#prev_job').toggle( nbr_daysE < min_emploi_days ); 
// OR
$('#prev_job').value = 'yes';
...
</script>

The values are changing (if I use an alert) but not the markup...

Thanks

+4  A: 

jQuery uses .val() to get/set the value of an input (or select or textarea) element.

You want $('#prev_job').val('new value');

If you want to see the changed value, you can use Firebug to view the current DOM. The built-in "view source" feature of most browsers simply displays the original HTML as sent by the browser; no scripts are run against it so you will not see your changes.

meagar
A: 

If you modify a value after the page has been loaded, you can access that modified value with other scripts, but if you do a view-source on the page, you will see the original values.

chris