Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why document.getElementById for hidden input works in IE but not Chrome?

i have a problem with this part of js code not working in Chrome but working in IE.

this is my javascript code :

function submitformWithPage(xpage)
{

  document.getElementById('itempage').value = xpage;
 alert(xpage);
  document.searchForm.submit();

}

and this is my html code

<form name="searchForm" action="search.php" method="get">

<input  type="text" name="search" value="<?php if(isset($_GET['search'])) { echo $_GET['search']; } ?>"/>
<input type="hidden" name="parameter" value="test" />
<input id="item" type="hidden" name="itempage" value="1" />
<input type="hidden" name="pageBigForward" value="10" />
<input type="hidden" name="pageSmallForward" value="1" />

<button style="" onclick="javascript: submitform()">Search</button>

</form>

I submitted the form by using this code and it works in IE but not in Chorme.

<button style="" onclick="javascript: submitformWithPage(3);">3</button>

I am lost on how to solve this problem.

Can anyone help me ?

Thanks in advance.

like image 773
Melvin Avatar asked Dec 06 '22 21:12

Melvin


1 Answers

Your input has the name of itempage, not the id.

<input id="item" type="hidden" name="itempage" value="1" id="itempage"/>

Using names-as-ids is only supported in IE5-7!

like image 169
Matt Avatar answered Jan 26 '23 01:01

Matt