0

I have an html page that submits a form through javascript. Before submitting the form I change the value of a hidden tag which I then try to get in php but it doesn't work. It appears blank.

Here is the javascript

function remove(){



remove.value = 'true';


  document.newrow.submit() ;


}

The value for remove is set successfully however when I submit the form I get a blank value.

Here is the php code to retrieve the value.

$test = $_POST['remove'];


echo $test;

any idea why the value is blank?

Thanks

<form name = 'newrow' action = 'update.php' method = 'post'>


<input type='hidden' name='remove' id = 'remove' /><a href='javascript:remove()'><img src = 'images/delete.png' / ></a>
3
  • 3
    What does your packet sniffer say? Commented Apr 9, 2012 at 4:26
  • 1
    Can we have more source? For all we know, it's a GET form and remove is a DOM element that isn't even in it. Commented Apr 9, 2012 at 4:28
  • No I have not found a solution yet. Commented Apr 9, 2012 at 13:47

2 Answers 2

2
remove.value = 'true';

Is too ambigous. Try using document.getElementById('remove').value, assuming that the element has remove as its ID.

Sign up to request clarification or add additional context in comments.

2 Comments

@user541597: are you sure that form gets submitted?
yes I get to the php page, and I get other values for other tags.
0

You should do like this

<input type='hidden' name='random' id='random' />
<input type='submit' name='enter' value="Enter" onclick="remove" />

function remove() { document.getElementById("random").value='true'; }

//PHP part

if(isset($_POST['enter']))
{
   $ramdom=$_POST['random'];
}

The error probably is that you are submitting it twice

--Update for anchor tag

Here is what you're missing:

A link does not submit the form with input data, it just changes the url.
Submit the form.
Override the default <a> behavior (for example, using return false).

function random()  
{  
    document.getElementById("random").value = 'true';  
    document.getElementById("thisForm").submit();
    return false;
}  

You can call it using:

<a href="" name="enter" onclick="return random();">Enter </a>

3 Comments

how am I submitting it twice? I'm actually submitting once through javascript only.
I'm using an anchor tag to submit with javascript not a submit button.
Anchor tab does not post data use a submit button and make it look like a anchor tab using stylesheet

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.