views:

275

answers:

8

I have just done the code for submit the form using JavaScript.

It works in all browsers except in Internet Explorer 6.

I have pasted my HTML form and JavaScript code below.

Can you please find what's the problem with it?

JavaScript:

    <script type="text/javascript" language="javascript">
    function dodelete(image_id)
    {
        if (confirm("Are you sure want to delete this image?"))
        {
            document.getElementById('image_id').value=image_id;
            document.del_form.submit();
        }
    }
    </script>

HTML Code:

    <form name="del_form" id="del_form" method="post">
        <input type="hidden" name="do" id="do" value="delete" />
        <input type="hidden" name="image_id" id="image_id" />
    </form>

Function Call Code:::

<p class="video">
  <a href="javascript:void(0)" onclick="dodelete('<?php echo $row['image_id']?>')">         
    <img src="<?php echo $cfg->admin_image_path; ?>/delete_icon1.gif" border="0" alt="Delete"/>
   </a>
</p>
A: 

OnSubmit call for javascript would help.

<form name="del_form" id="del_form" onsubmit="dodelete(value);" >
    <input type="hidden" name="do" id="do" value="delete" />
    <input type="hidden" name="image_id" id="image_id" />
</form>
TuxGeek
hi,here onclick of delete image, after confirmation it will write the image is to the hidden field and submit that form.So here form is used to just hold the image_id.
Avinash
A: 

There are two things I'd like to try, I'm not sure why or when this doesn't work it seems random, first try to set a timeout for the submit :

document.doSubmit = function() {
    document.del_form.submit();
}
setTimeout("document.doSubmit();", 100);

Sometimes, just return something after the click works :

<input type="hidden" name="image_id" id="image_id" onclick="submitFormFunction(); return false;” />
Soufiane Hassou
hi thanks for your ans, but i m not getting what r u trying to explain? :-)
Avinash
Alternatives to make it work on IE6.
Soufiane Hassou
but in my functionality there is no onclick event of image_id.my js function will execute on click of the delete image.and it will fill the image id to the my del_form form.and after filling form it will submit the form using javascript..
Avinash
A: 

What happens if you replace:

    document.del_form.submit();

with:

document.getElementById('del_form').submit()
meder
no, its not working.
Avinash
When are you invoking `dodelete`? Do you get any errors? If so what are they?
meder
dodelete will invoke by clicking on the image, no i m not getting any erros.
Avinash
Does it change the value? Is your markup 100% valid? No duplicate ids? Can you post an example?
meder
yes its changing the value of the form hidden field image_id...
Avinash
K.. try alerting document.getElementById('foo') of the form, does it say object Object in IE6? And is your markup 100% valid?
meder
i have alerted the following code in js function.document.getElementById('image_id')its displaying only object not a object object in ie 6.Can be this is the problem with my script.
Avinash
A: 

Try to move method='POST' to the beginning of form element definition.

I mean -- method attribute should be the first attribute of form element.

If I remember well, this fixed some problems with submitting forms on IE6.

Grzegorz Gierlik
its not working
Avinash
A: 

I have edited your code a little bit.

<script type="text/javascript" language="javascript"> 
    function dodelete(image_id) 
    { 

        if (confirm("Are you sure want to delete this image?")) 
        { 

            document.getElementById('image_id').value=image_id; 
            document.del_form.submit(); 
        } 
 return false;
    } 
</script>

and the HTML with some test Image ID and it works in IE6

<form name="del_form" id="del_form" method="post" onSubmit="return(dodelete('2'));"> 
        <input name="do" id="do" value="delete" /> 
        <input name="image_id" id="image_id"  /> 
<input type="submit" value="Submit">
</form>
Shoban
+1  A: 

What is returned by:

document.getElementById('image_id')

It returns one INPUT element of collection of elements?

Try to replace:

document.getElementById('image_id').value=image_id;

with:

document.del_form.image_id.value=image_id;

Grzegorz Gierlik
no luck with this guys
Avinash
A: 

Let's try again :).

What happen after replacing:

onclick="dodelete('<?php echo $row['image_id']?>')">

with:

onclick="dodelete('<?php echo $row['image_id']?>'); return false;">

What exactly doesn't work with your code? Throw JS error, there is no server request, values in request are empty?

And (maybe the most important question) -- where is action attribute for your del_form form?

Grzegorz Gierlik
A: 

I think you have two image_id elements in your document. Try changing this:

<input type="hidden" name="image_id" id="image_id" />

To:

<input type="hidden" name="image_id" />

And this:

document.getElementById('image_id').value=image_id;

To:

document.del_form[ 'image_id' ].value=image_id;
Salman A