-1

I have a div

<div id="force_id"></div>

This prints an id for each product on the page. Ex: 26588

How do I assign it to a hidden input value ?

<input name="" id="deger" type="hidden" value="<div id="force_id"></div>">   

Not like of course :=)

Extropy
  • 13
  • 1
  • 1
  • 5
  • 1
    so does it look like `
    26588
    `?
    – jmore009 Jan 18 '15 at 19:16
  • No, not like that. Value of their writing According to the product on the page where.
    = 38735 for example.
    – Extropy Jan 18 '15 at 19:23
  • 2
    @Extropy what do you mean `
    = 38735 for example` how does a div equal a number?
    – jmore009 Jan 18 '15 at 19:24
  • Yes I will post it with ajax. var parcel=$("#deger").val(); – Extropy Jan 18 '15 at 19:26
  • @jmore009 This div prints an id for each product on the page. 15423 writes in a page. in another 28763. That variables. It says #force_id – Extropy Jan 18 '15 at 19:30
  • @Extropy sorry but this is not making any sense. how does a div `print an id`. I think you need to explain further or post more code demonstrating what you're talking about – jmore009 Jan 18 '15 at 19:35

2 Answers2

0

First off all I think you question ambiguous and what ever you are trying to achieve through this kind of tag might not be a good way to do. I suggest you to look for alternative ways if possible.

<input name="" id="deger" type="hidden" value="<div id="force_id"></div>"> 

But if you insist this can be easily done. Treat the value like any other string value you would insert inside a div but this time you will need to escape the quote character as below

$("#deger").val('<div id=\"force_id\"></div>');
Bikal Basnet
  • 1,452
  • 1
  • 17
  • 27
0

Try this

$('#deger').val($('#force_id').text());

see the code snippet below

function doIt() {
  $('#deger').val($('#force_id').text());
}

// Just for testing what happens
var degerEl = document.getElementById('deger');
var resultEl = document.getElementById('result');
var doItBtn = document.getElementById('doItBtn');
doItBtn.addEventListener('click', doItOnClickCallback);
setResultElValue();

function doItOnClickCallback() {
  doIt();
  setResultElValue();
}

function setResultElValue() {
  resultEl.value = degerEl.outerHTML;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input name="" id="deger" type="hidden" value="">
<div id="force_id">26588</div>

<!-- Just for testing what happens -->
<button id="doItBtn">Do it</button><br/>
<textarea readonly id="result" style="font-family:monospace;width:400px"></textarea>

Scymex
  • 877
  • 9
  • 17