Solved

javascript value to html hidden input value

Posted on 2014-12-31
2
262 Views
Last Modified: 2014-12-31
On an e-commerce product page I have the add to basket button set to call a javascript function. The function creates 2 objects and for testing they are displayed in an alert box just before the last line of javascript fires the add to basket submit process.

alert(obj.image_id + ' AND ' + obj.image_name);
 
I've added 2 hidden input fields and I'm trying to set the value of these fields equal to the 2 javascript objects. Without any luck.

<html>
 <head> 
 <script>
  var req;
  function screenshot() {
	  $('#btncapture').val('Adding to cart...');
	  $('#btncapture').attr('disabled', 'disabled');
	  if (req) { req.abort(); } 
	  req = $.ajax({
		type: 'POST',
		url: 'screenshot.php',
		data: "containt="+$('#main-container').html().replace(/&/g, "%26"),
		cache: false,
		success: function(response){
			var obj = $.parseJSON(response);
			alert(obj.image_id + ' AND ' + obj.image_name);
			document.getElementById('newimage_id').innerHTML = obj.image_id;
			document.getElementById('newimage_name').innerHTML = obj.image_name;
			$('#PRODProducts').submit();
		}
	});
  }
</script>
</head>
<body>      
        <form NAME="PRODProducts" id="PRODProducts" method="post" action="Screen=BASK">
          <input type="hidden" name="Action" value="ADPR" />
          <input type="hidden" name="Product_Code" value="101" />
          <input type="hidden" name="newimage_id" id="newimage_id" value="overwrite this ID value" />
          <input type="hidden" name="newimage_name" id="newimage_name" value="overwrite this Name value" />
          <input type="hidden" name="containt" id="containt" value="" />
          <input id="btncapture" type="button" value="Add To Basket" onClick="screenshot()" class="wl-buttons" />
        </form>
</body>
</html>

Open in new window


Anyone have an idea of how to fix this?
Untitled.html
0
Comment
Question by:Gary Samuels
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 40526072
use :
			document.getElementById('newimage_id').value = obj.image_id;
			document.getElementById('newimage_name').value = obj.image_name;

Open in new window

or because you've jQuery :
			$('#newimage_id').val( obj.image_id );
			$('#newimage_name').val( obj.image_name );

Open in new window

0
 

Author Closing Comment

by:Gary Samuels
ID: 40526081
works great, thanks
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Finding original email is quite difficult due to their duplicates. From this article, you will come to know why multiple duplicates of same emails appear and how to delete duplicate emails from Outlook securely and instantly while vital emails remai…
Originally, this post was published on Monitis Blog, you can check it here . Websites are getting bigger and more complicated by the day. Video, images and custom fonts are all great for showcasing your product or service. But the price to pay in…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question