checking the value of a submit button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • F159753
    New Member
    • Apr 2008
    • 31

    checking the value of a submit button

    I have the following code:

    Code:
     <script type="text/javascript"> 
     
    function displayRow(){ 
    var ET = document.getElementById("ExpenseTable");
    var	row3 = document.getElementById("searchbutton");
     
    If row3.value == 'search' {
    if (row2.value == 'Expenses') {
    		 ET.style.display = '';
    		 }
    }
    </script>
     
     
    <input type="submit" name="searchbutton" id="searchbutton" value='search' border="0" onClick="displayrow();return false;">
    I want to do special things in Javascirpt function(displa yrow) only if the value of submit button (searchbutton) equals to "search". ( Basically only if this button had been pressed)

    right now every time I go to the form, the stuff in the javascirpt is happening but I want them to be place only if the search button had been pressed!

    do you know how?
    Last edited by DrBunchman; Jun 9 '08, 09:17 PM. Reason: Added code tags - Please use the # button
  • F159753
    New Member
    • Apr 2008
    • 31

    #2
    Submit button in JavaScript

    Hi,

    I have the following part in my code in ASP and JavaScript:


    [CODE=html]<script type="text/javascript">

    function displayRow(){
    var ET = document.getEle mentById("Expen seTable");
    var row3 = document.getEle mentById("searc hbutton");

    If row3.value == 'search' {
    if (row2.value == 'Expenses') {
    ET.style.displa y = '';
    }
    }
    </script>


    <input type="submit" name="searchbut ton" id="searchbutto n" value='search' border="0" onClick="displa yrow();return false;">[/CODE]


    Basically in the Javascript part I want to check if the Searchbutton has been pressed or not! I don't know how to do that?!
    Do you have any idea?

    Regards,
    FF
    Last edited by gits; Jun 10 '08, 06:53 AM. Reason: added code tags

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5388

      #3
      in case the function is called the search-button HAS BEEN clicked ... since you assigned the function to its onclick-handler. please explain your problem in more detail ...

      kind regards

      Comment

      • DrBunchman
        Recognized Expert Contributor
        • Jan 2008
        • 979

        #4
        Hi FF,

        You can be absolutely sure that the code in your function will only run when your submit button is pressed if the only place you call this function is from the onclick event of the submit button.

        Do you mean that the function appears to be called even if you don't click the submit button?

        Dr B

        PS Please can you start to use the # button when writing your posts to surround your code with code tags - it makes it much easier for everyone to read. Thanks.

        Comment

        • jeffstl
          Recognized Expert Contributor
          • Feb 2008
          • 432

          #5
          From what you posted that javascript should not execute until the button is pressed.

          How do you know its executing without the button? I don't believe that it would.

          The only way that would be possible is if you placed that function call in the <body onload> tag.

          Comment

          Working...