By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,238 Members | 1,661 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,238 IT Pros & Developers. It's quick & easy.

checking the value of a submit button

P: 31
I have the following code:

Expand|Select|Wrap|Line Numbers
  1.  <script type="text/javascript"> 
  2.  
  3. function displayRow(){ 
  4. var ET = document.getElementById("ExpenseTable");
  5. var    row3 = document.getElementById("searchbutton");
  6.  
  7. If row3.value == 'search' {
  8. if (row2.value == 'Expenses') {
  9.          ET.style.display = '';
  10.          }
  11. }
  12. </script>
  13.  
  14.  
  15. <input type="submit" name="searchbutton" id="searchbutton" value='search' border="0" onClick="displayrow();return false;">
  16.  
  17.  
I want to do special things in Javascirpt function(displayrow) 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?
Jun 9 '08 #1
Share this Question
Share on Google+
4 Replies


P: 31
Hi,

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


Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2.  
  3. function displayRow(){ 
  4. var ET = document.getElementById("ExpenseTable");
  5. var row3 = document.getElementById("searchbutton");
  6.  
  7. If row3.value == 'search' {
  8. if (row2.value == 'Expenses') {
  9.          ET.style.display = '';
  10.          }
  11. }
  12. </script>
  13.  
  14.  
  15. <input type="submit" name="searchbutton" id="searchbutton" value='search' border="0" onClick="displayrow();return false;">

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
Jun 9 '08 #2

gits
Expert Mod 5K+
P: 5,390
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
Jun 10 '08 #3

DrBunchman
Expert 100+
P: 979
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.
Jun 10 '08 #4

jeffstl
Expert 100+
P: 432
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.
Jun 10 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.