Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get value from div.

Is there a way to get the value from a div element within a form instead of using a input?

I know it's kinda a dumb question, but I just want to know if its possible. Something like PHP DOM?

Or is there a way to possible changing the div to an input when hitting submit?

Thanks,

like image 801
Brian Avatar asked Dec 27 '22 23:12

Brian


1 Answers

With Javascript, you can put the div's content into a (hidden) input right before you submit the form.

It will approximately look like this in jQuery:

$('#myForm').submit(function() {
  $('#myHiddenInput').val($('#myDiv').html());
});

Edit: Why are you guys talking about AJAX? There's no need of using AJAX in this situation!

like image 163
Samy Dindane Avatar answered Dec 29 '22 14:12

Samy Dindane