2

I have the following code and it's working but i want to use ( <a> ) tag instead of ( <input type='submit'> ). I am a beginner in php - I hope my question will be entertained. I have googled my problem but it didn't help me.

<html>
<head>
    <script type="text/javascript">

        function load(thediv, thefile)
        {
            //alert('works');
            if(window.XMLHttpRequest)
            {

                xmlhttp = new  XMLHttpRequest();
            }
            else
            {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            }
            xmlhttp.onreadystatechange = function(){
            if(!(xmlhttp.readystate == 4 && xmlhttp.status == 200))
            {
                    // alert('works');
                    document.getElementById(thediv).innerHTML = xmlhttp.responseText;
            }

            }
            xmlhttp.open('GET', thefile, false );
            xmlhttp.send();
        }
    </script>
</head>

<body>
    <input type='submit' value="submit" onclick='load('main','itc_result.php');'>
</body>

Sean Hogan
  • 2,902
  • 24
  • 22
Sadeel Anjum
  • 135
  • 2
  • 14

2 Answers2

0

favorite
i have following code and its working but i want to use ( <a> ) tage instead of "( <input type='submit'> ) " i am a beginner in php, hope my question will be entertained, i have goggled my problem but it didn't help me

<html>
<head>
    <script type="text/javascript">

        function load(thediv, thefile)
        {
            //alert('works');
            if(window.XMLHttpRequest)
            {

                xmlhttp = new  XMLHttpRequest();
            }
            else
            {
                xmlhttp = new ActiveXObject('Microsoft.XMLHTTP');
            }
            xmlhttp.onreadystatechange = function(){
            if(!(xmlhttp.readystate == 4 && xmlhttp.status == 200))
            {
                    // alert('works');
                    document.getElementById(thediv).innerHTML = xmlhttp.responseText;
            }

            }
   alert('sending ajax');
            xmlhttp.open('GET', thefile, false );
            xmlhttp.send();
          
        }
    </script>
</head>

<body>
  <div id="main" />
    <a href="#" onclick="load('main','itc_result.php');" >submit</a>
</body>

add the above into onclick of anchor tag like this

<a href="#" onclick="load('main','itc_result.php');" >submit</a>
Raghavendra
  • 3,530
  • 1
  • 17
  • 18
0

You can do it like:-

<a onclick="load('main','itc_result.php');">Click Me </a>.

But what it's need is not clear?Submit works fine.

Alive to die - Anant
  • 70,531
  • 10
  • 51
  • 98
  • Anchr tag given by you is working , but there is still a problem, when i click the anchor tag it shows the required page data but suddenly disapears ..! – Sadeel Anjum Aug 04 '15 at 07:01