0

I am trying to find value of the input element in a popup window which is being opened from a parent page.

My code is below. I am getting not able to get pc value from input.

<html>
<head>
<? 
$pid=$_GET['pid'];
$cart_url = '../cart.php?action=add&p='.$pid;
echo $cart_url;
?>  
</head>

<body>
<SCRIPT LANGUAGE="JavaScript">
<!-- Begin
function sendValue(val){
window.opener.document.getElementById('details_<?=$pid?>').value = val;
window.opener.location.href='<?php echo $cart_url; ?>&pc='.concat(val);
window.close();
window.location.reload();
}
</script>
<form name="selectform">
<label>Enter Price:</label>
<input id="1" name="details_<?=$pid?>" type="text"></input>
<input   type="Submit"  onsubmit="sendValue(this.value)"></input>
</form> 
</body>
</html> 
1
  • 2
    You're using the getElementById method, but the ID value is equal 1 no equal "details_<?=$pid?>" Commented May 20, 2013 at 1:52

3 Answers 3

1

Code:

<input id="1" name="details_<?=$pid?>" type="text"></input>
<input   type="Submit"  onsubmit="sendValue(this.value)"></input>

Change to:

  <input id="details" type="text">
  <input type="button" value='Send...' onclick="sendValue(document.getElementById('details').value)">
Sign up to request clarification or add additional context in comments.

Comments

0

Just make your input box id from

<input id="1" name="details_<?=$pid?>" type="text"></input>

to

<input id="details_<?=$pid?>" name="details_<?=$pid?>" type="text"></input>

It should work

Comments

0

If you're using getElementById, you have to use pass the id of the element you're trying to get the value from (in this case 1).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.