0

Please help me solve a problem on passing the value form javascript function to the 'hidden' form and the form will be submitted to the php code for processing the data. Here are my codes below:

First i have a link which will trigger the function 'passValue()' that holds 3 values.

<a href="javascript: passValue('1','student','1')">Pass Values</a>

Here in my script, i want to pass the data to a form and this values are hidden.

<script type="text/javascript">
function passValue(idNumber,userType,foreignNumber){
document.myForm.id.value = idNumber;
document.myForm.type.value = userType;
document.myForm.typeId.value = foreignNumber;
}
</script>

I assume that the values of the 'hidden' input forms are already set. So I trigger the submit button to send the data to php code which is in another page using a jquery and ajax(but i did not include it anymore in this post) so that the page would not refresh.

<form method="post" name="myForm" action="process.php">
<input type="text" name="myText" />
<input type="hidden" name="id" />
<input type="hidden" name="type" />
<input type="hidden" name="typeId" />
<input type="Submit" name="Submit" value="Send" />
</form>

Here is the php code 'process.php' that will receive the data sent by the form 'myForm'.

<?php
if($_POST){
$id=$_REQUEST['id'];
$type=$_REQUEST['type'];
$typeId=$_REQUEST['typeId'];
}
?>

Problem: I found out that the values of the hidden forms are empty or no values has been set. In this case i assume that the data that has been set by the javascript for those 'hidden' forms cannot be passed to another page or code. Please help...what should i do?

2
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by McLaren
0

Problem: I found out that the values of the hidden forms are empty or no values has been set.

They are set. I made some testings:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
function passValue(idNumber,userType,foreignNumber){
document.myForm.id.value = idNumber;
document.myForm.type.value = userType;
document.myForm.typeId.value = foreignNumber;

console.log($('input[name=id]').val());
}


</script>

so in the console I see 1.

So probably there is something wrong in you php code. I don't know much about pure php, but with codeigniter I made this:

function test2()
{
echo $this->input->post('id');
	  }

and it echoes 1.

0

Problem: I found out that the values of the hidden forms are empty or no values has been set.

They are set. I made some testings:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js" type="text/javascript"></script>

<script type="text/javascript">
function passValue(idNumber,userType,foreignNumber){
document.myForm.id.value = idNumber;
document.myForm.type.value = userType;
document.myForm.typeId.value = foreignNumber;

console.log($('input[name=id]').val());
}


</script>

so in the console I see 1.

So probably there is something wrong in you php code. I don't know much about pure php, but with codeigniter I made this:

function test2()
{
  echo $this->input->post('id');
}

and it echoes 1.

Double post because preesed tab while editing and then something so it posted.

Edited by McLaren: Damn misclics :)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.