Form’s array element in javascript


Hits: 1481  

How to access form’s array element in javascript?

Web Post
Mobile Post
Application Post
Open Source Post

Solution:

<form action=”<?=$_SERVER[‘PHP_SELF’]?>” method=”post”>

<input name=”post[]” type=”checkbox” value=”web” /> Web Post
<input name=”post[]” type=”checkbox” value=”mobile” /> Mobile Post
<input name=”post[]” type=”checkbox” value=”application” />Application Post
<input name=”post[]” type=”checkbox” value=”open” /> Open Source Post

</form>

<script type=”text/javascript”>
for(i=0;i
{

if(document.sv.elements[i].type==”checkbox” && document.sv.elements[i].name==”post[]”)
{

if(document.sv.elements[i].checked==true)
alert(document.sv.elements[i].value);

}

}
</script>

Published by

Sandeep Verma

I’m an Entrepreneur. I’m proud to work as Blogger, LAMP Programmer, Linux Admin, Web Consultant, Cloud Manager, Apps Developer, Searcher. Concentrate > Observe > Imagine > Launch