Jump to content

Can't get a real value with: document.getElementById(keyword1).value;


JoshEir
Go to solution Solved by Barand,

Recommended Posts

I have the following code which is passing the variables to:  SaveProductItems(...  unfortunately, the passed values are being set to:  ""   They do not work with .value or without.  I need help please.  

 

	$imageID = $_GET['imageID'];
	$fileID = $_GET['fileID'];
	$descID = $_GET['bdescID'];
	$title1    = $_GET['title1'];
	$productID = $_GET['productID'];
	 $titleID = $_GET['btitleID'];
	 
	 $costID = $_GET['bcostID'];
	 $quantityID = $_GET['bquantityID'];
	 $key1ID  = $_GET['bkey1ID'];
	 $key2ID  = $_GET['bkey2ID'];
	 $key3ID  = $_GET['bkey3ID'];
	$gKeyword1   = $_GET['gKeyword1'];
	$gKeyword2   = $_GET['gKeyword2'];
 	$gKeyword3  = $_GET['gKeyword3'];
  	$image      = $_GET['image'];
   	$description  = $_GET['description'];
	$cost    = $_GET['cost'];
	$quantity   = $_GET['quantity'];
	$category = $_GET['category'];

$string0 =  "  


<p id = \"link1\">product id   :$productID</p>
<div style = \"background-color:#40e0d0;\" class = \"A\" id = \"$mainDiv\">
<center><h1>Added Record<h1></center></p>
<div class=\"container\">


  <div class=\"row\" >

	
	<div class = \"col\">

	<iframe id=\"upload_target\" name=\"upload_target\"  style=\"width:0;height:0;border:0px solid #fff;\"></iframe> 	
	
	
	<div class=\"text-left\">

	<form   target=\"upload_target\"  method = \"POST\" action = \"upload2a.php\" enctype=\"multipart/form-data\">
	
	<input type=hidden id=\"$productID\" name= \"productID\" value=\"$productID\">
	<!--
	<input type=hidden id=\"$filename\" name=\"filename\" value=\"$filename\">
	-->
	
	<input  type = \"file\" name = \"file\" id = \"$fileID\">
	<br><br>
	<button    value = \"Submit\" type = \"submit\"  >submit it</button>
	
	
	</form>

	<div id = \"text-left\">
	<button    onclick = \"imageRefresh( '{$filename}', '{$imageID}')\" >Confirm</button><br><br>
	</div>

	</div>

	<img class=\"NO-CACHE\" width=\"120\" height =\"120\"  id = \"$imageID\"  src=\"http://localhost/phpproj/uploads/$filename?<?php filemtime('$filename') ?>\">No Image</img>
	
	
	</div>
	
	<div class=\"col\"><br><br><br><br>
      <h4><center><p id =\"\"  >Title</p></center></h4>        
      
	<center><p>      <input id = \"$titleID\" value = \"$title1\" type=\"text\" name=\"\" placeholder=\"\"></p></center>
    </div>
	
	
	<div class=\"col\">
      <h4><center><p id = \"\">Desc</p></center></h4>
      
	  <center><textarea wrap id = \"$descID\"   value = \"$description\"  name=\"text\" rows=\"5\" cols=\"34\">$description</textarea></center>
	  </div>
    
	<div class=\"col\"><br><br>
      <h4><center><p id = \"\" >Cost</p></center></h4>
	<center><p>	<input id = $costID value = $cost type=\"number\" name=\"title\" placeholder=\"$cost\">		</p></center>
	
	</div>
	

	</div>
	</div>


	<div class=\"container\">
	  <div class=\"row\" >
	  
	<div class=\"col\">
    <h4><center><p id = \"\" >Quantity</p></center></h4>    
	<center><p> <input id = $quantityID value = $quantity type=\"number\" name=\"title\" placeholder=\"$quantity\">	</p></center>
	</div>

	<div class=\"col\">
      <h4><center><p id = \"\" >Keyword 1</p></center></h4>
	<center><p>	<input id = \"$key1ID\" value = \"$gKeyword1\" type=\"text\" name=\"title\" placeholder=\"$gKeyword1\">		</p></center>
	
	</div>


	<div class=\"col\">
      <h4><center><p id = \"\" >Keyword 2</p></center></h4>
	<center><p>	<input id = \"$key2ID\" value = \"$gKeyword2\" type=\"text\" name=\"title\" placeholder=\"$gKeyword2\">		</p></center>
	
	</div>


	<div class=\"col\">
      <h4><center><p id = \"\" >Keyword 3</p></center></h4>
	<center><p>	<input id = \"$key3ID\" value = \"$gKeyword3\" type=\"text\" name=\"title\" placeholder=\"$gKeyword3\">		</p></center>
	
	
	</div>
	

	<br><br>
	</div>
	</div>
	

<div class=\"container\">
  <div class=\"row\" >


	<!-- the keys are   -->
	<div class=\"col\">
      ////////////////////////////////////////////
      //////////////////Failing funtion call://////
      ////////////////////////////////////////////
      <center><button id = \"\" onclick = \"SaveProductItems(  '{$productID}',  '{$deleteFlag}', '{$mainDiv}',   '{$titleID}', '{$descID}', '{$costID}','{$quantityID}', '{$key1ID}' , '{$key2ID}' , '{$key3ID}'  )\">Resubmit</button></center>
    
	
    <center><button id = \"\" onclick = \"deleteRecord(1, '{$mainDiv}', '{$productID}' )\">Delete</button></center>

	</div>
	

	
</div>
</div>	
	


</div><!--mainDiv-->
";//stringend

insertNewRecord( $fileID, $filename, $title1, $descID ,$productID, $titleID  ,$costID ,$quantityID,$key1ID  ,$key2ID  ,$key3ID  ,$gKeyword1 , $gKeyword2  ,$gKeyword3  ,$image     ,$description,  $cost    ,$quantity ,  $category  );


if (!isset($myObj) && isset($string0))
{
$myObj = new stdClass();
$myObj->htmlstuff = $string0;


//Encode the data as a JSON string
$jsonStr = json_encode($myObj);
echo $jsonStr;


}

 

 And here is the Javascript function that sets the values to "" or  [object HTMLTextAreaElement.

 

function SaveProductItems( ProductID, deleteFlag , maindiv, title, desc, cost, quantity, keyword1, keyword2, keyword3){


		
		const element = document.getElementById("dropDown1");
		
		const checkValue = element.options[element.selectedIndex].value;
		const checkText = element.options[element.selectedIndex].text;
		
		var val13 = checkText;

	//changed these
	var val1 = document.getElementById(title);
	var a = val1.value;
	
//////////////////////////////////////////
//////////////PROBLEM HERE://////////////
/////////////////////////////////////////
	var val2 = document.getElementById(desc).value;
	var val3 = document.getElementById(cost);
	var val4 = document.getElementById(quantity);
    var val5 = ProductID;
	var val8 = document.getElementById(keyword1).value;
    var val9 = document.getElementById(keyword2).value;
	var val10 = document.getElementById(keyword3).value;
	//var val11 = document.getElementById(fileID).attributes.value.textContent
	//var val11 = document.getElementById(fileID).value;
	//var val11 = $('input[type=file]').val().replace(/C:\\fakepath\\/i, '')
	

	//var val14 = category;
	//var val15 = customerid;
	
	if (deleteFlag == 1)
	{
		document.getElementById(maindiv).innerHTML = "";
	}

    var xmlhttp = new XMLHttpRequest();
	var PageToSendTo = "saveNewRecord.php?";
	var UrlToSend = PageToSendTo  +   "val1=" + val1 + "&" + "val2=" + val2 + "&" + "val3=" + val3 + "&"  + "val4=" + val4 + "&"
        + "val8=" + val8 + "&" + "val9=" + val9 + "&" + "val10=" + val10 + "&" + "val5=" + val5 + "&" + "val13=" + val13 + "&" + /*"filename=" + val11  		"&" +*/ "pdib=" + ProductID;

  xmlhttp.onreadystatechange = function() {
		
	if (this.readyState == 4 && this.status == 200) {
		}
	};

	
	xmlhttp.open("GET", UrlToSend , true);
	
	xmlhttp.send();
	
}

Thank you for your help,

JoshEir

Link to comment
Share on other sites

I'm no guru, but it looks like I'm the only one around right now, so I'll say this:

I believe you need quotation marks around the item in parentheses.

Quote

You have

var val9 = document.getElementById(keyword2).value;

Should be

var val9 = document.getElementById("keyword2").value;

Try fixing that on a variable and see if anything changes.

Link to comment
Share on other sites

I do want the decimals to work as well.  I'm no guru either, but because keyword1 is a variable it won't work with quotes.  As far as PHP is concerned This seems to be the last question for my ecommerce site project.  Next should be Golang with Javascript again.  Please help me succeed.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.