SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Probably an easy question

    I have a form that is used to select an account to either edit or delete. My form consists of a select box, a submit button, and two radios.

    Basically, what im wondering is how:
    - if when they select 'delete' radio button, and click an account and click go, it gives them a java confirm box to confirm the delete, but ONLY if the account isnt the default "--Select Account--" option with the value of "select". if it is that, then it tells them they need to select an account

    - if they select the edit radio button and click the submit button, it submits the form, but only if they have selected an account..



    Its probably easy for you java people, but ive been trying it and i cant get it to work!

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not too hard
    Code:
    <html>
    <head>
    <title>Test</title>
    <script type="text/javascript">
    function checkIt( f )
    {
    	var action, rb, i = 0;
    	while( rb = f.action[i++] )
    	{
    		if ( rb.checked ) action = rb.value;
    	}
    	if ( f.account.selectedIndex == 0 )
    	{
    		if ( action == 'edit' )
    			alert( "You must select a valid account for editing" );
    		else if ( action == 'delete' )
    			alert( "You must select a valid account for deletion!" );
    		else
    			alert( "Please choose an account and an action" );
    		return false;
    	}
    	else
    	{
    		if ( action == 'edit' )
    			return false;
    		else
    			return confirm( "Are you sure you want to delete this account?" );
    	}
    }
    </script>
    </head>
    <body>
    <form onsubmit="return checkIt( this )">
    	Account
    	<select name="account">
    		<option value="select">Choose</option>
    		<option value="one">One</option>
    		<option value="two">Two</option>
    		<option value="three">Three</option>
    	</select>
    	<br />
    	<br />
    	Action:<br />
    	Edit <input type="radio" name="action" value="edit" />
    	Delete<input type="radio" name="action" value="delete" />
    	<br />
    	<br />
    	<input type="submit" name="Submit" value="Submit" />
    </form>
    </body>
    </html>
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Bah, I'll just hack it DoobyWho's Avatar
    Join Date
    Jul 2002
    Posts
    476
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It works somewhat. It doesnt submit the form on edit, and it does on delete, but it just refreshes the page, doesnt take it the right page.

    edit: nevermind, i got it :-)
    Last edited by DoobyWho; Apr 7, 2003 at 07:09.


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
  •