Results 1 to 7 of 7

Thread: Button function

  1. #1
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Button function

    Hi, I would like to ask if it is possible to do change a button function depending to the number of times it is pressed. For example if I click on the submit button and it changes to edit.

  2. #2
    Join Date
    Jul 2008
    Location
    Portugal
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Yes, and faster if you use AJAX to update your division.
    Say:
    <div id=xxx> <form..> <input..> <input type='button' value='submit> ... </div>
    The button shows "submit".
    When clicked, it goes to the server. The server replies:
    "fill <div id=xxx> with:
    <form..> <input..> <input type='button' value='edit'> ... "
    and so-on.
    With javascript, you could have image buttons, and swap images on each click
    i.e. <img src=button1 onclick='change_image(2)' ...>
    and
    function change_image(imno) {
    document.write... (where, ID)... with image # 2 }

  3. #3
    Join Date
    Sep 2005
    Location
    India
    Posts
    1,627
    Thanks
    6
    Thanked 107 Times in 107 Posts

    Default

    You can change the label of a button as well as its functionality using JavaScript. One demo page is below, which illustrates that.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    	<head>
    		<title>Untitled Document</title>
    		<style type="text/css">
    
    		</style>
    		<script type="text/javascript">
    		window.onload = function(){
    			document.forms['f1'].b1.onclick = firstState;
    		}		
    		var firstState = function(){
    			alert('You are in button\'s first state');			
    			document.forms['f1'].b1.value = "second state";
    			document.forms['f1'].b1.onclick = function(){
    				alert('You are in button\'s second state');
    				document.forms['f1'].b1.value = "third state";
    				document.forms['f1'].b1.onclick = function(){
    					alert('You are in button\'s third state');
    					document.forms['f1'].b1.value = "fourth state";
    					document.forms['f1'].b1.onclick = function(){
    						alert('You are in button\'s fourth state');
    						document.forms['f1'].b1.value = "fifth state";
    						document.forms['f1'].b1.onclick = function(){
    							alert('You are in button\'s fifth state and you are going back to first state');			
    							document.forms['f1'].b1.value = "first state";
    							document.forms['f1'].b1.onclick = firstState;
    						};
    					};
    				};;
    			};
    		}
    		</script>
    	</head>
    	<body>
    		<form name="f1">
    			<input type="button" name="b1" value="first state"/>
    		</form>
    	</body>
    </html>
    After saving the code in your machine open it in your browser and click the button available and you can see that how its lable and functionality changing.

    You need to use AJAX only if you want to use a code snippet from the server as the new functionality.

  4. #4
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thank you for your replies. I'm looking to integrate the button into Chronoform base on Joomla!. Is it possible to use php to code it or it is better to leave it in java ?

  5. #5
    Join Date
    Jul 2008
    Location
    Johannesburg, South Africa
    Posts
    31
    Thanks
    1
    Thanked 10 Times in 10 Posts

    Default

    Quote Originally Posted by jolicious View Post
    Thank you for your replies. I'm looking to integrate the button into Chronoform base on Joomla!. Is it possible to use php to code it or it is better to leave it in java ?
    Firstly JavaScript and Java are two VERY different things. One is a broswer side scripting language the other is an enterprise Object Oriented Development Langauge.

    To answer your question its a lot better to use JavaScript for situations like this as JavaScript can respond to events such as clicking and change a button's values immediatly. PHP would require that the entire page be reloaded before the button changes....

  6. #6
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Thanks for the information. I'm still learning more about programming as this is my first time doing a project on programming and I did not have any experience with programming.

  7. #7
    Join Date
    May 2008
    Posts
    38
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Hi again. I would like to know if it is possible to have data entered in the 1st page to appear again when you click a link from a 2nd page that goes back to the 1st page.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •