0

I m new here and in HTML.Well I have to select many values from different areas (eg dropdown list, date input type, time input type etc) and compare them with a table. It select the value right,but it appears only for a sec in the screen and then it disappears!It seems that my Chrome refreshes!This is what i ve done till now..

//inside javascript

function Searching()
    {
        var a=document.getElementById('movies');
        var selMov=a.options[a.selectedIndex].value;
        var b=document.getElementById('areas');
        var selAr=b.options[b.selectedIndex].value;
        var c=document.getElementById('dat').type='date';
        var d=document.getElementById("tim").type='time';
        var rows=document.getElementById('dataProgram').getElementsByTagName('tr');
        document.getElementById("demo").innerHTML=selMov;

    }

And i have this <p id="demo"></p> to appear the result.

1
  • How is the function called? Commented Jan 24, 2013 at 23:12

1 Answer 1

1

You are not cancelling the event that triggers the function. So the page is reloading.

You need to return false or call event.preventDefault()

Edit:

based on the comment

<button type="submit" id="but" onclick="Searching(); return false;">Search</button>
Sign up to request clarification or add additional context in comments.

5 Comments

i tried with this,but it didn't work.i found this code,with no return false and is ok. <code> <!DOCTYPE html> <html> <body> <p>Click the button to check the age.</p> Age:<input id="age" value="18" /> <p>Old enough to vote?</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { var age,voteable; age=document.getElementById("age").value; voteable=(age<18)?"Too young":"Old enough"; document.getElementById("demo").innerHTML=voteable; } </script> </body> </html> <code>
How are you triggering the method Searching()?
<button type="submit" id="but" onclick="Searching()">Search</button>
and that is why. A button does not post back. A submit button does!
i add a loop and an if ,to have more than 1 results back.It works,but i want to have the results in radiobuttons so the user can choose only one. Is this possibly?

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.